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: readExamResults 구현 #245

Merged
merged 2 commits into from
Oct 6, 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 @@ -8,6 +8,7 @@ import com.swm_standard.phote.dto.GradeExamRequest
import com.swm_standard.phote.dto.GradeExamResponse
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.service.ExamService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
Expand Down Expand Up @@ -48,6 +49,16 @@ class ExamController(
): BaseResponse<List<ReadExamHistoryListResponse>> =
BaseResponse(msg = "문제풀이 기록 리스트 조회 성공", data = examService.readExamHistoryList(workbookId))

@Operation(summary = "readExamResults", description = "(강사가) 학생들의 시험 결과 목록을 조회")
@SecurityRequirement(name = "bearer Auth")
@GetMapping("/exams/result/{examId}")
fun readExamResults(
@PathVariable(
required = true,
) examId: UUID,
): BaseResponse<ReadExamResultsResponse> =
BaseResponse(msg = "학생 시험 결과 조회 성공", data = examService.readExamResults(examId))

@Operation(summary = "gradeExam", description = "문제풀이 제출 및 채점")
@SecurityRequirement(name = "bearer Auth")
@PostMapping("/exam/{workbookId}")
Expand Down
12 changes: 12 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 @@ -34,6 +34,18 @@ data class ReadExamHistoryListResponse(
val sequence: Int,
)

data class ReadExamStudentResult(
val userId: UUID,
val name: String,
val score: Int,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

여기도 time (소요 시간) 들어가면 좋을 것 같네욘


data class ReadExamResultsResponse(
val examId: UUID,
val totalQuestionCount: Int,
val students: List<ReadExamStudentResult>,
)

data class GradeExamRequest(
val time: Int,
val answers: List<SubmittedAnswerRequest>,
Expand Down
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 findAllByExamId(examId: UUID): List<ExamResult>
}
20 changes: 20 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 @@ -10,6 +10,8 @@ import com.swm_standard.phote.dto.GradeExamResponse
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.ReadExamStudentResult
import com.swm_standard.phote.dto.ReadExamResultsResponse
import com.swm_standard.phote.dto.SubmittedAnswerRequest
import com.swm_standard.phote.entity.Answer
import com.swm_standard.phote.entity.Category
Expand Down Expand Up @@ -54,6 +56,7 @@ class ExamService(
@Value("\${openai.api.url}")
lateinit var url: String

@Transactional(readOnly = true)
Copy link
Contributor

Choose a reason for hiding this comment

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

클래스에 어노테이션 붙어있어서 기존대로 빼도 될 것 같아온

fun readExamHistoryDetail(id: UUID): ReadExamHistoryDetailResponse {
val examResult = examResultRepository.findByExamId(id) ?: throw NotFoundException(fieldName = "examResult")
val responses =
Expand Down Expand Up @@ -87,6 +90,7 @@ class ExamService(
)
}

@Transactional(readOnly = true)
fun readExamHistoryList(workbookId: UUID): List<ReadExamHistoryListResponse> {
val exams = examRepository.findAllByWorkbookId(workbookId)
return exams.map { exam ->
Expand All @@ -104,6 +108,22 @@ class ExamService(
}
}

@Transactional(readOnly = true)
fun readExamResults(examId: UUID): ReadExamResultsResponse {
val exam = examRepository.findById(examId).orElseThrow { NotFoundException(fieldName = "examId") }
val examResults = examResultRepository.findAllByExamId(examId)

val responses = examResults.map { examResult ->
ReadExamStudentResult(
examResult.member.id,
examResult.member.name,
examResult.totalCorrect
)
}

return ReadExamResultsResponse(examId, exam.workbook.quantity, responses)
}

@Transactional
fun gradeExam(
workbookId: UUID,
Expand Down
Loading