Skip to content

Commit

Permalink
Merge pull request #122 from GSM-MSG/114-feat/student-activity-detail…
Browse files Browse the repository at this point in the history
…-api

114 학생 활동 상세 조회 api 개발
  • Loading branch information
KimTaeO authored Nov 12, 2023
2 parents b2e06f5 + e271f52 commit 1bfb6e8
Showing 5 changed files with 80 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -14,7 +14,8 @@ import org.springframework.web.bind.annotation.RequestMapping
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.StudentActivitiesResponse
import team.msg.domain.student.presentation.data.response.StudentActivityDetailsResponse
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
@@ -65,14 +66,20 @@ class StudentActivityController(
}

@GetMapping("/{student_id}")
fun queryStudentActivitiesByStudent(@PathVariable("student_id") studentId: UUID, pageable: Pageable): ResponseEntity<StudentActivitiesByStudentResponse> {
fun queryStudentActivitiesByStudent(@PathVariable("student_id") studentId: UUID, pageable: Pageable): ResponseEntity<StudentActivitiesResponse> {
val response = studentActivityService.queryStudentActivitiesByStudent(studentId, pageable)
return ResponseEntity.status(HttpStatus.OK).body(response)
}

@GetMapping("/my")
fun queryMyStudentActivities(pageable: Pageable): ResponseEntity<StudentActivitiesByStudentResponse> {
fun queryMyStudentActivities(pageable: Pageable): ResponseEntity<StudentActivitiesResponse> {
val response = studentActivityService.queryMyStudentActivities(pageable)
return ResponseEntity.status(HttpStatus.OK).body(response)
}

@GetMapping("/{id}/detail")
fun queryStudentActivityDetail(@PathVariable id: UUID): ResponseEntity<StudentActivityDetailsResponse> {
val response = studentActivityService.queryStudentActivityDetail(id)
return ResponseEntity.status(HttpStatus.OK).body(response)
}
}
Original file line number Diff line number Diff line change
@@ -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(
@@ -25,13 +26,31 @@ data class StudentActivityResponse(
)
}

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

data class AllStudentActivitiesResponse(
val activities: Page<StudentActivityResponse>
)

data class StudentActivitiesByStudentResponse(
data class StudentActivitiesResponse(
val activities: Page<StudentActivityResponse>
)

data class StudentActivityDetailsResponse(
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
@@ -4,7 +4,8 @@ import org.springframework.data.domain.Pageable
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.StudentActivitiesResponse
import team.msg.domain.student.presentation.data.response.StudentActivityDetailsResponse
import java.util.*

interface StudentActivityService {
@@ -14,6 +15,7 @@ interface StudentActivityService {
fun rejectStudentActivity(id: UUID)
fun approveStudentActivity(id: UUID)
fun queryAllStudentActivities(pageable: Pageable): AllStudentActivitiesResponse
fun queryStudentActivitiesByStudent(studentId: UUID, pageable: Pageable): StudentActivitiesByStudentResponse
fun queryMyStudentActivities(pageable: Pageable): StudentActivitiesByStudentResponse
fun queryStudentActivitiesByStudent(studentId: UUID, pageable: Pageable): StudentActivitiesResponse
fun queryMyStudentActivities(pageable: Pageable): StudentActivitiesResponse
fun queryStudentActivityDetail(id: UUID): StudentActivityDetailsResponse
}
Original file line number Diff line number Diff line change
@@ -7,19 +7,26 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import team.msg.common.enums.ApproveStatus
import team.msg.common.util.UserUtil
import team.msg.domain.bbozzak.model.Bbozzak
import team.msg.domain.company.model.CompanyInstructor
import team.msg.domain.government.model.Government
import team.msg.domain.professor.model.Professor
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.StudentActivitiesResponse
import team.msg.domain.student.presentation.data.response.StudentActivityDetailsResponse
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.*

@@ -186,7 +193,7 @@ class StudentActivityServiceImpl(
* @param 학생활동을 조회하기 위한 학생 id 및 페이징을 처리하기 위한 pageable
*/
@Transactional(readOnly = true)
override fun queryStudentActivitiesByStudent(studentId: UUID, pageable: Pageable): StudentActivitiesByStudentResponse {
override fun queryStudentActivitiesByStudent(studentId: UUID, pageable: Pageable): StudentActivitiesResponse {
val user = userUtil.queryCurrentUser()

val student = studentRepository.findStudentById(studentId)
@@ -200,7 +207,7 @@ class StudentActivityServiceImpl(

val studentActivities = studentActivityRepository.findAllByStudent(student, pageable)

val response = StudentActivitiesByStudentResponse(
val response = StudentActivitiesResponse(
StudentActivityResponse.pageOf(studentActivities, student.user!!)
)

@@ -212,19 +219,51 @@ class StudentActivityServiceImpl(
* @param 페이징을 처리하기 위한 pageable
*/
@Transactional(readOnly = true)
override fun queryMyStudentActivities(pageable: Pageable): StudentActivitiesByStudentResponse {
override fun queryMyStudentActivities(pageable: Pageable): StudentActivitiesResponse {
val user = userUtil.queryCurrentUser()

val student = studentRepository.findByUser(user)
?: throw StudentNotFoundException("학생을 찾을 수 없습니다. info : [ userId = ${user.id}, username = ${user.name} ]")

val studentActivities = studentActivityRepository.findAllByStudent(student, pageable)

val response = StudentActivitiesByStudentResponse(
val response = StudentActivitiesResponse(
StudentActivityResponse.pageOf(studentActivities, user)
)

return response
}

/**
* 학생 활동의 상세 정보를 조회하는 비즈니스 로직
* @param 학생 활동을 조회하기 위한 id
*/
@Transactional(readOnly = true)
override fun queryStudentActivityDetail(id: UUID): StudentActivityDetailsResponse {
val user = userUtil.queryCurrentUser()

val entity = userUtil.getAuthorityEntityAndOrganization(user).first

val studentActivity = studentActivityRepository.findByIdOrNull(id)
?: throw StudentActivityNotFoundException("학생 활동을 찾을 수 없습니다. info : [ studentActivityId = $id ]")

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} ]")
}
is Bbozzak,
is Professor,
is CompanyInstructor,
is Government -> throw ForbiddenStudentActivityException("유효하지 않은 권한입니다. info : [ userAuthority = ${user.authority} ]")
}

val response = StudentActivityResponse.detailOf(studentActivity)

return response
}
}
Original file line number Diff line number Diff line change
@@ -73,6 +73,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)

0 comments on commit 1bfb6e8

Please sign in to comment.