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

114 학생 활동 상세 조회 api 개발 #122

Merged
merged 15 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
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 @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController
import team.msg.domain.student.mapper.StudentActivityMapper
import team.msg.domain.student.presentation.data.response.AllStudentActivitiesResponse
import team.msg.domain.student.presentation.data.response.StudentActivitiesByStudentResponse
import team.msg.domain.student.presentation.data.response.StudentActivityDetailResponse
import team.msg.domain.student.presentation.data.web.CreateStudentActivityWebRequest
import team.msg.domain.student.presentation.data.web.UpdateStudentActivityWebRequest
import team.msg.domain.student.service.StudentActivityService
Expand Down Expand Up @@ -75,4 +76,10 @@ class StudentActivityController(
val response = studentActivityService.queryMyStudentActivities(pageable)
return ResponseEntity.status(HttpStatus.OK).body(response)
}

@GetMapping("/{id}/detail")
fun queryStudentActivityDetail(@PathVariable id: UUID): ResponseEntity<StudentActivityDetailResponse> {
val response = studentActivityService.queryStudentActivityDetail(id)
return ResponseEntity.status(HttpStatus.OK).body(response)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

detail 붙인 이유가 무엇인가요? id에 GET 하면 되는거 아닌가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

학생 활동을 학생 단위로 조회하는 api와 endpoint가 겹쳐서 detail을 붙이게 되었습니다

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.springframework.data.domain.Page
import team.msg.common.enums.ApproveStatus
import team.msg.domain.student.model.StudentActivity
import team.msg.domain.user.model.User
import java.time.LocalDateTime
import java.util.*

data class StudentActivityResponse(
Expand All @@ -25,6 +26,15 @@ data class StudentActivityResponse(
)
}

fun detailOf(studentActivity: StudentActivity): StudentActivityDetailResponse =
StudentActivityDetailResponse(
id = studentActivity.id,
title = studentActivity.title,
content = studentActivity.content,
credit = studentActivity.credit,
activityDate = studentActivity.activityDate,
modifiedAt = studentActivity.modifiedAt
)
}
}

