Skip to content

Commit

Permalink
πŸ”€ :: μžμŠ΅κ°λ…μ„ μƒλ‹˜ 리슀트 쑰회 API μ—λŸ¬ ν•΄κ²°
Browse files Browse the repository at this point in the history
  • Loading branch information
μ •λŒ€ν˜„ committed Mar 23, 2023
1 parent 3ea1d3a commit 1e7e294
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.util.UUID

interface QueryTypeSpi {

fun queryTypeListByToday(): List<Type>
fun queryTypeListByDate(startDate: LocalDate): List<Type>

fun queryTypeById(typeId: UUID): Type

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.pickdsm.pickserverspring.domain.selfstudydirector.usecase

import com.pickdsm.pickserverspring.common.annotation.ReadOnlyUseCase
import com.pickdsm.pickserverspring.domain.application.spi.CommandStatusSpi
import com.pickdsm.pickserverspring.domain.application.spi.QueryStatusSpi
import com.pickdsm.pickserverspring.domain.selfstudydirector.DirectorType
import com.pickdsm.pickserverspring.domain.selfstudydirector.SelfStudyDirector
import com.pickdsm.pickserverspring.domain.selfstudydirector.Type
import com.pickdsm.pickserverspring.domain.selfstudydirector.api.SelfStudyDirectorApi
import com.pickdsm.pickserverspring.domain.selfstudydirector.api.dto.requst.DomainChangeSelfStudyDirectorRequest
import com.pickdsm.pickserverspring.domain.selfstudydirector.api.dto.response.SelfStudyElement
Expand Down Expand Up @@ -36,23 +33,17 @@ class SelfStudyDirectorUseCase(
val selfStudyDirectorList = querySelfStudyDirectorSpi.querySelfStudyDirectorByDate(startDate)
val teacherIdList = selfStudyDirectorList.map { it.teacherId }
val userInfoList = userQuerySelfStudyDirectorSpi.queryUserInfo(teacherIdList)
val typeList = queryTypeSpi.queryTypeListByToday()
val typeList = queryTypeSpi.queryTypeListByDate(startDate)

// ν•΄λ‹Ή λ‹¬μ˜ 1일뢀터 λ§ˆμ§€λ§‰μΌκΉŒμ§€ λ°˜λ³΅λ¬Έμ„ λŒλ©΄μ„œ κ°’ 가곡
val selfStudyDirectorResponseList = (1..startDate.lengthOfMonth())
.filter { i ->
selfStudyDirectorList.find {
val type = typeList.find { type -> type.id == it.typeId } ?: throw TypeNotFoundException
type.date != LocalDate.of(startDate.year, startDate.month, i)
} == null
}
.map { i ->
val date = LocalDate.of(startDate.year, startDate.month, i)
val directorType: DirectorType = typeList.find { it.date == date }?.type ?: DirectorType.SELF_STUDY
val directorType = typeList.find { it.date == date }?.type ?: DirectorType.SELF_STUDY
val teacher = MutableList(5) { "" }

selfStudyDirectorList.filter {
val type: Type = typeList.find { type -> type.id == it.typeId } ?: throw TypeNotFoundException
val type = typeList.find { type -> type.id == it.typeId } ?: throw TypeNotFoundException
type.date == date
}.map { selfStudy ->
teacher[selfStudy.floor - 1] = userInfoList.find { it.id == selfStudy.teacherId }?.name ?: ""
Expand Down Expand Up @@ -102,8 +93,9 @@ class SelfStudyDirectorUseCase(
}

override fun changeSelfStudyDirector(request: DomainChangeSelfStudyDirectorRequest) {
val selfStudyDirector = querySelfStudyDirectorSpi.querySelfStudyDirectorByDateAndFloor(request.date, request.floor)
?: throw SelfStudyDirectorNotFoundException
val selfStudyDirector =
querySelfStudyDirectorSpi.querySelfStudyDirectorByDateAndFloor(request.date, request.floor)
?: throw SelfStudyDirectorNotFoundException

commandSelfStudyDirectorSpi.updateSelfStudyDirector(
selfStudyDirector.changeSelfStudyDirector(teacherId = request.teacherId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SelfStudyDirectorPersistenceAdapter(
override fun querySelfStudyDirectorByDate(date: LocalDate): List<SelfStudyDirector> =
jpaQueryFactory
.selectFrom(selfStudyDirectorEntity)
.innerJoin(selfStudyDirectorEntity.typeEntity, typeEntity)
.join(typeEntity)
.on(selfStudyDirectorEntity.typeEntity.id.eq(typeEntity.id))
.where(typeEntity.date.between(date, date.plusMonths(1)))
.fetch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class TypePersistenceAdapter(
private val typeRepository: TypeRepository,
) : TypeSpi {

override fun queryTypeListByToday(): List<Type> =
override fun queryTypeListByDate(startDate: LocalDate): List<Type> =
jpaQueryFactory
.selectFrom(typeEntity)
.where(typeEntity.date.eq(LocalDate.now()))
.where(typeEntity.date.between(startDate, startDate.plusMonths(1)))
.fetch()
.map(typeMapper::entityToDomain)

Expand Down

0 comments on commit 1e7e294

Please sign in to comment.