-
Notifications
You must be signed in to change notification settings - Fork 0
Dating Exam Answer Personality type 추가 #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eb9fb44
feat: dating exam answer에 personality type 컬럼 추가
hainho 21463bd
feat: 기존 dating exam 관련 데이터 제거 및 새로운 데이터 추가
hainho 5fd5341
feat: dating exam submit result 추가
hainho 5aaa1bb
feat: submit 할때 dating exam submit result 업데이트 로직 추가
hainho f3192f6
feat: 가장 count 높은 personality type 조회 api 구현
hainho 28ef27b
feat: 동시성 문제 방지 비관적락 조회 메서드 추가 및 사용
hainho 5aa564c
feat: Flyway script ddl dml 분리
hainho fdc9006
feat: 비관적락 사용 테스트 코드에 반
hainho ae72605
feat: dating exam 데이터 수정
hainho b2a52bf
feat: 대표 성격 유형 조회 API에 선택한 항목 count 추
hainho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...main/java/deepple/deepple/datingexam/application/dto/DominantPersonalityTypeResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package deepple.deepple.datingexam.application.dto; | ||
|
|
||
| import deepple.deepple.datingexam.domain.AnswerPersonalityType; | ||
| import deepple.deepple.datingexam.domain.DatingExamSubmitResult; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| public record DominantPersonalityTypeResponse( | ||
| @Schema(implementation = AnswerPersonalityType.class) | ||
| String personalityType, | ||
| int decisiveIndependentCount, | ||
| int growingRunningMateCount, | ||
| int devotedRomanticCount, | ||
| int realisticShelterCount | ||
| ) { | ||
| public static DominantPersonalityTypeResponse from(DatingExamSubmitResult result) { | ||
| return new DominantPersonalityTypeResponse( | ||
| result.getDominantPersonalityType().name(), | ||
| result.getDecisiveIndependentCount(), | ||
| result.getGrowingRunningMateCount(), | ||
| result.getDevotedRomanticCount(), | ||
| result.getRealisticShelterCount() | ||
| ); | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
src/main/java/deepple/deepple/datingexam/application/provided/DatingExamFinder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| package deepple.deepple.datingexam.application.provided; | ||
|
|
||
| import deepple.deepple.datingexam.application.dto.DatingExamInfoWithSubjectSubmissionResponse; | ||
| import deepple.deepple.datingexam.application.dto.DominantPersonalityTypeResponse; | ||
|
|
||
| public interface DatingExamFinder { | ||
| DatingExamInfoWithSubjectSubmissionResponse findRequiredExamInfo(Long memberId); | ||
|
|
||
| DatingExamInfoWithSubjectSubmissionResponse findOptionalExamInfo(Long memberId); | ||
|
|
||
| DominantPersonalityTypeResponse findDominantPersonalityType(Long memberId); | ||
| } |
11 changes: 11 additions & 0 deletions
11
...main/java/deepple/deepple/datingexam/application/required/DatingExamAnswerRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package deepple.deepple.datingexam.application.required; | ||
|
|
||
| import deepple.deepple.datingexam.domain.DatingExamAnswer; | ||
| import org.springframework.data.repository.Repository; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| public interface DatingExamAnswerRepository extends Repository<DatingExamAnswer, Long> { | ||
| List<DatingExamAnswer> findAllByIdIn(Collection<Long> ids); | ||
| } |
20 changes: 20 additions & 0 deletions
20
...ava/deepple/deepple/datingexam/application/required/DatingExamSubmitResultRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package deepple.deepple.datingexam.application.required; | ||
|
|
||
| import deepple.deepple.datingexam.domain.DatingExamSubmitResult; | ||
| import jakarta.persistence.LockModeType; | ||
| import org.springframework.data.jpa.repository.Lock; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.Repository; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public interface DatingExamSubmitResultRepository extends Repository<DatingExamSubmitResult, Long> { | ||
| Optional<DatingExamSubmitResult> findByMemberId(Long memberId); | ||
|
|
||
| @Lock(LockModeType.PESSIMISTIC_WRITE) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 어떤 경우 동시성 문제가 발생하나요?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 서로 다른 과목 답변 제출이 동시에 처리되면 동시성 문제 발생 가능해요 앱이라서 실제 과목 답변 제출 사이에 텀이 있겠지만, 네트워크 지연이나 등의 이유로 발생이 가능하긴해서 |
||
| @Query("SELECT r FROM DatingExamSubmitResult r WHERE r.memberId = :memberId") | ||
| Optional<DatingExamSubmitResult> findByMemberIdForUpdate(@Param("memberId") Long memberId); | ||
|
|
||
| DatingExamSubmitResult save(DatingExamSubmitResult result); | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
src/main/java/deepple/deepple/datingexam/domain/AnswerPersonalityType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package deepple.deepple.datingexam.domain; | ||
|
|
||
| public enum AnswerPersonalityType { | ||
| DECISIVE_INDEPENDENT, // (A) 단호한 독립주의자 | ||
| GROWING_RUNNING_MATE, // (B) 성장하는 러닝메이트 | ||
| DEVOTED_ROMANTIC, // (C) 헌신적인 로맨티스트 | ||
| REALISTIC_SHELTER // (D) 현실적인 안식처 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/main/java/deepple/deepple/datingexam/domain/DatingExamSubmitResult.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| package deepple.deepple.datingexam.domain; | ||
|
|
||
| import deepple.deepple.common.entity.BaseEntity; | ||
| import jakarta.persistence.*; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.NonNull; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import static jakarta.persistence.GenerationType.IDENTITY; | ||
| import static lombok.AccessLevel.PROTECTED; | ||
|
|
||
| @Entity | ||
| @NoArgsConstructor(access = PROTECTED) | ||
| @Getter | ||
| @Table( | ||
| uniqueConstraints = @UniqueConstraint( | ||
| name = "uk_dating_exam_submit_result_member", | ||
| columnNames = {"memberId"} | ||
| ) | ||
| ) | ||
| public class DatingExamSubmitResult extends BaseEntity { | ||
| @Id | ||
| @GeneratedValue(strategy = IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false) | ||
| private Long memberId; | ||
|
|
||
| @Column(nullable = false) | ||
| private int decisiveIndependentCount; | ||
|
|
||
| @Column(nullable = false) | ||
| private int growingRunningMateCount; | ||
|
|
||
| @Column(nullable = false) | ||
| private int devotedRomanticCount; | ||
|
|
||
| @Column(nullable = false) | ||
| private int realisticShelterCount; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(columnDefinition = "varchar(50)", nullable = false) | ||
| private AnswerPersonalityType dominantPersonalityType; | ||
|
|
||
| private DatingExamSubmitResult(@NonNull Long memberId) { | ||
| this.memberId = memberId; | ||
| this.decisiveIndependentCount = 0; | ||
| this.growingRunningMateCount = 0; | ||
| this.devotedRomanticCount = 0; | ||
| this.realisticShelterCount = 0; | ||
| this.dominantPersonalityType = AnswerPersonalityType.DECISIVE_INDEPENDENT; | ||
| } | ||
|
|
||
| public static DatingExamSubmitResult create(Long memberId) { | ||
| return new DatingExamSubmitResult(memberId); | ||
| } | ||
|
|
||
| public void addCounts(Map<AnswerPersonalityType, Integer> counts) { | ||
| this.decisiveIndependentCount += counts.getOrDefault(AnswerPersonalityType.DECISIVE_INDEPENDENT, 0); | ||
| this.growingRunningMateCount += counts.getOrDefault(AnswerPersonalityType.GROWING_RUNNING_MATE, 0); | ||
| this.devotedRomanticCount += counts.getOrDefault(AnswerPersonalityType.DEVOTED_ROMANTIC, 0); | ||
| this.realisticShelterCount += counts.getOrDefault(AnswerPersonalityType.REALISTIC_SHELTER, 0); | ||
| recalculateDominant(); | ||
| } | ||
|
|
||
| private void recalculateDominant() { | ||
| AnswerPersonalityType dominant = AnswerPersonalityType.DECISIVE_INDEPENDENT; | ||
| int maxCount = this.decisiveIndependentCount; | ||
|
|
||
| if (this.growingRunningMateCount > maxCount) { | ||
| dominant = AnswerPersonalityType.GROWING_RUNNING_MATE; | ||
| maxCount = this.growingRunningMateCount; | ||
| } | ||
| if (this.devotedRomanticCount > maxCount) { | ||
| dominant = AnswerPersonalityType.DEVOTED_ROMANTIC; | ||
| maxCount = this.devotedRomanticCount; | ||
| } | ||
| if (this.realisticShelterCount > maxCount) { | ||
| dominant = AnswerPersonalityType.REALISTIC_SHELTER; | ||
| } | ||
|
|
||
| this.dominantPersonalityType = dominant; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/main/resources/db/migration/V11__reset_dating_exams.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| -- 기존 데이터 삭제 (submit → answer → question → subject 순서) | ||
| DELETE | ||
| FROM dating_exam_submit; | ||
| DELETE | ||
| FROM dating_exam_answer; | ||
| DELETE | ||
| FROM dating_exam_question; | ||
| DELETE | ||
| FROM dating_exam_subject; | ||
|
|
||
| -- members 테이블의 is_dating_exam_submitted를 전체 false로 초기화 | ||
| UPDATE members | ||
| SET is_dating_exam_submitted = FALSE; |
2 changes: 2 additions & 0 deletions
2
src/main/resources/db/migration/V12__add_personality_type_column.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| ALTER TABLE dating_exam_answer | ||
| ADD COLUMN personality_type VARCHAR(50) NOT NULL; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
조회 누락 answerId를 검증하지 않아 personality count가 왜곡될 수 있습니다.
Line 73-79은
findAllByIdIn결과 개수 검증이 없어, 요청 ID 일부가 누락되면 under-count가 그대로 저장됩니다. dominant personality type 계산이 틀어질 수 있으니 요청 ID 집합과 조회 결과를 비교해 mismatch 시 예외 처리하세요.Diff 제안
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DatingExamSubmitRequestValidator 로 이미 검증하고 있습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 3849
@hainho, 확인했습니다.DatingExamSubmitRequestValidator.validateAnswer()에서 각answerId가 해당questionId의 유효한 답변 집합(validAnswers.contains(answerId))에 속하는지 이미 검증하고 있어,findAllByIdIn호출 전에 유효하지 않은 ID는 모두 차단됩니다. 제 지적이 잘못되었습니다.