Expand All @@ -34,4 +44,13 @@ data class AllStudentActivitiesResponse(

data class StudentActivitiesByStudentResponse(
val activities: Page<StudentActivityResponse>
)
Copy link
Contributor

Choose a reason for hiding this comment

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

이것도 ByStudentResponse 말고 StudentActivitiesResponse 하나로 써주시는게 좋을 것 같아요 StudentsReponse처럼요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

변경하였습니다
40dff6d


data class StudentActivityDetailResponse(
val id: UUID,
val title: String,
val content: String,
val credit: Int,
val activityDate: LocalDateTime,
val modifiedAt: LocalDateTime
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import team.msg.domain.student.presentation.data.request.CreateStudentActivityRe
import team.msg.domain.student.presentation.data.request.UpdateStudentActivityRequest
import team.msg.domain.student.presentation.data.response.AllStudentActivitiesResponse
import team.msg.domain.student.presentation.data.response.StudentActivitiesByStudentResponse
import team.msg.domain.student.presentation.data.response.StudentActivityDetailResponse
import java.util.*

interface StudentActivityService {
Expand All @@ -16,4 +17,5 @@ interface StudentActivityService {
fun queryAllStudentActivities(pageable: Pageable): AllStudentActivitiesResponse
fun queryStudentActivitiesByStudent(studentId: UUID, pageable: Pageable): StudentActivitiesByStudentResponse
fun queryMyStudentActivities(pageable: Pageable): StudentActivitiesByStudentResponse
fun queryStudentActivityDetail(id: UUID): StudentActivityDetailResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ import team.msg.domain.student.event.UpdateStudentActivityEvent
import team.msg.domain.student.exception.ForbiddenStudentActivityException
import team.msg.domain.student.exception.StudentActivityNotFoundException
import team.msg.domain.student.exception.StudentNotFoundException
import team.msg.domain.student.model.Student
import team.msg.domain.student.model.StudentActivity
import team.msg.domain.student.presentation.data.request.CreateStudentActivityRequest
import team.msg.domain.student.presentation.data.request.UpdateStudentActivityRequest
import team.msg.domain.student.presentation.data.response.AllStudentActivitiesResponse
import team.msg.domain.student.presentation.data.response.StudentActivitiesByStudentResponse
import team.msg.domain.student.presentation.data.response.StudentActivityDetailResponse
import team.msg.domain.student.presentation.data.response.StudentActivityResponse
import team.msg.domain.student.repository.StudentActivityRepository
import team.msg.domain.student.repository.StudentRepository
import team.msg.domain.teacher.exception.TeacherNotFoundException
import team.msg.domain.teacher.model.Teacher
import team.msg.domain.teacher.repository.TeacherRepository
import java.util.*

Expand Down Expand Up @@ -227,4 +230,32 @@ class StudentActivityServiceImpl(
return response
}

/**
* 학생 활동의 상세 정보를 조회하는 비즈니스 로직
* @param 학생 활동을 조회하기 위한 id
*/
@Transactional(rollbackFor = [Exception::class])
ani2689 marked this conversation as resolved.
Show resolved Hide resolved
override fun queryStudentActivityDetail(id: UUID): StudentActivityDetailResponse {
val user = userUtil.queryCurrentUser()

val entity = userUtil.getAuthorityEntityAndOrganization(user).first

val studentActivity = studentActivityRepository.findByIdOrNull(id)
?: throw StudentActivityNotFoundException("학생 활동을 찾을 수 없습니다")
ani2689 marked this conversation as resolved.
Show resolved Hide resolved

when(entity) {
is Student -> {
if(entity != studentActivity.student)
throw ForbiddenStudentActivityException("해당 학생 활동에 대한 권한이 없습니다. info : [ userId = ${user.id} ]")
}
is Teacher -> {
if(entity != studentActivity.teacher)
throw ForbiddenStudentActivityException("해당 학생 활동에 대한 권한이 없습니다. info : [ userId = ${user.id} ]")
}
Comment on lines +250 to +258
Copy link
Contributor

Choose a reason for hiding this comment

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

else일때도 처리해줘야하지 않을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

else 분기도 처리하였는데 검증로직이 따로 필요 없는 어드민의 경우에는 아무것도 수행하지 않도록 하였는데 어떻게 처리할지 좋은 생각이 있으시다면 피드백 부탁드립니다
427d8e2

Copy link
Contributor

Choose a reason for hiding this comment

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

else일때 말고 그럼 GOVERNMENT, COMPANY_INSTRUCTOR .... -> forbidden 이런식으로 가도 되고 when 대신 assert나 require, check 사용해서 해결해도 될거같네요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

0de932d
변경했는데 현재 InvalidRoleException이 401에러를 띄워주고 있는 상태인데 403이 더 적절한 상태코드 인것 같아서 수정하려고 하는데 괜찮을까요

Copy link
Contributor

Choose a reason for hiding this comment

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

InvalidRoleException을 던지는 것 보단 ForbiddenStudentActivityException을 던지는게 맞지 않을까 싶어요

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

변경했습니다
a19ccb7

}

val response = StudentActivityResponse.detailOf(studentActivity)

return response
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class SecurityConfig(
.mvcMatchers(HttpMethod.GET, "/activity").hasRole(ADMIN)
.mvcMatchers(HttpMethod.GET, "/activity/my").hasRole(STUDENT)
.mvcMatchers(HttpMethod.GET, "/activity/{student_id}").hasRole(TEACHER)
.mvcMatchers(HttpMethod.GET, "/activity/{id}/detail").hasAnyRole(STUDENT, TEACHER, ADMIN)

// lecture
.mvcMatchers(HttpMethod.POST, "/lecture").hasAnyRole(PROFESSOR, COMPANY_INSTRUCTOR, GOVERNMENT)
Expand Down