Skip to content

Commit

Permalink
Merge pull request #115 from GSM-MSG/109-feat/query-user-list
Browse files Browse the repository at this point in the history
#109 동아리에 속한 학생 리스트 조회
  • Loading branch information
JuuuuHong authored Nov 11, 2023
2 parents 9d5a1e1 + 11a7a9b commit b2e06f5
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import team.msg.domain.club.presentation.data.response.AllClubResponse
import team.msg.domain.club.presentation.data.response.ClubDetailsResponse
import team.msg.domain.club.service.ClubService
import team.msg.domain.school.enums.HighSchool
import team.msg.domain.student.presentation.data.response.AllStudentsResponse

@RestController
@RequestMapping("/club")
Expand All @@ -28,4 +29,10 @@ class ClubController(
val response = clubService.queryClubDetailsService(id)
return ResponseEntity.status(HttpStatus.OK).body(response)
}

@GetMapping("/{id}/member")
fun queryUserByClubId(@PathVariable id: Long): ResponseEntity<AllStudentsResponse> {
val response = clubService.queryAllStudentsByClubId(id)
return ResponseEntity.status(HttpStatus.OK).body(response)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package team.msg.domain.club.presentation.data.response

import team.msg.domain.club.model.Club
import team.msg.domain.school.enums.HighSchool

data class ClubResponse(
val id: Long,
Expand All @@ -15,9 +14,9 @@ data class ClubResponse(
)
}

fun detailOf(club: Club, highSchool: HighSchool, headCount: Int) = ClubDetailsResponse(
fun detailOf(club: Club, headCount: Int) = ClubDetailsResponse(
clubName = club.name,
highSchoolName = highSchool.schoolName,
highSchoolName = club.school.highSchool.schoolName,
headCount = headCount
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package team.msg.domain.club.service
import team.msg.domain.club.presentation.data.response.AllClubResponse
import team.msg.domain.club.presentation.data.response.ClubDetailsResponse
import team.msg.domain.school.enums.HighSchool
import team.msg.domain.student.presentation.data.response.AllStudentsResponse

interface ClubService {
fun queryAllClubsService(highSchool: HighSchool): AllClubResponse
fun queryClubDetailsService(id: Long): ClubDetailsResponse
fun queryAllStudentsByClubId(id: Long): AllStudentsResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import team.msg.domain.club.exception.ClubNotFoundException
import team.msg.domain.club.presentation.data.response.AllClubResponse
import team.msg.domain.club.presentation.data.response.ClubDetailsResponse
import team.msg.domain.club.presentation.data.response.ClubResponse
import team.msg.domain.club.presentation.data.response.*
import team.msg.domain.club.repository.ClubRepository
import team.msg.domain.school.enums.HighSchool
import team.msg.domain.school.exception.SchoolNotFoundException
import team.msg.domain.school.repository.SchoolRepository
import team.msg.domain.student.presentation.data.response.AllStudentsResponse
import team.msg.domain.student.presentation.data.response.StudentResponse
import team.msg.domain.student.repository.StudentRepository

@Service
Expand Down Expand Up @@ -49,7 +49,25 @@ class ClubServiceImpl(

val headCount = studentRepository.countByClub(club).toInt()

val response = ClubResponse.detailOf(club, club.school.highSchool, headCount)
val response = ClubResponse.detailOf(club, headCount)

return response
}

/**
* 동아리를의 학생 리스트를 조회하는 비즈니스 로직
* @param 동아리에 속한 학생 리스트를 조회하기 위한 id
*/
@Transactional(readOnly = true)
override fun queryAllStudentsByClubId(id: Long): AllStudentsResponse {
val club = clubRepository.findByIdOrNull(id)
?: throw ClubNotFoundException("존재하지 않는 동아리 입니다. info : [ clubId = $id ]")

val students = studentRepository.findAllByClub(club)

val response = AllStudentsResponse(
StudentResponse.listOf(students)
)

return response
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class StudentActivityResponse(
val approveStatus: ApproveStatus
) {
companion object {
fun pageOf(studentActivities: Page<StudentActivity>,user: User): Page<StudentActivityResponse> =
fun pageOf(studentActivities: Page<StudentActivity>, user: User): Page<StudentActivityResponse> =
studentActivities.map {
StudentActivityResponse(
activityId = it.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package team.msg.domain.student.presentation.data.response

import team.msg.domain.student.model.Student
import team.msg.domain.user.enums.Authority
import java.util.*

class StudentResponse(
val id: UUID,
val name: String,
val authority: Authority
) {
companion object {
fun listOf(students: List<Student>) = students.map {
StudentResponse(
id = it.user!!.id,
name = it.user!!.name,
authority = it.user!!.authority
)
}
}
}

data class AllStudentsResponse(
val students: List<StudentResponse>
)
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class SecurityConfig(
// club
.mvcMatchers(HttpMethod.GET, "/club").hasRole(ADMIN)
.mvcMatchers(HttpMethod.GET, "/club/{id}").hasAnyRole(STUDENT, ADMIN, PROFESSOR, COMPANY_INSTRUCTOR, BBOZZAK, TEACHER, GOVERNMENT)
.mvcMatchers(HttpMethod.GET, "/club/{id}/member").hasAnyRole(STUDENT, ADMIN, PROFESSOR, COMPANY_INSTRUCTOR, BBOZZAK, TEACHER, GOVERNMENT)

// activity
.mvcMatchers(HttpMethod.POST, "/activity").hasRole(STUDENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ interface StudentRepository : CrudRepository<Student, UUID> {
@EntityGraph(attributePaths = ["user"], type = EntityGraph.EntityGraphType.FETCH)
fun findStudentById(id: UUID): Student?
fun countByClub(club: Club): Long
fun findAllByClub(club: Club): List<Student>
}

0 comments on commit b2e06f5

Please sign in to comment.