-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: Create QuestionSheet #86
Changes from 5 commits
3a3b655
3dd65b4
df8083a
3228a81
22c6692
9433583
d7560ee
bc905da
4a13c4a
b5fc2ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,10 @@ interface MemberRelationService { | |
fromId: MemberId, | ||
toId: MemberId, | ||
): Boolean | ||
|
||
fun findCandidateOfFriend(memberId: MemberId): List<MemberId> | ||
|
||
fun findCandidateOfAccompany(memberId: MemberId): List<MemberId> | ||
} | ||
|
||
@Service | ||
|
@@ -79,6 +83,28 @@ class DefaultMemberRelationService( | |
): Boolean { | ||
return memberRelationRepository.isFriend(fromId = fromId.value, toId = toId.value) | ||
} | ||
|
||
override fun findCandidateOfFriend(memberId: MemberId): List<MemberId> { | ||
return memberRelationRepository.findRandomOfFriend( | ||
memberId = memberId.value, | ||
limit = DEFAULT_CANDIDATE_SIZE | ||
).map { | ||
MemberId(it) | ||
} | ||
} | ||
|
||
override fun findCandidateOfAccompany(memberId: MemberId): List<MemberId> { | ||
return memberRelationRepository.findRandomOfAccompany( | ||
memberId = memberId.value, | ||
limit = DEFAULT_CANDIDATE_SIZE | ||
).map { | ||
MemberId(it) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val DEFAULT_CANDIDATE_SIZE: Long = 8 | ||
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. Candidate size ๋ ์ฌ์ฉํ๋ ๊ณณ์์ ํํธ๋์ด ์ฌ์ฉ๋ ์ ์์ผ๋, application.yaml ๋ก ๋นผ๊ณ ์ฃผ์
ํด์ ์ฌ์ฉํ๋ฉด ์ข๊ฒ ๋ค์ |
||
} | ||
} | ||
|
||
private fun MemberRelation.toEntity(): MemberRelationEntity { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ import com.mashup.dojo.QuestionSheetEntity | |
import com.mashup.dojo.QuestionSheetRepository | ||
import com.mashup.dojo.Status | ||
import com.mashup.dojo.domain.ImageId | ||
import com.mashup.dojo.domain.Member | ||
import com.mashup.dojo.domain.MemberId | ||
import com.mashup.dojo.domain.PublishStatus | ||
import com.mashup.dojo.domain.PublishedTime | ||
|
@@ -71,9 +70,11 @@ interface QuestionService { | |
endAt: LocalDateTime, | ||
): QuestionSet | ||
|
||
fun createQuestionSheets( | ||
fun createQuestionSheetsForMember( | ||
questionSet: QuestionSet, | ||
members: List<Member>, | ||
candidatesOfFriend: List<MemberId>, | ||
candidatesOfAccompany: List<MemberId>, | ||
resolver: MemberId, | ||
): List<QuestionSheet> | ||
} | ||
|
||
|
@@ -224,21 +225,51 @@ class DefaultQuestionService( | |
} | ||
|
||
@Transactional | ||
override fun createQuestionSheets( | ||
override fun createQuestionSheetsForMember( | ||
questionSet: QuestionSet, | ||
members: List<Member>, | ||
candidatesOfFriend: List<MemberId>, | ||
candidatesOfAccompany: List<MemberId>, | ||
resolver: MemberId, | ||
): List<QuestionSheet> { | ||
/** | ||
* TODO: | ||
* TODO: ์ฌ๊ธฐ ์๋ ์ ๋ค์ ํด๊ฒฐ๋ ๊ฒ์ผ๊น์? | ||
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. ๋ต ํด๊ฒฐ๋ ๊ฒ ๊ฐ์์! |
||
* target : members | ||
* question : QuestionSet | ||
* candidate : member.candidate() | ||
* | ||
* - make friend logic, get Candidate logic | ||
* | ||
* ToDo ์๋๋ ์ถํ ์บ์์ ๋ฃ๋ ์์ ์ ํด์ผํฉ๋๋ค. | ||
* - cache put -> QuestionSet and return | ||
* - Temporarily set to create for all members, discuss details later | ||
*/ | ||
return LIST_SAMPLE_QUESTION_SHEET | ||
|
||
val questionIds = questionSet.questionIds.map { questionOrder -> questionOrder.questionId.value } | ||
val friendQuestionIds = questionRepository.findFriendQuestionsByIds(questionIds) | ||
val accompanyQuestionIds = questionRepository.findAccompanyQuestionsByIds(questionIds) | ||
|
||
val friendQuestionSheetEntities = | ||
friendQuestionIds.map { friendQuestionId -> | ||
QuestionSheet.create( | ||
questionSetId = questionSet.id, | ||
questionId = QuestionId(friendQuestionId), | ||
resolverId = resolver, | ||
candidates = candidatesOfFriend | ||
).toEntity() | ||
} | ||
|
||
val accompanyQuestionSheetEntities = | ||
accompanyQuestionIds.map { friendQuestionId -> | ||
QuestionSheet.create( | ||
questionSetId = questionSet.id, | ||
questionId = QuestionId(friendQuestionId), | ||
resolverId = resolver, | ||
candidates = candidatesOfAccompany | ||
).toEntity() | ||
} | ||
|
||
val questionSheetEntities = friendQuestionSheetEntities + accompanyQuestionSheetEntities | ||
return questionSheetRepository.saveAll(questionSheetEntities).map { it.toQuestionSheetWithCandidatesId() } | ||
} | ||
|
||
override fun getQuestionById(id: QuestionId): Question? { | ||
|
@@ -379,6 +410,16 @@ private fun QuestionSetEntity.toQuestionSet(): QuestionSet { | |
) | ||
} | ||
|
||
private fun QuestionSheet.toEntity(): QuestionSheetEntity { | ||
return QuestionSheetEntity( | ||
id = questionSheetId.value, | ||
questionSetId = questionSetId.value, | ||
questionId = questionId.value, | ||
resolverId = resolverId.value, | ||
candidates = candidates.map { it.value }.toList() | ||
) | ||
} | ||
|
||
private fun QuestionSheetEntity.toQuestionSheetWithCandidatesId(): QuestionSheet { | ||
return QuestionSheet( | ||
questionSheetId = QuestionSheetId(id), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import com.mashup.dojo.domain.QuestionSheet | |
import com.mashup.dojo.domain.QuestionSheetId | ||
import com.mashup.dojo.domain.QuestionType | ||
import com.mashup.dojo.service.ImageService | ||
import com.mashup.dojo.service.MemberRelationService | ||
import com.mashup.dojo.service.MemberService | ||
import com.mashup.dojo.service.PickService | ||
import com.mashup.dojo.service.QuestionService | ||
|
@@ -85,6 +86,7 @@ class DefaultQuestionUseCase( | |
private val memberService: MemberService, | ||
private val pickService: PickService, | ||
private val imageService: ImageService, | ||
private val memberRelationService: MemberRelationService, | ||
) : QuestionUseCase { | ||
@Transactional | ||
override fun create(command: QuestionUseCase.CreateCommand): QuestionId { | ||
|
@@ -120,7 +122,18 @@ class DefaultQuestionUseCase( | |
override fun createQuestionSheet(): List<QuestionSheet> { | ||
val currentQuestionSet = questionService.getNextOperatingQuestionSet() ?: throw DojoException.of(DojoExceptionType.QUESTION_SET_NOT_READY) | ||
val allMemberRecords = memberService.findAllMember() | ||
return questionService.createQuestionSheets(currentQuestionSet, allMemberRecords) | ||
// ToDo Default ์น๊ตฌ ์๊ฐ 8๋ช ์ดํ์ผ ๊ฒฝ์ฐ ์ค๋ฅ ๋ฐ์ํ๋ฏ๋ก, ์น๊ตฌ๊ฐ 8๋ช ์ด ์๋๋ฉด ํ์๊ฐ์ ๋ถ๊ฐ๋ฅ | ||
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. ์ด๋์์ ํ๋ก์ฐ๋ฅผ ๋ฐฉ์ดํ๋๋๋ ์ ํด์ผํ๋๊ตฐ์.. ๋ ์ถ๊ฐ์ ์ผ๋ก ๋ง์ฝ ํ์๊ฐ์
์ ์ฐจ์ ๋ง์ง ์๋๋ค๋ฉด, getQuestionSheet (ํฌํ์ง ์กฐํ) ์ ํด๋น ์ ์ ์ ์น๊ตฌ์๊ฐ 8๋ช
์ด ์๋๋์ ๋ ํ๋ก์ฐ๋ฅผ ์ถ๊ฐํ๊ฒ๋ ํ๋ ํ๋ก์ฐ๋ก ์ด์ด์ง๊ฒ ํ๋ ๊ฒ๋ ๋ฐฉ๋ฒ์ด๊ธด ํ๊ฒ ๋ค์. 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. ๋ต ๋ง์ํ์ ๊ฒ์ฒ๋ผ ์ด๋์ ๋ฐฉ์ดํด์ผํ ์ง ์ ํด์ผํฉ๋๋ค. |
||
|
||
return allMemberRecords.flatMap { member -> | ||
val candidateOfFriend = memberRelationService.findCandidateOfFriend(member.id) | ||
val candidateOfAccompany = memberRelationService.findCandidateOfAccompany(member.id) | ||
questionService.createQuestionSheetsForMember( | ||
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. Question์ QuestionType์ด ์น๊ตฌ์ธ์ง ๋น์น๊ตฌ์ธ์ง 1๋ฒ๋ง ๊ณ์ฐํด์ ์ฌ์ฉํ๋ฉด ์ข์ ๊ฒ ๊ฐ์๋ฐ ๊ณ ๋ฏผ์
๋๋ค. 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. ์ฐ์ ํ ์์ผ์ ๋งํ ๊ฒ์ฒ๋ผ ๋ฐฐ์น์ฑ์ด๋๊น ๋จผ์ ํด๋ณด๊ณ ๋ฌธ์ ์๋ค๋ฉด ๊ทธ๋ ๊ฐ์ ๊ฐ์ ํ๋ ๊ฒ๋ ๊ด์ฐฎ์ ๋ณด์ ๋๋ค. |
||
questionSet = currentQuestionSet, | ||
candidatesOfFriend = candidateOfFriend, | ||
candidatesOfAccompany = candidateOfAccompany, | ||
resolver = member.id | ||
) | ||
} | ||
} | ||
|
||
override fun getQuestionSheetList(memberId: MemberId): QuestionUseCase.GetQuestionSheetsResult { | ||
|
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.
์ฑ๊ธฐํ๋ค์ Expressions.numberTemplate()