diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/dto/res/QueryAuthenticationVerifyResponseData.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/dto/res/QueryAuthenticationVerifyResponseData.kt new file mode 100644 index 00000000..4ea6ceaf --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/dto/res/QueryAuthenticationVerifyResponseData.kt @@ -0,0 +1,10 @@ +package team.msg.sms.domain.authentication.dto.res + +import team.msg.sms.domain.authentication.model.MarkingBoardType + +data class QueryAuthenticationVerifyResponseData( + val name: String, + val score: Double, + val grader: String?, + val markingBoardType: MarkingBoardType +) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/model/MarkingBoard.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/model/MarkingBoard.kt index f9d10a1b..33808618 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/model/MarkingBoard.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/model/MarkingBoard.kt @@ -8,5 +8,6 @@ data class MarkingBoard( val authenticationId: UUID, val studentId: UUID, val totalScore: Double = 0.0, - val markingBoardType: MarkingBoardType + val markingBoardType: MarkingBoardType, + val graderName: String? ) diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/service/GetMarkingBoardService.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/service/GetMarkingBoardService.kt index 9b88f3e3..e27a0ef5 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/service/GetMarkingBoardService.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/service/GetMarkingBoardService.kt @@ -6,6 +6,7 @@ import team.msg.sms.domain.authentication.model.MarkingBoardType import java.util.* interface GetMarkingBoardService { + fun verifyMarkingBoardByStudentId(studentId: UUID): MarkingBoard? fun getMarkingBoardById(id: UUID): MarkingBoard fun getMarkingBoardByStudentIds( studentIds: List, diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/service/impl/GetMarkingBoardServiceImpl.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/service/impl/GetMarkingBoardServiceImpl.kt index 88db020d..6c271098 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/service/impl/GetMarkingBoardServiceImpl.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/service/impl/GetMarkingBoardServiceImpl.kt @@ -14,6 +14,9 @@ import java.util.UUID class GetMarkingBoardServiceImpl( private val markingBoardPort: MarkingBoardPort ) : GetMarkingBoardService { + override fun verifyMarkingBoardByStudentId(studentId: UUID): MarkingBoard? = + markingBoardPort.verifyMarkingBoardByStudentId(studentId) + override fun getMarkingBoardById(id: UUID): MarkingBoard { return markingBoardPort.queryMarkingBoardById(id) ?: throw MarkingBoardNotFoundException } diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/spi/QueryMarkingBoardPort.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/spi/QueryMarkingBoardPort.kt index 4738dbba..bda58e48 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/spi/QueryMarkingBoardPort.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/spi/QueryMarkingBoardPort.kt @@ -6,6 +6,7 @@ import team.msg.sms.domain.authentication.model.MarkingBoardType import java.util.UUID interface QueryMarkingBoardPort { + fun verifyMarkingBoardByStudentId(studentId: UUID): MarkingBoard? fun queryMarkingBoardById(id: UUID): MarkingBoard? fun queryMarkingBoardByStudentIds( studentIds: List, diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/usecase/GradingAuthenticationFormUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/usecase/GradingAuthenticationFormUseCase.kt index 444d9e18..2a76a1df 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/usecase/GradingAuthenticationFormUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/usecase/GradingAuthenticationFormUseCase.kt @@ -10,6 +10,7 @@ import team.msg.sms.domain.authentication.service.MarkingBoardService import team.msg.sms.domain.authentication.service.MarkingValueService import team.msg.sms.domain.authentication.service.UserFormValueService import team.msg.sms.domain.teacher.service.TeacherService +import team.msg.sms.domain.user.service.UserService import java.time.LocalDateTime import java.util.UUID @@ -18,7 +19,8 @@ class GradingAuthenticationFormUseCase( private val markingValueService: MarkingValueService, private val markingBoardService: MarkingBoardService, private val userFormValueService: UserFormValueService, - private val teacherService: TeacherService + private val teacherService: TeacherService, + private val userService: UserService ) { fun execute(markingBoardId: UUID, gradingDataList: List) { //요청한 setId 들 중 실제 userFormValue 테이블에 없는 setId 일 경우 최종점수에 영향을 미칠 수 있어 예외처리 @@ -26,6 +28,8 @@ class GradingAuthenticationFormUseCase( val teacher = teacherService.currentTeacher() + val user = userService.getUserById(teacher.userId) + val markingValueList = markingValueService.findMarkingValueListByMarkingBoardId(markingBoardId) val markingValueMap = markingValueList.associateBy { it.setId } @@ -55,7 +59,8 @@ class GradingAuthenticationFormUseCase( markingBoardService.save( markingBoard.copy( totalScore = totalScore, - markingBoardType = MarkingBoardType.COMPLETED + markingBoardType = MarkingBoardType.COMPLETED, + graderName = user.name ) ) } diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/usecase/QueryAuthenticationVerifyUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/usecase/QueryAuthenticationVerifyUseCase.kt new file mode 100644 index 00000000..8b52ac18 --- /dev/null +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/usecase/QueryAuthenticationVerifyUseCase.kt @@ -0,0 +1,35 @@ +package team.msg.sms.domain.authentication.usecase + +import team.msg.sms.common.annotation.ReadOnlyUseCase +import team.msg.sms.domain.authentication.dto.res.QueryAuthenticationVerifyResponseData +import team.msg.sms.domain.authentication.model.MarkingBoardType +import team.msg.sms.domain.authentication.service.MarkingBoardService +import team.msg.sms.domain.student.service.StudentService + +@ReadOnlyUseCase +class QueryAuthenticationVerifyUseCase( + private val studentService: StudentService, + private val markingBoardService: MarkingBoardService +) { + fun execute(): QueryAuthenticationVerifyResponseData { + val student = studentService.currentStudent() + val markingBoard = markingBoardService.verifyMarkingBoardByStudentId(student.id) + + return if (markingBoard == null) { + QueryAuthenticationVerifyResponseData( + name = student.name, + score = 0.0, + grader = null, + markingBoardType = MarkingBoardType.NOT_SUBMITTED + ) + } else { + QueryAuthenticationVerifyResponseData( + name = student.name, + score = markingBoard.totalScore, + grader = markingBoard.graderName, + markingBoardType = markingBoard.markingBoardType + ) + } + + } +} \ No newline at end of file diff --git a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/usecase/SubmitUserFormDataUseCase.kt b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/usecase/SubmitUserFormDataUseCase.kt index 09df7b37..27223a1b 100644 --- a/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/usecase/SubmitUserFormDataUseCase.kt +++ b/sms-core/src/main/kotlin/team/msg/sms/domain/authentication/usecase/SubmitUserFormDataUseCase.kt @@ -52,6 +52,7 @@ class SubmitUserFormDataUseCase( markingBoardType = MarkingBoardType.PENDING_REVIEW, authenticationId = authenticationFormId, studentId = student.id, + graderName = null ) markingBoardService.save(markingBoard) } diff --git a/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt b/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt index 80dd2db4..c5f50d32 100644 --- a/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt +++ b/sms-infrastructure/src/main/kotlin/team/msg/sms/global/security/SecurityConfig.kt @@ -98,6 +98,7 @@ class SecurityConfig( .antMatchers(HttpMethod.GET, "/authentication/form").hasAnyAuthority(STUDENT, TEACHER) .antMatchers(HttpMethod.GET, "/authentication/{uuid}/form").hasAuthority(TEACHER) .antMatchers(HttpMethod.GET, "/authentication").hasAuthority(TEACHER) + .antMatchers(HttpMethod.GET, "/authentication/verify").hasAuthority(STUDENT) .antMatchers(HttpMethod.PUT, "/authentication/{uuid}").hasAuthority(STUDENT) .antMatchers(HttpMethod.POST, "/authentication").hasAuthority(STUDENT) .antMatchers(HttpMethod.POST, "/authentication/submit").hasAuthority(STUDENT) diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/MarkingBoardPersistenceAdapter.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/MarkingBoardPersistenceAdapter.kt index 17e9d182..5e2b37ad 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/MarkingBoardPersistenceAdapter.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/MarkingBoardPersistenceAdapter.kt @@ -21,6 +21,9 @@ class MarkingBoardPersistenceAdapter( markingBoardJpaRepository.save(markingBoard.toEntity()) } + override fun verifyMarkingBoardByStudentId(studentId: UUID): MarkingBoard? = + markingBoardCustomRepository.findMarkingBoardWithStudentId(studentId)?.toDomain() + override fun queryMarkingBoardById(id: UUID): MarkingBoard? = markingBoardJpaRepository.findByIdOrNull(id)?.toDomain() diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/entity/MarkingBoardJpaEntity.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/entity/MarkingBoardJpaEntity.kt index 9b43a52d..06fb5e57 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/entity/MarkingBoardJpaEntity.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/entity/MarkingBoardJpaEntity.kt @@ -27,5 +27,7 @@ class MarkingBoardJpaEntity( val totalScore: Double, @Enumerated(EnumType.STRING) - val markingBoardType : MarkingBoardType + val markingBoardType : MarkingBoardType, + + val graderName: String? ): BaseUuidEntity(id) \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/mapper/MarkingBoardMapper.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/mapper/MarkingBoardMapper.kt index 2a272075..e90fc415 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/mapper/MarkingBoardMapper.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/mapper/MarkingBoardMapper.kt @@ -10,7 +10,8 @@ fun MarkingBoardJpaEntity.toDomain() = studentId = studentId, title = title, totalScore = totalScore, - markingBoardType = markingBoardType + markingBoardType = markingBoardType, + graderName = graderName ) fun MarkingBoard.toEntity() = @@ -20,5 +21,6 @@ fun MarkingBoard.toEntity() = studentId = studentId, title = title, totalScore = totalScore, - markingBoardType = markingBoardType + markingBoardType = markingBoardType, + graderName = graderName ) \ No newline at end of file diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/repository/queryDSL/MarkingBoardCustomRepository.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/repository/queryDSL/MarkingBoardCustomRepository.kt index 7d86cdd3..19f47bb4 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/repository/queryDSL/MarkingBoardCustomRepository.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/repository/queryDSL/MarkingBoardCustomRepository.kt @@ -2,9 +2,12 @@ package team.msg.sms.persistence.authentication.repository.queryDSL import team.msg.sms.domain.authentication.dto.res.UserBoardPageResponseData import team.msg.sms.domain.authentication.model.MarkingBoardType +import team.msg.sms.persistence.authentication.entity.MarkingBoardJpaEntity import java.util.* interface MarkingBoardCustomRepository { + fun findMarkingBoardWithStudentId(studentId: UUID): MarkingBoardJpaEntity? + fun findMarkingBoardWithStudentInfoByStudentIds( studentIds: List, authenticationId: UUID, diff --git a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/repository/queryDSL/MarkingBoardRepositoryImpl.kt b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/repository/queryDSL/MarkingBoardRepositoryImpl.kt index bf158f66..8dc15fa6 100644 --- a/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/repository/queryDSL/MarkingBoardRepositoryImpl.kt +++ b/sms-persistence/src/main/kotlin/team/msg/sms/persistence/authentication/repository/queryDSL/MarkingBoardRepositoryImpl.kt @@ -7,7 +7,10 @@ import org.springframework.data.domain.PageRequest import org.springframework.stereotype.Repository import team.msg.sms.domain.authentication.dto.res.UserBoardPageResponseData import team.msg.sms.domain.authentication.dto.res.UserBoardWithStudentInfoResponseData +import team.msg.sms.domain.authentication.model.MarkingBoard import team.msg.sms.domain.authentication.model.MarkingBoardType +import team.msg.sms.persistence.authentication.entity.MarkingBoardJpaEntity +import team.msg.sms.persistence.authentication.entity.QAuthenticationFormJpaEntity import team.msg.sms.persistence.authentication.entity.QMarkingBoardJpaEntity import team.msg.sms.persistence.student.entity.QStudentJpaEntity import team.msg.sms.persistence.user.entity.QUserJpaEntity @@ -17,6 +20,22 @@ import java.util.* class MarkingBoardRepositoryImpl( private val jpaQueryFactory: JPAQueryFactory ) : MarkingBoardCustomRepository { + override fun findMarkingBoardWithStudentId(studentId: UUID): MarkingBoardJpaEntity? { + val qMarkingBoard = QMarkingBoardJpaEntity.markingBoardJpaEntity + val qAuthenticationForm = QAuthenticationFormJpaEntity.authenticationFormJpaEntity + val data = jpaQueryFactory + .select(qMarkingBoard) + .from(qMarkingBoard) + .join(qAuthenticationForm).on(qMarkingBoard.authenticationId.eq(qAuthenticationForm.id)) + .where( + qMarkingBoard.studentId.eq(studentId) + .and(qAuthenticationForm.active.isTrue) + ) + .fetch() + return if (data.isEmpty()) null else { + data.first() + } + } override fun findMarkingBoardWithStudentInfoByStudentIds( studentIds: List, diff --git a/sms-presentation/src/main/kotlin/team/msg/sms/domain/authentication/AuthenticationWebAdapter.kt b/sms-presentation/src/main/kotlin/team/msg/sms/domain/authentication/AuthenticationWebAdapter.kt index 0671b476..e3d5aed4 100644 --- a/sms-presentation/src/main/kotlin/team/msg/sms/domain/authentication/AuthenticationWebAdapter.kt +++ b/sms-presentation/src/main/kotlin/team/msg/sms/domain/authentication/AuthenticationWebAdapter.kt @@ -32,8 +32,14 @@ class AuthenticationWebAdapter( private val createAuthenticationFormUseCase: CreateAuthenticationFormUseCase, private val queryStudentFormListUseCase: QueryStudentFormListUseCase, private val queryStudentAuthenticationFormDetailUseCase: QueryStudentAuthenticationFormDetailUseCase, - private val gradingAuthenticationFormUseCase: GradingAuthenticationFormUseCase + private val gradingAuthenticationFormUseCase: GradingAuthenticationFormUseCase, + private val queryAuthenticationVerifyUseCase: QueryAuthenticationVerifyUseCase ) { + @GetMapping("/verify") + fun verifyStudentAuthenticationForm(): ResponseEntity = + queryAuthenticationVerifyUseCase.execute() + .let { ResponseEntity.ok(it.toResponse()) } + @GetMapping("/form") fun queryAuthenticationForm(): ResponseEntity = queryAuthenticationFormUseCase.execute() @@ -248,6 +254,14 @@ class AuthenticationWebAdapter( content = content ) + private fun QueryAuthenticationVerifyResponseData.toResponse() = + QueryAuthenticationVerifyWebResponse( + name = name, + score = score, + grader = grader, + markingBoardType = markingBoardType + ) + private fun isValidUUID(uuid: String): Boolean { return try { UUID.fromString(uuid) diff --git a/sms-presentation/src/main/kotlin/team/msg/sms/domain/authentication/dto/res/QueryAuthenticationVerifyWebResponse.kt b/sms-presentation/src/main/kotlin/team/msg/sms/domain/authentication/dto/res/QueryAuthenticationVerifyWebResponse.kt new file mode 100644 index 00000000..14b28e39 --- /dev/null +++ b/sms-presentation/src/main/kotlin/team/msg/sms/domain/authentication/dto/res/QueryAuthenticationVerifyWebResponse.kt @@ -0,0 +1,10 @@ +package team.msg.sms.domain.authentication.dto.res + +import team.msg.sms.domain.authentication.model.MarkingBoardType + +data class QueryAuthenticationVerifyWebResponse( + val name: String, + val score: Double, + val grader: String?, + val markingBoardType: MarkingBoardType +)