Skip to content

Commit

Permalink
Merge pull request #136 from mash-up-kr/jm/fix-all-question-candidates
Browse files Browse the repository at this point in the history
fix : 전체 대상에 대한 질문에 대해선 후보자 친구+비친구로 변경
  • Loading branch information
xonmin authored Sep 21, 2024
2 parents ef67561 + 959d398 commit a6d3d0f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface MemberRelationQueryRepository {
limit: Long,
): List<String>

fun findRandomOfAccompany(
fun findRandomOfAll(
memberId: String,
limit: Long,
): List<String>
Expand Down Expand Up @@ -142,7 +142,7 @@ class MemberRelationQueryRepositoryImpl(
.fetch()
}

override fun findRandomOfAccompany(
override fun findRandomOfAll(
memberId: String,
limit: Long,
): List<String> {
Expand All @@ -151,10 +151,7 @@ class MemberRelationQueryRepositoryImpl(
return jpaQueryFactory
.select(memberRelation.toId)
.from(memberRelation)
.where(
memberRelation.fromId.eq(memberId),
memberRelation.relationType.eq(RelationType.ACCOMPANY)
)
.where(memberRelation.fromId.eq(memberId))
.orderBy(Expressions.numberTemplate(Double::class.java, "function('RAND')").asc())
.limit(8)
.fetch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface MemberRelationService {

fun findCandidateOfFriend(memberId: MemberId): List<MemberId>

fun findCandidateOfAccompany(memberId: MemberId): List<MemberId>
fun findCandidateOfAll(memberId: MemberId): List<MemberId>

fun findRelationByIds(
fromId: MemberId,
Expand Down Expand Up @@ -123,8 +123,8 @@ class DefaultMemberRelationService(
}
}

override fun findCandidateOfAccompany(memberId: MemberId): List<MemberId> {
return memberRelationRepository.findRandomOfAccompany(
override fun findCandidateOfAll(memberId: MemberId): List<MemberId> {
return memberRelationRepository.findRandomOfAll(
memberId = memberId.value,
limit = defaultCandidateSize
).map {
Expand Down
16 changes: 6 additions & 10 deletions service/src/main/kotlin/com/mashup/dojo/service/QuestionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ interface QuestionService {
questionId: QuestionId,
resolver: MemberId,
candidatesOfFriend: List<MemberId>,
candidatesOfAccompany: List<MemberId>,
candidatesOfAll: List<MemberId>,
questionType: QuestionType,
): QuestionSheet

Expand Down Expand Up @@ -252,7 +252,7 @@ class DefaultQuestionService(
questionId: QuestionId,
resolver: MemberId,
candidatesOfFriend: List<MemberId>,
candidatesOfAccompany: List<MemberId>,
candidatesOfAll: List<MemberId>,
questionType: QuestionType,
): QuestionSheet {
/**
Expand All @@ -262,19 +262,15 @@ class DefaultQuestionService(
* 질문의 타입에 따라 적절한 후보자 리스트를 사용
*/

if (candidatesOfFriend.size < defaultCandidateSize && candidatesOfAccompany.size < defaultCandidateSize) {
if (candidatesOfFriend.size < defaultCandidateSize && candidatesOfAll.size < defaultCandidateSize) {
throw DojoException.of(DojoExceptionType.CANDIDATE_INVALID_SIZE)
}

val candidates =
when (questionType) {
QuestionType.FRIEND ->
// 친구 후보자의 크기가 기본 크기보다 작을 경우 비친구 후보자를 사용
if (candidatesOfFriend.size < defaultCandidateSize) candidatesOfAccompany else candidatesOfFriend

QuestionType.ACCOMPANY ->
// 비친구 후보자의 크기가 기본 크기보다 작을 경우 친구 후보자를 사용
if (candidatesOfAccompany.size < defaultCandidateSize) candidatesOfFriend else candidatesOfAccompany
// 친구 후보자의 크기가 기본 크기보다 작을 경우 전체 후보자를 사용
QuestionType.FRIEND -> if (candidatesOfFriend.size < defaultCandidateSize) candidatesOfAll else candidatesOfFriend
QuestionType.ACCOMPANY -> candidatesOfAll
}

return QuestionSheet.create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ class DefaultQuestionUseCase(
val questionSheets =
questions.map { questionOrder ->
val candidatesOfFriend = memberRelationService.findCandidateOfFriend(member.id)
val candidatesOfAccompany = memberRelationService.findCandidateOfAccompany(member.id)

// all -> accompany + friend
val candidatesOfAll = memberRelationService.findCandidateOfAll(member.id)
val questionType = questionOrder.type

// 질문의 타입에 따라 다른 후보자 리스트를 전달
Expand All @@ -147,7 +147,7 @@ class DefaultQuestionUseCase(
questionType = questionType,
resolver = member.id,
candidatesOfFriend = candidatesOfFriend,
candidatesOfAccompany = candidatesOfAccompany
candidatesOfAll = candidatesOfAll
)
}
questionSheets
Expand Down

0 comments on commit a6d3d0f

Please sign in to comment.