Skip to content

Commit

Permalink
Feat: ReadExamResultDetail 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
RinRinPARK committed Oct 14, 2024
1 parent ac9a402 commit dca8a02
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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.dto.ReadExamResultsResponse
import com.swm_standard.phote.dto.ReadExamResultDetailResponse
import com.swm_standard.phote.service.ExamService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
Expand Down Expand Up @@ -62,6 +63,19 @@ class ExamController(
): BaseResponse<ReadExamResultsResponse> =
BaseResponse(msg = "학생 시험 결과 조회 성공", data = examService.readExamResults(examId))

@Operation(summary = "readExamResultDetail", description = "(강사가) 학생의 시험 결과 상세조회")
@SecurityRequirement(name = "bearer Auth")
@GetMapping("/exam/result/{examId}/{memberId}")
fun readExamResultDetail(
@PathVariable(
required = true,
) examId: UUID,
@PathVariable(
required = true,
) memberId: UUID,
): BaseResponse<ReadExamResultDetailResponse> =
BaseResponse(msg = "학생 시험 결과 상세조회 성공", data = examService.readExamResultDetail(examId, memberId))

@Operation(summary = "gradeExam", description = "문제풀이 제출 및 채점")
@SecurityRequirement(name = "bearer Auth")
@PostMapping("/exam")
Expand Down
20 changes: 20 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 @@ -47,6 +47,26 @@ data class ReadExamResultsResponse(
val students: List<ReadExamStudentResult>,
)

data class ReadExamResultDetail(
val statement: String,
val options: List<String>?,
val image: String?,
val category: Category,
val answer: String,
val submittedAnswer: String?,
val isCorrect: Boolean,
val sequence: Int,
)

data class ReadExamResultDetailResponse(
val examId: UUID,
val memberId: UUID,
val totalCorrect: Int,
val time: Int,
val createdAt: LocalDateTime,
val questions: List<ReadExamResultDetail>,
)

data class GradeExamRequest(
val time: Int,
val workbookId: UUID?,
Expand Down
36 changes: 35 additions & 1 deletion src/main/kotlin/com/swm_standard/phote/service/ExamService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import com.swm_standard.phote.dto.ReadExamHistoryDetail
import com.swm_standard.phote.dto.ReadExamHistoryDetailResponse
import com.swm_standard.phote.dto.ReadExamHistoryListResponse
import com.swm_standard.phote.dto.ReadExamResultsResponse
import com.swm_standard.phote.dto.ReadExamResultDetail
import com.swm_standard.phote.dto.ReadExamResultDetailResponse
import com.swm_standard.phote.dto.ReadExamStudentResult
import com.swm_standard.phote.dto.SubmittedAnswerRequest
import com.swm_standard.phote.entity.Answer
Expand Down Expand Up @@ -81,7 +83,6 @@ class ExamService(
}
}

// FIXME: 원래 createdAt 은 시험 생성일시임
return ReadExamHistoryDetailResponse(
examId = id,
totalCorrect = examResult.totalCorrect,
Expand Down Expand Up @@ -125,6 +126,39 @@ class ExamService(
return ReadExamResultsResponse(examId, exam.workbook.quantity, responses)
}

fun readExamResultDetail(examId: UUID, memberId: UUID): ReadExamResultDetailResponse {
val examResult = examResultRepository.findByExamIdAndMemberId(examId, memberId)
val responses =
buildList {
examResult.answers.forEach { answer ->
val question = answer.question
if (question != null) {
add(
ReadExamResultDetail(
statement = question.statement,
options = question.options?.let { question.deserializeOptions() },
image = question.image,
category = question.category,
answer = question.answer,
submittedAnswer = answer.submittedAnswer,
isCorrect = answer.isCorrect,
sequence = answer.sequence,
),
)
}
}
}

return ReadExamResultDetailResponse(
examId = examId,
memberId = memberId,
totalCorrect = examResult.totalCorrect,
time = examResult.time,
questions = responses,
createdAt = examResult.createdAt,
)
}

@Transactional
fun gradeExam(
request: GradeExamRequest,
Expand Down

0 comments on commit dca8a02

Please sign in to comment.