From f52c51adfe00daa3ad8a38c4b9755daae607c55f Mon Sep 17 00:00:00 2001 From: KimTaeO Date: Tue, 24 Oct 2023 19:18:06 +0900 Subject: [PATCH] =?UTF-8?q?delete=20::=20=EA=B2=80=EC=A6=9D=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=ED=95=A8=EC=88=98=EB=A1=9C=20=EB=B6=84=EB=A6=AC=20?= =?UTF-8?q?=EB=A1=A4=EB=B0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/StudentActivityServiceImpl.kt | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/bitgouel-api/src/main/kotlin/team/msg/domain/student/service/StudentActivityServiceImpl.kt b/bitgouel-api/src/main/kotlin/team/msg/domain/student/service/StudentActivityServiceImpl.kt index de5d26c2f..ea743b212 100644 --- a/bitgouel-api/src/main/kotlin/team/msg/domain/student/service/StudentActivityServiceImpl.kt +++ b/bitgouel-api/src/main/kotlin/team/msg/domain/student/service/StudentActivityServiceImpl.kt @@ -65,7 +65,16 @@ class StudentActivityServiceImpl( */ @Transactional(rollbackFor = [Exception::class]) override fun updateStudentActivity(id: UUID, request: UpdateStudentActivityRequest) { - val studentActivity = validateStudent(id) + val user = userUtil.queryCurrentUser() + + val student = studentRepository.findByUser(user) + ?: throw StudentNotFoundException("학생을 찾을 수 없습니다. info : [ userId = ${user.id}, username = ${user.name} ]") + + val studentActivity = studentActivityRepository.findByIdOrNull(id) + ?: throw StudentActivityNotFoundException("학생 활동을 찾을 수 없습니다. info : [ studentActivityId = $id ]") + + if(student.id != studentActivity.student.id) + throw ForbiddenStudentActivityException("해당 학생 활동에 대한 권한이 없습니다. info : [ studentId = ${student.id} ]") val updatedStudentActivity = StudentActivity( id = studentActivity.id, @@ -87,8 +96,17 @@ class StudentActivityServiceImpl( */ @Transactional(rollbackFor = [Exception::class]) override fun deleteStudentActivity(id: UUID) { - val studentActivity = validateStudent(id) - + val user = userUtil.queryCurrentUser() + + val student = studentRepository.findByUser(user) + ?: throw StudentNotFoundException("학생을 찾을 수 없습니다. info : [ userId = ${user.id}, username = ${user.name} ]") + + val studentActivity = studentActivityRepository.findByIdOrNull(id) + ?: throw StudentActivityNotFoundException("학생 활동을 찾을 수 없습니다. info : [ studentActivityId = $id ]") + + if(student.id != studentActivity.student.id) + throw ForbiddenStudentActivityException("해당 학생 활동에 대한 권한이 없습니다. info : [ studentId = ${student.id} ]") + studentActivityRepository.delete(studentActivity) } @@ -117,16 +135,7 @@ class StudentActivityServiceImpl( * @param 학생활동을 검증하기 위한 id */ private fun validateStudent(id: UUID): StudentActivity { - val user = userUtil.queryCurrentUser() - val student = studentRepository.findByUser(user) - ?: throw StudentNotFoundException("학생을 찾을 수 없습니다. info : [ userId = ${user.id}, username = ${user.name} ]") - - val studentActivity = studentActivityRepository.findByIdOrNull(id) - ?: throw StudentActivityNotFoundException("학생 활동을 찾을 수 없습니다. info : [ studentActivityId = $id ]") - - if(student.id != studentActivity.student.id) - throw ForbiddenStudentActivityException("해당 학생 활동에 대한 권한이 없습니다. info : [ studentId = ${student.id} ]") return studentActivity }