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

Feat: ReadExamResultDetail 구현 #253

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val memberId: UUID,
val name: String,

여기 member id 대신 member 이름 담아주는거 어떨까영

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그게 낫겠다!! 바꿨시유

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
Loading