Skip to content

Commit

Permalink
fix: 질문마다 후보자를 다르게 설정 - QuestionSet의 질문들마다 Type을 분류 후 후보자를 매번 뽑아 Ques…
Browse files Browse the repository at this point in the history
…tionSheet 생성
  • Loading branch information
toychip committed Aug 16, 2024
1 parent aec1738 commit c57faf2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum class DojoExceptionType(
QUESTION_NOT_EXIST("Question is not exist", "Q004_QUESTION_NOT_EXIST", 500),
QUESTION_SHEET_NOT_EXIST("QuestionSheet is not exist", "Q005_QUESTION_SHEET_NOT_EXIST", 500),
QUESTION_LACK_FOR_CREATE_QUESTION_SET("Question is lack for creation QSet", "Q006_QUESTION_LACK", 500),
QUESTION_INVALID_TYPE("Question Type is Invalid Type", "Q007_QUESTION_TYPE", 500),

// friend
FRIEND_NOT_FOUND("Friend not found", "C070_FRIEND_NOT_FOUND", 400),
Expand Down
65 changes: 34 additions & 31 deletions service/src/main/kotlin/com/mashup/dojo/service/QuestionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ interface QuestionService {
endAt: LocalDateTime,
): QuestionSet

fun createQuestionSheetsForMember(
questionSet: QuestionSet,
fun saveQuestionSheets(allMemberQuestionSheets: List<QuestionSheet>): List<QuestionSheet>

fun createQuestionSheetForSingleQuestion(
questionSetId: QuestionSetId,
questionId: QuestionId,
resolver: MemberId,
candidatesOfFriend: List<MemberId>,
candidatesOfAccompany: List<MemberId>,
resolver: MemberId,
): List<QuestionSheet>
questionType: QuestionType,
): QuestionSheet

fun saveQuestionSheets(allMemberQuestionSheets: List<QuestionSheet>): List<QuestionSheet>
fun getQuestionType(questionId: QuestionId): Question
}

@Service
Expand Down Expand Up @@ -227,44 +231,43 @@ class DefaultQuestionService(
return questionSet
}

override fun getQuestionType(questionId: QuestionId): Question {
return questionRepository.findByIdOrNull(questionId.value)?.toQuestion()
?: throw DojoException.of(DojoExceptionType.QUESTION_NOT_EXIST)
}

@Transactional
override fun createQuestionSheetsForMember(
questionSet: QuestionSet,
override fun createQuestionSheetForSingleQuestion(
questionSetId: QuestionSetId,
questionId: QuestionId,
resolver: MemberId,
candidatesOfFriend: List<MemberId>,
candidatesOfAccompany: List<MemberId>,
resolver: MemberId,
): List<QuestionSheet> {
questionType: QuestionType,
): QuestionSheet {
/**
* ToDo 아래는 추후 캐시에 넣는 작업을 해야합니다.
* - cache put -> QuestionSet and return
* - Temporarily set to create for all members, discuss details later
*/

val questionIds = questionSet.questionIds.map { questionOrder -> questionOrder.questionId.value }
val friendQuestionIds = questionRepository.findFriendQuestionsByIds(questionIds)
val accompanyQuestionIds = questionRepository.findAccompanyQuestionsByIds(questionIds)

val friendQuestionSheets =
friendQuestionIds.map { friendQuestionId ->
QuestionSheet.create(
questionSetId = questionSet.id,
questionId = QuestionId(friendQuestionId),
resolverId = resolver,
candidates = candidatesOfFriend
)
}
// 질문의 타입에 따라 적절한 후보자 리스트를 사용

val accompanyQuestionSheets =
accompanyQuestionIds.map { friendQuestionId ->
QuestionSheet.create(
questionSetId = questionSet.id,
questionId = QuestionId(friendQuestionId),
resolverId = resolver,
candidates = candidatesOfAccompany
)
val candidates =
if (questionType == QuestionType.FRIEND) {
candidatesOfFriend
} else if (questionType == QuestionType.ACCOMPANY) {
candidatesOfAccompany
} else {
throw DojoException.of(DojoExceptionType.QUESTION_INVALID_TYPE)
}

return friendQuestionSheets + accompanyQuestionSheets
return QuestionSheet.create(
questionSetId = questionSetId,
questionId = questionId,
resolverId = resolver,
candidates = candidates
)
}

override fun saveQuestionSheets(allMemberQuestionSheets: List<QuestionSheet>): List<QuestionSheet> {
Expand Down
37 changes: 28 additions & 9 deletions service/src/main/kotlin/com/mashup/dojo/usecase/QuestionUseCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,38 @@ class DefaultQuestionUseCase(

@Transactional
override fun createQuestionSheet(): List<QuestionSheet> {
val currentQuestionSet = questionService.getNextOperatingQuestionSet() ?: throw DojoException.of(DojoExceptionType.QUESTION_SET_NOT_READY)
val currentQuestionSet =
questionService.getNextOperatingQuestionSet()
?: throw DojoException.of(DojoExceptionType.QUESTION_SET_NOT_READY)

val allMemberRecords = memberService.findAllMember()

val questions =
currentQuestionSet.questionIds.map { questionOrder ->
questionService.getQuestionType(questionOrder.questionId)
}

val allMemberQuestionSheets =
allMemberRecords.flatMap { member ->
val candidateOfFriend = memberRelationService.findCandidateOfFriend(member.id)
val candidateOfAccompany = memberRelationService.findCandidateOfAccompany(member.id)
questionService.createQuestionSheetsForMember(
questionSet = currentQuestionSet,
candidatesOfFriend = candidateOfFriend,
candidatesOfAccompany = candidateOfAccompany,
resolver = member.id
)
// 각 질문별로 후보자를 선택
val questionSheets =
questions.map { questionOrder ->
val candidatesOfFriend = memberRelationService.findCandidateOfFriend(member.id)
val candidatesOfAccompany = memberRelationService.findCandidateOfAccompany(member.id)

val questionType = questionOrder.type

// 질문의 타입에 따라 다른 후보자 리스트를 전달
questionService.createQuestionSheetForSingleQuestion(
questionSetId = currentQuestionSet.id,
questionId = questionOrder.id,
questionType = questionType,
resolver = member.id,
candidatesOfFriend = candidatesOfFriend,
candidatesOfAccompany = candidatesOfAccompany
)
}
questionSheets
}

return questionService.saveQuestionSheets(allMemberQuestionSheets)
Expand Down

0 comments on commit c57faf2

Please sign in to comment.