-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(judgment): implement the function to apply and retrieve judgment…
… results Co-authored-by: cjlee38 <gptpem38@gmail.com>
- Loading branch information
1 parent
e164183
commit 0f9a16c
Showing
38 changed files
with
832 additions
and
209 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,52 @@ | ||
package apply.application | ||
|
||
import apply.domain.assignment.AssignmentRepository | ||
import apply.domain.assignment.getById | ||
import apply.domain.evaluationtarget.EvaluationTargetRepository | ||
import apply.domain.evaluationtarget.getByEvaluationIdAndUserId | ||
import apply.domain.judgment.JudgmentStartedEvent | ||
import apply.domain.judgment.JudgmentSucceededEvent | ||
import apply.domain.judgment.JudgmentTouchedEvent | ||
import apply.domain.judgmentitem.JudgmentItemRepository | ||
import apply.domain.judgmentitem.getByMissionId | ||
import apply.domain.mission.MissionRepository | ||
import apply.domain.mission.getById | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Propagation | ||
import org.springframework.transaction.annotation.Transactional | ||
import org.springframework.transaction.event.TransactionalEventListener | ||
|
||
@Transactional | ||
@Service | ||
class GradingService( | ||
private val evaluationTargetRepository: EvaluationTargetRepository, | ||
private val missionRepository: MissionRepository, | ||
private val judgmentItemRepository: JudgmentItemRepository, | ||
private val assignmentRepository: AssignmentRepository | ||
) { | ||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
@TransactionalEventListener(condition = "#event.type.evaluable") | ||
fun grade(event: JudgmentStartedEvent) { | ||
grade(event.assignmentId, 0) | ||
} | ||
|
||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
@TransactionalEventListener(condition = "#event.type.evaluable") | ||
fun grade(event: JudgmentTouchedEvent) { | ||
grade(event.assignmentId, event.passCount) | ||
} | ||
|
||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
@TransactionalEventListener(condition = "#event.type.evaluable") | ||
fun grade(event: JudgmentSucceededEvent) { | ||
grade(event.assignmentId, event.passCount) | ||
} | ||
|
||
private fun grade(assignmentId: Long, score: Int) { | ||
val assignment = assignmentRepository.getById(assignmentId) | ||
val mission = missionRepository.getById(assignment.missionId) | ||
val judgmentItem = judgmentItemRepository.getByMissionId(mission.id) | ||
val target = evaluationTargetRepository.getByEvaluationIdAndUserId(mission.evaluationId, assignment.userId) | ||
target.updateScore(judgmentItem.evaluationItemId, score) | ||
} | ||
} |
This file contains 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,27 @@ | ||
package apply.application | ||
|
||
import apply.domain.assignment.AssignmentRepository | ||
import apply.domain.judgment.JudgmentType | ||
import apply.domain.judgmentitem.JudgmentItemRepository | ||
import apply.domain.mission.MissionRepository | ||
import apply.domain.mission.getByEvaluationId | ||
import org.springframework.scheduling.annotation.Async | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class JudgmentAllService( | ||
private val judgmentService: JudgmentService, | ||
private val missionRepository: MissionRepository, | ||
private val judgmentItemRepository: JudgmentItemRepository, | ||
private val assignmentRepository: AssignmentRepository | ||
) { | ||
@Async | ||
fun judgeAll(evaluationId: Long) { | ||
val mission = missionRepository.getByEvaluationId(evaluationId) | ||
check(judgmentItemRepository.existsByMissionId(mission.id)) { "자동 채점을 실행할 수 없습니다." } | ||
val assignments = assignmentRepository.findAllByMissionId(mission.id) | ||
assignments.forEach { | ||
runCatching { judgmentService.judge(mission, it, JudgmentType.REAL) } | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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,97 @@ | ||
package apply.application | ||
|
||
import apply.domain.assignment.Assignment | ||
import apply.domain.assignment.AssignmentRepository | ||
import apply.domain.evaluation.EvaluationRepository | ||
import apply.domain.evaluationtarget.EvaluationTargetRepository | ||
import apply.domain.evaluationtarget.getById | ||
import apply.domain.judgment.Judgment | ||
import apply.domain.judgment.JudgmentRepository | ||
import apply.domain.judgment.JudgmentType | ||
import apply.domain.judgmentitem.JudgmentItem | ||
import apply.domain.judgmentitem.JudgmentItemRepository | ||
import apply.domain.mission.Mission | ||
import apply.domain.mission.MissionRepository | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Transactional(readOnly = true) | ||
@Service | ||
class MyMissionService( | ||
private val evaluationRepository: EvaluationRepository, | ||
private val evaluationTargetRepository: EvaluationTargetRepository, | ||
private val missionRepository: MissionRepository, | ||
private val judgmentItemRepository: JudgmentItemRepository, | ||
private val assignmentRepository: AssignmentRepository, | ||
private val judgmentRepository: JudgmentRepository | ||
) { | ||
fun findAllByUserIdAndRecruitmentId(userId: Long, recruitmentId: Long): List<MyMissionResponse> { | ||
val missions = findMissions(userId, recruitmentId) | ||
if (missions.isEmpty()) return emptyList() | ||
|
||
val assignments = assignmentRepository.findAllByUserId(userId) | ||
if (assignments.isEmpty()) return missions.map(::MyMissionResponse) | ||
|
||
val judgmentItems = judgmentItemRepository.findAllByMissionIdIn(missions.map { it.id }) | ||
if (judgmentItems.isEmpty()) return missions.mapBy(assignments) | ||
|
||
val judgments = judgmentRepository | ||
.findAllByAssignmentIdInAndType(assignments.map { it.id }, JudgmentType.EXAMPLE) | ||
return missions.mapBy(assignments, judgmentItems, judgments) | ||
} | ||
|
||
private fun findMissions(userId: Long, recruitmentId: Long): List<Mission> { | ||
val evaluationIds = evaluationRepository.findAllByRecruitmentId(recruitmentId).map { it.id } | ||
val targets = evaluationTargetRepository.findAllByUserIdAndEvaluationIdIn(userId, evaluationIds) | ||
return missionRepository.findAllByEvaluationIdIn(targets.map { it.id }).filterNot { it.hidden } | ||
} | ||
|
||
private fun List<Mission>.mapBy(assignments: List<Assignment>): List<MyMissionResponse> { | ||
return map { mission -> | ||
val assignment = assignments.find { it.missionId == mission.id } | ||
MyMissionResponse(mission, assignment != null) | ||
} | ||
} | ||
|
||
private fun List<Mission>.mapBy( | ||
assignments: List<Assignment>, | ||
judgmentItems: List<JudgmentItem>, | ||
judgments: List<Judgment> | ||
): List<MyMissionResponse> { | ||
return map { mission -> | ||
val assignment = assignments.find { it.missionId == mission.id } | ||
val judgmentItem = judgmentItems.find { it.missionId == mission.id } | ||
val judgment = judgments.findLastJudgment(assignment, judgmentItem) | ||
MyMissionResponse( | ||
mission = mission, | ||
submitted = assignment != null, | ||
runnable = assignment != null && judgmentItem != null, | ||
judgment = judgment | ||
) | ||
} | ||
} | ||
|
||
private fun List<Judgment>.findLastJudgment( | ||
assignment: Assignment?, | ||
judgmentItem: JudgmentItem? | ||
): LastJudgmentResponse? { | ||
if (assignment == null || judgmentItem == null) return null | ||
val judgment = find { it.assignmentId == assignment.id } ?: return null | ||
return LastJudgmentResponse(assignment.pullRequestUrl, judgment.lastRecord) | ||
} | ||
|
||
fun findLastRealJudgmentByEvaluationTargetId(evaluationTargetId: Long): JudgmentData? { | ||
val evaluationTarget = evaluationTargetRepository.getById(evaluationTargetId) | ||
val mission = missionRepository.findByEvaluationId(evaluationTarget.evaluationId) ?: return null | ||
val judgmentItem = judgmentItemRepository.findByMissionId(mission.id) ?: return null | ||
val assignment = assignmentRepository.findByUserIdAndMissionId(evaluationTarget.userId, mission.id) | ||
?: return JudgmentData(evaluationItemId = judgmentItem.evaluationItemId) | ||
val judgment = judgmentRepository.findByAssignmentIdAndType(assignment.id, JudgmentType.REAL) | ||
return JudgmentData( | ||
id = judgment?.id, | ||
evaluationItemId = judgmentItem.evaluationItemId, | ||
assignmentId = assignment.id, | ||
judgmentRecord = judgment?.lastRecord | ||
) | ||
} | ||
} |
Oops, something went wrong.