Refactor: extract helpers to satisfy detekt (throws, returns, loops)
This commit is contained in:
@@ -114,16 +114,22 @@ class DefenseService(
|
||||
code: String,
|
||||
): DefenseDto {
|
||||
syncTimeouts()
|
||||
val s =
|
||||
sessions.findByCode(code.trim())
|
||||
?: throw BadRequestException("Код не найден")
|
||||
if (s.studentId != studentId) throw ForbiddenException("Этот код выдан другому студенту")
|
||||
if (s.status != DefenseStatus.waiting.name) throw BadRequestException("Защита по этому коду уже начата")
|
||||
val s = requireWaitingSession(studentId, code)
|
||||
s.status = DefenseStatus.started.name
|
||||
s.startedAt = Instant.now()
|
||||
return toDto(sessions.save(s))
|
||||
}
|
||||
|
||||
private fun requireWaitingSession(
|
||||
studentId: UUID,
|
||||
code: String,
|
||||
): DefenseSession {
|
||||
val s = sessions.findByCode(code.trim()) ?: throw BadRequestException("Код не найден")
|
||||
if (s.studentId != studentId) throw ForbiddenException("Этот код выдан другому студенту")
|
||||
if (s.status != DefenseStatus.waiting.name) throw BadRequestException("Защита по этому коду уже начата")
|
||||
return s
|
||||
}
|
||||
|
||||
@Transactional
|
||||
fun finish(
|
||||
studentId: UUID,
|
||||
|
||||
Reference in New Issue
Block a user