Skip to content

Feat : 설문조사 조회 및 참여 기능 추가#87

Merged
Lee9Bin merged 1 commit into
devfrom
feature/survey
Apr 27, 2026
Merged

Feat : 설문조사 조회 및 참여 기능 추가#87
Lee9Bin merged 1 commit into
devfrom
feature/survey

Conversation

@Lee9Bin

@Lee9Bin Lee9Bin commented Apr 27, 2026

Copy link
Copy Markdown
Member

🎯 작업 내용

  • 설문조사 도메인 추가 (entity, dto, repository, service, controller)
  • 활성 설문조사 조회 API 추가
  • 설문조사 참여 가능 여부 조회 API 추가
  • 설문조사 참여 기록 저장 API 추가
  • 운동 기록 수 조회를 위해 WorkoutService에 사용자 운동 기록 카운트 메서드 추가

📝 상세 설명

활성화된 설문조사를 조회하고, 사용자의 설문조사 참여 가능 여부를 확인한 뒤 참여 이력을 저장할 수 있도록 구현했습니다.

  • Survey: 설문조사 URL, 제목, 내용, 활성화 여부 관리
  • UserSurveyParticipation: 사용자별 설문조사 참여 이력 저장
  • SurveyService: 활성 설문 조회, 참여 가능 여부 확인, 참여 기록 저장 처리
  • 참여 가능 조건: 저장된 운동 기록 수가 2, 6, 10회 중 하나이고 현재 활성 설문조사에 참여 이력이 없는 사용자
  • 참여 검증: 참여 저장 시 활성 설문 여부, 중복 참여 여부, 운동 기록 수 조건을 재검증
  • 중복 방지: user_id, survey_id unique 제약 추가

✅ 테스트

  • 활성 설문조사 조회 API 응답 확인
  • 설문조사 참여 가능 여부 조회 API 응답 확인
  • 운동 기록 수가 조건에 맞지 않는 사용자 참여 차단 확인
  • 운동 기록 수가 2회인 사용자 참여 성공 확인
  • 참여 후 참여 가능 여부가 false로 변경되는지 확인
  • 동일 설문조사 중복 참여 요청 시 에러 응답 확인
  • 인증 없이 설문조사 API 요청 시 401 응답 확인

Summary by CodeRabbit

  • New Features
    • Added survey system with eligibility checking based on workout history
    • Users can view active survey details and content
    • Survey participation is restricted to eligible users and prevents duplicate responses
    • New error handling for missing surveys, ineligible users, and duplicate participation attempts

- 활성 설문조사 조회 API 추가
- 설문조사 참여 가능 여부 조회 API 추가
- 설문조사 참여 기록 저장 API 추가
- 참여 가능 조건으로 운동 기록 수 2, 6, 10회 및 미참여 여부 검증
- 설문 참여 저장 시 활성 설문 여부와 참여 대상 여부 재검증
- 사용자별 설문 중복 참여 방지를 위한 unique 제약 추가
@Lee9Bin Lee9Bin self-assigned this Apr 27, 2026
@coderabbitai

coderabbitai Bot commented Apr 27, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces a complete survey feature module with REST endpoints, JPA entities for surveys and user participation tracking, repositories for data access, a service layer implementing eligibility checks based on workout counts, and new error codes for survey-related failures.

Changes

Cohort / File(s) Summary
Survey Entities
src/main/java/com/prography/zone_2_be/domain/survey/entity/Survey.java, UserSurveyParticipation.java
New Survey entity with url, title, content, active status, and deleted timestamp. New UserSurveyParticipation entity with composite unique constraint on user and survey IDs for tracking participation.
Survey DTOs
src/main/java/com/prography/zone_2_be/domain/survey/dto/SurveyEligibilityResponse.java, SurveyFindResponse.java
New response DTOs: SurveyEligibilityResponse with boolean eligible field (JSON-mapped as isEligible), and SurveyFindResponse containing survey id, title, content, and url.
Survey Repository Layer
src/main/java/com/prography/zone_2_be/domain/survey/repository/SurveyRepository.java, UserSurveyParticipationRepository.java
Spring Data JPA repositories with derived query methods: findByActiveTrue(), findByIdAndActiveTrue(Long) for surveys, and existsByUserAndSurvey(User, Survey) for participation checks.
Survey Service
src/main/java/com/prography/zone_2_be/domain/survey/service/SurveyService.java
Service layer implementing eligibility checking (based on workout count: 2, 6, or 10), active survey retrieval, and survey participation with transactional logic and validation.
Survey Controller
src/main/java/com/prography/zone_2_be/domain/survey/controller/SurveyController.java
REST endpoints under /api/v1/survey: eligibility check (GET), active survey retrieval (GET), and participation (POST) with appropriate API responses.
Error Codes
src/main/java/com/prography/zone_2_be/global/error/ErrorCode.java
Three new error codes: SURVEY_NOT_FOUND (4600), SURVEY_ALREADY_RESPONDED (4601), SURVEY_NOT_ELIGIBLE (4602).
Workout Service Enhancement
src/main/java/com/prography/zone_2_be/domain/workout/repository/WorkoutRepository.java, ...service/WorkoutService.java
Extended WorkoutRepository with countByUser(User) method and added countUserWorkouts(User) public method to WorkoutService.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Controller as SurveyController
    participant Service as SurveyService
    participant Repos as Repositories
    participant WS as WorkoutService
    participant DB as Database

    Client->>Controller: POST /api/v1/survey/{surveyId}/participate
    Controller->>Service: participateSurvey(surveyId)
    
    Service->>Repos: JwtUtil.getUser()
    Repos-->>Service: User
    
    Service->>Repos: SurveyRepository.findByIdAndActiveTrue(surveyId)
    Repos->>DB: Query active survey by ID
    DB-->>Repos: Survey (if exists)
    Repos-->>Service: Optional<Survey>
    
    Service->>Repos: UserSurveyParticipationRepository.existsByUserAndSurvey(user, survey)
    Repos->>DB: Check participation exists
    DB-->>Repos: boolean
    Repos-->>Service: Already participated?
    
    alt Already Participated
        Service-->>Controller: Throw CustomException(SURVEY_ALREADY_RESPONDED)
    else Not Participated
        Service->>WS: countUserWorkouts(user)
        WS->>DB: Count user workouts
        DB-->>WS: count
        WS-->>Service: long
        Service->>Service: isEligibleWorkoutCount(user)
        
        alt Not Eligible (count ≠ 2, 6, 10)
            Service-->>Controller: Throw CustomException(SURVEY_NOT_ELIGIBLE)
        else Eligible
            Service->>Repos: UserSurveyParticipationRepository.save(participation)
            Repos->>DB: Insert participation record
            DB-->>Repos: Persisted
            Repos-->>Service: Done
            Service-->>Controller: Success (Void)
            Controller-->>Client: ApiResponse<Void> 200 OK
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Refactor/workout fatusage #67: Modifies WorkoutService which is now integrated with the new SurveyService; changes to workout saving and DTOs may interact with survey eligibility logic.

Poem

🐰 A survey hops into the codebase bright,
Tracking workouts (2, 6, 10 just right),
With entities, DTOs, and queries so fine,
User participation preserved by design!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main changes: adding survey inquiry and participation features, which aligns with the comprehensive survey domain implementation across controllers, services, entities, and repositories.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/survey

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Lee9Bin
Lee9Bin merged commit 535331e into dev Apr 27, 2026
3 of 4 checks passed
@Lee9Bin
Lee9Bin deleted the feature/survey branch April 27, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant