Skip to content

Commit

Permalink
πŸ”€ :: (#18) feign μš”μ²­ μ—λŸ¬ μ½”λ“œ μˆ˜μ •
Browse files Browse the repository at this point in the history
πŸ”€ :: (#18) feign μš”μ²­ μ—λŸ¬ μ½”λ“œ μˆ˜μ •
  • Loading branch information
alsco39 authored May 1, 2023
2 parents 88421c8 + 7be22d6 commit 1ae7b2b
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.pickdsm.pickserverspring.domain.teacher.spi.StatusCommandTeacherSpi
import com.pickdsm.pickserverspring.domain.teacher.spi.TimeQueryTeacherSpi
import com.pickdsm.pickserverspring.domain.time.exception.TimeNotFoundException
import com.pickdsm.pickserverspring.domain.time.spi.QueryTimeSpi
import com.pickdsm.pickserverspring.domain.user.dto.request.UserInfoRequest
import com.pickdsm.pickserverspring.domain.user.exception.UserNotFoundException
import com.pickdsm.pickserverspring.domain.user.spi.UserSpi
import java.time.LocalDate
Expand All @@ -55,7 +56,8 @@ class AdminUseCase(
val timeList = timeQueryTeacherSpi.queryTime(LocalDate.now())
val nowPeriod = queryTimeSpi.queryNowPeriod(timeList)
val userIdList = request.userList.map { it.userId }
val userInfoList = userSpi.queryUserInfo(userIdList)
val userIdRequest = UserInfoRequest(userIdList)
val userInfoList = userSpi.queryUserInfo(userIdRequest)

val changeStatusList: List<Status> = request.userList.map {
val user = userInfoList.find { user -> user.id == it.userId }
Expand Down Expand Up @@ -118,7 +120,8 @@ class AdminUseCase(
DirectorType.AFTER_SCHOOL -> {
val afterSchoolList = queryAfterSchoolSpi.queryAfterSchoolListByClassroomId(classroomId)
val afterSchoolStudentIdList = afterSchoolList.map { it.studentId }
val afterSchoolUserInfos = userSpi.queryUserInfo(afterSchoolStudentIdList)
val userIdRequest = UserInfoRequest(afterSchoolStudentIdList)
val afterSchoolUserInfos = userSpi.queryUserInfo(userIdRequest)

afterSchoolUserInfos.map { user ->
val afterSchoolStatusList = dateStatusList.filter { it.studentId == user.id }
Expand Down Expand Up @@ -150,7 +153,8 @@ class AdminUseCase(
DirectorType.FRI_CLUB, DirectorType.TUE_CLUB -> {
val clubList = queryClubSpi.queryClubListByClassroomId(classroomId)
val clubStudentIdList = clubList.map { it.studentId }
val clubUserInfos = userSpi.queryUserInfo(clubStudentIdList)
val userIdRequest = UserInfoRequest(clubStudentIdList)
val clubUserInfos = userSpi.queryUserInfo(userIdRequest)

clubUserInfos.map { user ->
val clubStatusList = dateStatusList.filter { it.studentId == user.id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.pickdsm.pickserverspring.domain.afterschool.exception.AfterSchoolNotF
import com.pickdsm.pickserverspring.domain.afterschool.exception.AfterSchoolStudentExistsException
import com.pickdsm.pickserverspring.domain.afterschool.spi.CommandAfterSchoolSpi
import com.pickdsm.pickserverspring.domain.afterschool.spi.QueryAfterSchoolSpi
import com.pickdsm.pickserverspring.domain.user.dto.request.UserInfoRequest
import com.pickdsm.pickserverspring.domain.user.exception.UserNotFoundException
import com.pickdsm.pickserverspring.domain.user.spi.UserSpi
import java.util.*
Expand Down Expand Up @@ -55,7 +56,8 @@ class AfterSchoolUseCase(
?: throw AfterSchoolNotFoundException
val afterSchoolList = queryAfterSchoolSpi.queryAfterSchoolListByAfterSchoolId(afterSchoolId)
val afterSchoolStudentIdList = afterSchoolList.map { it.studentId }
val afterSchoolStudentInfos = userSpi.queryUserInfo(afterSchoolStudentIdList)
val userIdRequest = UserInfoRequest(afterSchoolStudentIdList)
val afterSchoolStudentInfos = userSpi.queryUserInfo(userIdRequest)

val afterSchoolUsers = afterSchoolList.map {
val user = afterSchoolStudentInfos.find { user -> user.id == it.studentId }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.pickdsm.pickserverspring.domain.application.spi

import com.pickdsm.pickserverspring.domain.user.User
import com.pickdsm.pickserverspring.domain.user.dto.request.UserInfoRequest
import java.util.UUID

interface UserQueryApplicationSpi {

fun queryUserInfo(ids: List<UUID>): List<User>
fun queryUserInfo(request: UserInfoRequest): List<User>

fun queryUserInfoByUserId(userId: UUID): User
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.pickdsm.pickserverspring.domain.selfstudydirector.spi.QueryTypeSpi
import com.pickdsm.pickserverspring.domain.teacher.spi.StatusCommandTeacherSpi
import com.pickdsm.pickserverspring.domain.teacher.spi.TimeQueryTeacherSpi
import com.pickdsm.pickserverspring.domain.time.exception.TimeNotFoundException
import com.pickdsm.pickserverspring.domain.user.dto.request.UserInfoRequest
import com.pickdsm.pickserverspring.domain.user.exception.UserNotFoundException
import com.pickdsm.pickserverspring.domain.user.spi.UserSpi
import java.time.DayOfWeek
Expand Down Expand Up @@ -100,7 +101,8 @@ class ApplicationUseCase(
val todayStatusList = queryStatusSpi.queryAwaitStudentListByToday(today)
val todayApplicationStudentIdList = todayStatusList.map { it.studentId }
val timeList = timeQueryTeacherSpi.queryTime(today)
val userList = userQueryApplicationSpi.queryUserInfo(todayApplicationStudentIdList)
val userIdRequest = UserInfoRequest(todayApplicationStudentIdList)
val userList = userQueryApplicationSpi.queryUserInfo(userIdRequest)

val outing = mutableListOf<QueryPicnicApplicationElement>()

Expand Down Expand Up @@ -324,7 +326,8 @@ class ApplicationUseCase(
val todayPicnicStudentInfoList = queryStatusSpi.queryPicnicStudentInfoListByToday(LocalDate.now())
val todayPicnicStudentIdList = todayPicnicStudentInfoList.map { status -> status.studentId }
val timeList = timeQueryTeacherSpi.queryTime(LocalDate.now())
val userList = userQueryApplicationSpi.queryUserInfo(todayPicnicStudentIdList)
val userIdRequest = UserInfoRequest(todayPicnicStudentIdList)
val userList = userQueryApplicationSpi.queryUserInfo(userIdRequest)

val outing: List<QueryPicnicStudentElement> = todayPicnicStudentInfoList
.map { status ->
Expand Down Expand Up @@ -358,7 +361,8 @@ class ApplicationUseCase(
DirectorType.AFTER_SCHOOL -> {
val afterSchoolList = queryAfterSchoolSpi.queryAfterSchoolListByClassroomId(classroomId)
val afterSchoolStudentIdList = afterSchoolList.map { it.studentId }
val afterSchoolUserInfos = userSpi.queryUserInfo(afterSchoolStudentIdList)
val userIdRequest = UserInfoRequest(afterSchoolStudentIdList)
val afterSchoolUserInfos = userSpi.queryUserInfo(userIdRequest)

afterSchoolUserInfos.map { user ->
val status = todayStudentStatusList.find { user.id == it.studentId }
Expand All @@ -378,7 +382,8 @@ class ApplicationUseCase(
DirectorType.TUE_CLUB, DirectorType.FRI_CLUB -> {
val clubList = queryClubSpi.queryClubListByClassroomId(classroomId)
val clubStudentIdList = clubList.map { it.studentId }
val clubUserInfos = userSpi.queryUserInfo(clubStudentIdList)
val userIdRequest = UserInfoRequest(clubStudentIdList)
val clubUserInfos = userSpi.queryUserInfo(userIdRequest)

clubUserInfos.map { user ->
val status = todayStudentStatusList.find { user.id == it.studentId }
Expand Down Expand Up @@ -421,7 +426,8 @@ class ApplicationUseCase(

override fun savePicnicPass(request: DomainPicnicPassRequest) {
val teacherId = userSpi.getCurrentUserId()
val userList = userSpi.queryUserInfo(request.userIdList)
val userIdRequest = UserInfoRequest(request.userIdList)
val userList = userSpi.queryUserInfo(userIdRequest)

val statusList = request.userIdList.map {
val user = userList.find { user -> user.id == it }
Expand All @@ -441,7 +447,8 @@ class ApplicationUseCase(

override fun savePicnicAcceptOrRefuse(request: DomainPicnicAcceptOrRefuseRequest) {
val teacherId = userSpi.getCurrentUserId()
val userList = userSpi.queryUserInfo(request.userIdList)
val userIdRequest = UserInfoRequest(request.userIdList)
val userList = userSpi.queryUserInfo(userIdRequest)
val todayAwaitStatusList = queryStatusSpi.queryAwaitStudentListByToday(LocalDate.now())

when (request.type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.pickdsm.pickserverspring.domain.teacher.spi.StatusCommandTeacherSpi
import com.pickdsm.pickserverspring.domain.teacher.spi.TimeQueryTeacherSpi
import com.pickdsm.pickserverspring.domain.time.exception.TimeNotFoundException
import com.pickdsm.pickserverspring.domain.user.User
import com.pickdsm.pickserverspring.domain.user.dto.request.UserInfoRequest
import com.pickdsm.pickserverspring.domain.user.spi.UserSpi
import java.time.DayOfWeek
import java.time.LocalDate
Expand Down Expand Up @@ -116,7 +117,8 @@ class ClassroomMovementUseCase(
): QueryMovementStudentList {
val todayMovementStudentInfoList = queryStatusSpi.queryMovementStudentInfoListByToday(LocalDate.now())
val todayMovementStudentIdList = todayMovementStudentInfoList.map { movement -> movement.studentId }
val userList = userQueryApplicationSpi.queryUserInfo(todayMovementStudentIdList)
val userIdRequest = UserInfoRequest(todayMovementStudentIdList)
val userList = userQueryApplicationSpi.queryUserInfo(userIdRequest)
val movementStudent = mutableListOf<MovementStudentElement>()
val studentAttendanceList = adminApi.getTypeByDate(LocalDate.now())

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.pickdsm.pickserverspring.domain.selfstudydirector.spi

import com.pickdsm.pickserverspring.domain.user.User
import com.pickdsm.pickserverspring.domain.user.dto.request.UserInfoRequest
import java.util.UUID

interface UserQuerySelfStudyDirectorSpi {

fun queryUserInfo(ids: List<UUID>): List<User>
fun queryUserInfo(request: UserInfoRequest): List<User>
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.pickdsm.pickserverspring.domain.selfstudydirector.spi.QuerySelfStudyD
import com.pickdsm.pickserverspring.domain.selfstudydirector.spi.QueryTypeSpi
import com.pickdsm.pickserverspring.domain.selfstudydirector.spi.UserQuerySelfStudyDirectorSpi
import com.pickdsm.pickserverspring.domain.user.User
import com.pickdsm.pickserverspring.domain.user.dto.request.UserInfoRequest
import com.pickdsm.pickserverspring.domain.user.spi.UserSpi
import java.time.LocalDate

Expand All @@ -34,7 +35,8 @@ class SelfStudyDirectorUseCase(
val startDate = LocalDate.of(LocalDate.now().year, month.toInt(), 1)
val selfStudyDirectorList = querySelfStudyDirectorSpi.querySelfStudyDirectorByDate(startDate)
val teacherIdList = selfStudyDirectorList.map { it.teacherId }
val userInfoList = userQuerySelfStudyDirectorSpi.queryUserInfo(teacherIdList)
val userIdRequest = UserInfoRequest(teacherIdList)
val userInfoList = userQuerySelfStudyDirectorSpi.queryUserInfo(userIdRequest)
val typeList = queryTypeSpi.queryTypeListByDate(startDate)

// ν•΄λ‹Ή λ‹¬μ˜ 1일뢀터 λ§ˆμ§€λ§‰μΌκΉŒμ§€ λ°˜λ³΅λ¬Έμ„ λŒλ©΄μ„œ κ°’ 가곡
Expand All @@ -60,7 +62,8 @@ class SelfStudyDirectorUseCase(
override fun getTodaySelfStudyTeacher(): TodaySelfStudyTeacherResponse {
val selfStudyList = querySelfStudyDirectorSpi.querySelfStudyDirectorByToday()
val teacherIdList = selfStudyList.map { it.teacherId }
val teacherList = userQuerySelfStudyDirectorSpi.queryUserInfo(teacherIdList)
val userIdRequest = UserInfoRequest(teacherIdList)
val teacherList = userQuerySelfStudyDirectorSpi.queryUserInfo(userIdRequest)

return TodaySelfStudyTeacherResponse(
secondFloor = getTeacherName(teacherList, selfStudyList, 2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.pickdsm.pickserverspring.domain.teacher.spi

import com.pickdsm.pickserverspring.domain.user.User
import com.pickdsm.pickserverspring.domain.user.dto.UserInfo
import com.pickdsm.pickserverspring.domain.user.dto.request.UserInfoRequest
import java.util.UUID

interface UserQueryTeacherSpi {

fun queryUserInfo(ids: List<UUID>): List<User>
fun queryUserInfo(request: UserInfoRequest): List<User>

fun queryUserInfoByGradeAndClassNum(grade: Int?, classNum: Int?): List<UserInfo>
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.pickdsm.pickserverspring.domain.teacher.api.dto.response.QueryStudent
import com.pickdsm.pickserverspring.domain.teacher.spi.StatusCommandTeacherSpi
import com.pickdsm.pickserverspring.domain.teacher.spi.TimeQueryTeacherSpi
import com.pickdsm.pickserverspring.domain.time.exception.TimeNotFoundException
import com.pickdsm.pickserverspring.domain.user.dto.request.UserInfoRequest
import com.pickdsm.pickserverspring.domain.user.exception.UserNotFoundException
import com.pickdsm.pickserverspring.domain.user.spi.UserSpi
import java.time.LocalDate
Expand Down Expand Up @@ -87,8 +88,8 @@ class TeacherUseCase(
?: throw ClassroomNotFoundException
val movementStatusList = queryStatusSpi.queryMovementStatusListByTodayAndClassroomId(classroomId)
val movementStudentIdList = movementStatusList.map { it.studentId }

val movementUserInfos = userSpi.queryUserInfo(movementStudentIdList)
val userIdRequest = UserInfoRequest(movementStudentIdList)
val movementUserInfos = userSpi.queryUserInfo(userIdRequest)

val movementList = movementStatusList.map {
val user = movementUserInfos.find { user -> user.id == it.studentId }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pickdsm.pickserverspring.domain.user.dto.request

import java.util.*

data class UserInfoRequest(
val userIds: List<UUID>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package com.pickdsm.pickserverspring.common.feign.client
import com.pickdsm.pickserverspring.common.feign.client.dto.response.UserInfoResponse
import com.pickdsm.pickserverspring.common.feign.client.dto.response.UserInfoResponse.UserInfoElement
import com.pickdsm.pickserverspring.common.feign.client.dto.response.UserResponse
import com.pickdsm.pickserverspring.domain.user.dto.request.UserInfoRequest
import org.springframework.cloud.openfeign.FeignClient
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestParam
import java.util.UUID
import javax.validation.Valid

@FeignClient(name = "UserClient", url = "\${service.scheme}://\${service.user.host}")
interface UserClient {

@PostMapping("/users/id")
fun getUserInfo(@Valid @RequestBody ids: List<UUID>): UserInfoResponse
fun getUserInfo(@RequestBody request: UserInfoRequest): UserInfoResponse

@GetMapping("/users/class")
fun getUserInfoByGradeAndClassNum(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pickdsm.pickserverspring.domain.user.persistence

import com.pickdsm.pickserverspring.common.feign.client.UserClient
import com.pickdsm.pickserverspring.domain.user.dto.request.UserInfoRequest
import com.pickdsm.pickserverspring.domain.user.User
import com.pickdsm.pickserverspring.domain.user.dto.UserInfo
import com.pickdsm.pickserverspring.domain.user.spi.UserSpi
Expand All @@ -16,11 +17,11 @@ class UserPersistenceAdapter(
override fun getCurrentUserId(): UUID =
UUID.fromString(SecurityContextHolder.getContext().authentication.name)

override fun queryUserInfo(ids: List<UUID>): List<User> =
if (ids.isEmpty()) {
override fun queryUserInfo(request: UserInfoRequest): List<User> =
if (request.userIds.isEmpty()) {
emptyList()
} else {
userClient.getUserInfo(ids)
userClient.getUserInfo(request)
.users
.map {
User(
Expand Down

0 comments on commit 1ae7b2b

Please sign in to comment.