Skip to content
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

학생 인증제의 상태를 조회하는 API 개발 #400

Merged
merged 8 commits into from
Jul 10, 2024
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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?
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -18,14 +19,17 @@ 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<GradingRequestData>) {
//요청한 setId 들 중 실제 userFormValue 테이블에 없는 setId 일 경우 최종점수에 영향을 미칠 수 있어 예외처리
if (!userFormValueService.checkUserFormValueBySetIds(gradingDataList.map { it.setId })) throw UserFormValueNotFoundException

val teacher = teacherService.currentTeacher()

val user = userService.getUserById(teacher.userId)

val markingValueList = markingValueService.findMarkingValueListByMarkingBoardId(markingBoardId)

val markingValueMap = markingValueList.associateBy { it.setId }
Expand Down Expand Up @@ -55,7 +59,8 @@ class GradingAuthenticationFormUseCase(
markingBoardService.save(
markingBoard.copy(
totalScore = totalScore,
markingBoardType = MarkingBoardType.COMPLETED
markingBoardType = MarkingBoardType.COMPLETED,
graderName = user.name
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SubmitUserFormDataUseCase(
markingBoardType = MarkingBoardType.PENDING_REVIEW,
authenticationId = authenticationFormId,
studentId = student.id,
graderName = null
)
markingBoardService.save(markingBoard)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ class MarkingBoardJpaEntity(
val totalScore: Double,

@Enumerated(EnumType.STRING)
val markingBoardType : MarkingBoardType
val markingBoardType : MarkingBoardType,

val graderName: String?
): BaseUuidEntity(id)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ fun MarkingBoardJpaEntity.toDomain() =
studentId = studentId,
title = title,
totalScore = totalScore,
markingBoardType = markingBoardType
markingBoardType = markingBoardType,
graderName = graderName
)

fun MarkingBoard.toEntity() =
Expand All @@ -20,5 +21,6 @@ fun MarkingBoard.toEntity() =
studentId = studentId,
title = title,
totalScore = totalScore,
markingBoardType = markingBoardType
markingBoardType = markingBoardType,
graderName = graderName
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID>,
authenticationId: UUID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<UUID>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<QueryAuthenticationVerifyWebResponse> =
queryAuthenticationVerifyUseCase.execute()
.let { ResponseEntity.ok(it.toResponse()) }

@GetMapping("/form")
fun queryAuthenticationForm(): ResponseEntity<QueryAuthenticationFormWebResponse> =
queryAuthenticationFormUseCase.execute()
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
Loading