Skip to content

Commit

Permalink
Feat: regradeExam 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
RinRinPARK committed Oct 6, 2024
1 parent 6b31bb0 commit aaa9a5b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.swm_standard.phote.dto.CreateSharedExamRequest
import com.swm_standard.phote.dto.CreateSharedExamResponse
import com.swm_standard.phote.dto.GradeExamRequest
import com.swm_standard.phote.dto.GradeExamResponse
import com.swm_standard.phote.dto.RegradeExamRequest
import com.swm_standard.phote.dto.RegradeExamResponse
import com.swm_standard.phote.dto.ReadExamHistoryDetailResponse
import com.swm_standard.phote.dto.ReadExamHistoryListResponse
import com.swm_standard.phote.service.ExamService
Expand Down Expand Up @@ -61,6 +63,19 @@ class ExamController(
return BaseResponse(msg = "문제 풀이 채점 성공", data = response)
}

@Operation(summary = "regradeExam", description = "(강사가) 시험 정오답 재채점")
@SecurityRequirement(name = "bearer Auth")
@PostMapping("/exam/{examId}/{userId}")
fun regradeExam(
@PathVariable(required = true) examId: UUID,
@PathVariable(required = true) userId: UUID,
@Valid @RequestBody request: RegradeExamRequest,
): BaseResponse<RegradeExamResponse> {
val response = examService.regradeExam(examId, userId, request)

return BaseResponse(msg = "문제 재채점 성공", data = response)
}

@Operation(summary = "createSharedExam", description = "공유용 시험 생성")
@SecurityRequirement(name = "bearer Auth")
@PostMapping("/exam/create")
Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/com/swm_standard/phote/dto/ExamDtos.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ data class GradeExamRequest(
val answers: List<SubmittedAnswerRequest>,
)

data class RegradeExamRequest(
val questionId: UUID,
val isCorrect: Boolean,
)

data class RegradeExamResponse(
val examId: UUID,
)

data class SubmittedAnswerRequest(
val questionId: UUID,
val submittedAnswer: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import com.swm_standard.phote.entity.Answer
import org.springframework.data.jpa.repository.JpaRepository
import java.util.UUID

interface AnswerRepository : JpaRepository<Answer, UUID>
interface AnswerRepository : JpaRepository<Answer, UUID> {
fun findByExamResultIdAndQuestionId(examResultId: UUID, questionId: UUID): Answer
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import java.util.UUID

interface ExamResultRepository : JpaRepository<ExamResult, UUID> {
fun findByExamId(examId: UUID): ExamResult?
fun findByExamIdAndMemberId(examId: UUID, memberId: UUID): ExamResult
}
17 changes: 17 additions & 0 deletions src/main/kotlin/com/swm_standard/phote/service/ExamService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.swm_standard.phote.dto.ChatGPTResponse
import com.swm_standard.phote.dto.CreateSharedExamRequest
import com.swm_standard.phote.dto.GradeExamRequest
import com.swm_standard.phote.dto.GradeExamResponse
import com.swm_standard.phote.dto.RegradeExamRequest
import com.swm_standard.phote.dto.RegradeExamResponse
import com.swm_standard.phote.dto.ReadExamHistoryDetail
import com.swm_standard.phote.dto.ReadExamHistoryDetailResponse
import com.swm_standard.phote.dto.ReadExamHistoryListResponse
Expand Down Expand Up @@ -194,6 +196,21 @@ class ExamService(
)
}

@Transactional
fun regradeExam(
examId: UUID,
memberId: UUID,
request: RegradeExamRequest,
): RegradeExamResponse {
val examResult = examResultRepository.findByExamIdAndMemberId(examId, memberId)
val answer = answerRepository.findByExamResultIdAndQuestionId(examResult.id!!, request.questionId)

examResult.increaseTotalCorrect(if (request.isCorrect) 1 else -1)
answer.isCorrect = request.isCorrect == true

return RegradeExamResponse(request.questionId)
}

@Transactional
fun createSharedExam(
memberId: UUID,
Expand Down

0 comments on commit aaa9a5b

Please sign in to comment.