Skip to content

Commit

Permalink
πŸ”€ :: (#241) ꡐ싀에 ν•™μƒμ‘΄μž¬μ—¬λΆ€ Response μΆ”κ°€
Browse files Browse the repository at this point in the history
πŸ”€ :: (#241) ꡐ싀에 ν•™μƒμ‘΄μž¬μ—¬λΆ€ Response μΆ”κ°€
  • Loading branch information
alsco39 authored Sep 13, 2023
1 parent eacbe85 commit 005a5bc
Show file tree
Hide file tree
Showing 23 changed files with 89 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pickdsm.pickserverspring.domain.afterschool

import com.pickdsm.pickserverspring.common.annotation.Aggregate
import java.util.*
import java.util.UUID

@Aggregate
data class AfterSchool(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ data class QueryResponsibleClassroomList(
val id: UUID,
val name: String,
val description: String,
val isUserExist: Boolean,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ interface QueryClassroomMovementSpi {
fun queryClassroomMovementByStudentIdAndToday(studentId: UUID): ClassroomMovement?

fun queryClassroomMovementClassroomIdByStatusId(statusId: UUID): UUID?

fun queryClassroomMovementListByClassroomId(classroomId: UUID): List<ClassroomMovement>
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.pickdsm.pickserverspring.domain.classroom.usecase

import com.pickdsm.pickserverspring.common.annotation.UseCase
import com.pickdsm.pickserverspring.domain.admin.api.AdminApi
import com.pickdsm.pickserverspring.domain.afterschool.exception.AfterSchoolNotFoundException
import com.pickdsm.pickserverspring.domain.afterschool.spi.QueryAfterSchoolSpi
import com.pickdsm.pickserverspring.domain.application.Status
Expand Down Expand Up @@ -51,7 +50,6 @@ class ClassroomMovementUseCase(
private val queryStatusSpi: QueryStatusSpi,
private val userQueryApplicationSpi: UserQueryApplicationSpi,
private val queryClassroomMovementSpi: QueryClassroomMovementSpi,
private val adminApi: AdminApi,
private val queryClubSpi: QueryClubSpi,
private val queryAfterSchoolSpi: QueryAfterSchoolSpi,
private val queryTypeSpi: QueryTypeSpi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import com.pickdsm.pickserverspring.domain.classroom.api.dto.response.QueryClass
import com.pickdsm.pickserverspring.domain.classroom.api.dto.response.QueryClassroomList.ClassroomElement
import com.pickdsm.pickserverspring.domain.classroom.api.dto.response.QueryResponsibleClassroomList
import com.pickdsm.pickserverspring.domain.classroom.api.dto.response.QueryResponsibleClassroomList.ResponsibleClassroomElement
import com.pickdsm.pickserverspring.domain.classroom.exception.ClassroomNotFoundException
import com.pickdsm.pickserverspring.domain.classroom.exception.FloorNotFoundException
import com.pickdsm.pickserverspring.domain.classroom.spi.QueryClassroomMovementSpi
import com.pickdsm.pickserverspring.domain.classroom.spi.QueryClassroomSpi
import com.pickdsm.pickserverspring.domain.club.spi.QueryClubSpi
import com.pickdsm.pickserverspring.domain.selfstudydirector.DirectorType
import com.pickdsm.pickserverspring.domain.selfstudydirector.exception.TypeNotFoundException
import com.pickdsm.pickserverspring.domain.selfstudydirector.spi.QuerySelfStudyDirectorSpi
import com.pickdsm.pickserverspring.domain.selfstudydirector.spi.QueryTypeSpi
import com.pickdsm.pickserverspring.domain.user.dto.UserInfo
import com.pickdsm.pickserverspring.domain.user.spi.UserSpi
import java.time.DayOfWeek
import java.time.LocalDate
Expand All @@ -27,6 +30,7 @@ class ClassroomUseCase(
private val queryClubSpi: QueryClubSpi,
private val queryAfterSchoolSpi: QueryAfterSchoolSpi,
private val queryTypeSpi: QueryTypeSpi,
private val queryClassroomMovementSpi: QueryClassroomMovementSpi,
) : ClassroomApi {

companion object {
Expand All @@ -51,23 +55,24 @@ class ClassroomUseCase(
else -> queryAfterSchoolSpi.queryAllAfterSchoolClassroom()
}

afterSchoolList.map { afterSchool ->
afterSchoolList.map {
val afterSchoolRoom = ClassroomElement(
classroomId = afterSchool.classroomId,
typeId = afterSchool.afterSchoolInfoId,
name = afterSchool.name,
description = afterSchool.description,
classroomId = it.classroomId,
typeId = it.afterSchoolInfoId,
name = it.name,
description = it.description,
)
classrooms.add(afterSchoolRoom)
}
}

ClassroomType.TUE_CLUB.name, ClassroomType.FRI_CLUB.name -> {
val clubRoomList = queryClubSpi.queryClubClassroomListByFloor(floor)

clubRoomList.map {
val clubRooms = ClassroomElement(
classroomId = it.classroomId,
typeId = it.clubId,
typeId = it.clubInfoId,
name = it.name,
description = it.description,
)
Expand All @@ -77,6 +82,7 @@ class ClassroomUseCase(

ClassroomType.ALL.name, ClassroomType.SELF_STUDY.name -> {
val allClassroomList = queryClassroomSpi.queryClassroomListByFloorAndByType(floor, type.name)

allClassroomList.map {
val allRooms = ClassroomElement(
classroomId = it.id,
Expand All @@ -96,48 +102,81 @@ class ClassroomUseCase(

override fun queryResponsibleClassroomList(): QueryResponsibleClassroomList {
val teacherId = userSpi.getCurrentUserId()
val typeId = queryTypeSpi.queryTypeIdByDate(LocalDate.now())
?: throw TypeNotFoundException
val typeId = queryTypeSpi.queryTypeIdByDate(LocalDate.now()) ?: throw TypeNotFoundException
val floor = querySelfStudyDirectorSpi.queryResponsibleFloorByTeacherIdAndTypeId(
teacherId = teacherId,
typeId = typeId,
) ?: throw FloorNotFoundException
val todayType = queryTypeSpi.queryDirectorTypeByDate(LocalDate.now())
?: DirectorType.SELF_STUDY
val todayType = queryTypeSpi.queryDirectorTypeByDate(LocalDate.now()) ?: DirectorType.SELF_STUDY
val classrooms = mutableListOf<ResponsibleClassroomElement>()
var isUserExist: Boolean

when (todayType.name) {
ClassroomType.AFTER_SCHOOL.name -> {
val afterSchoolList = queryAfterSchoolSpi.queryAfterSchoolClassroomListByFloor(floor)
afterSchoolList.map {

afterSchoolList.map { afterSchool ->
val afterSchoolUserList =
queryAfterSchoolSpi.queryAfterSchoolListByClassroomId(afterSchool.afterSchoolInfoId)
val afterSchoolMovementUserList =
queryClassroomMovementSpi.queryClassroomMovementListByClassroomId(afterSchool.classroomId)

isUserExist = !(afterSchoolUserList.isEmpty() && afterSchoolMovementUserList.isEmpty())

val afterSchoolRooms = ResponsibleClassroomElement(
id = it.classroomId,
name = it.name,
description = it.description,
id = afterSchool.classroomId,
name = afterSchool.name,
description = afterSchool.description,
isUserExist = isUserExist,
)
classrooms.add(afterSchoolRooms)
}
}

ClassroomType.TUE_CLUB.name, ClassroomType.FRI_CLUB.name -> {
val clubRoomList = queryClubSpi.queryClubClassroomListByFloor(floor)

clubRoomList.map {
val clubUserList = queryClubSpi.queryClubStudentIdListByClubInfoId(it.clubInfoId)
val clubMovementUserList =
queryClassroomMovementSpi.queryClassroomMovementListByClassroomId(it.classroomId)

isUserExist = !(clubUserList.isEmpty() && clubMovementUserList.isEmpty())

val clubRooms = ResponsibleClassroomElement(
id = it.classroomId,
name = it.name,
description = it.description,
isUserExist = isUserExist,
)
classrooms.add(clubRooms)
}
}

ClassroomType.SELF_STUDY.name -> {
val selfStudyClassroomList = queryClassroomSpi.queryClassroomListByFloorAndByType(floor, todayType.name)

selfStudyClassroomList.map {
val classroom = queryClassroomSpi.queryClassroomById(it.id) ?: throw ClassroomNotFoundException
val classroomMovementUsers =
queryClassroomMovementSpi.queryClassroomMovementListByClassroomId(classroom.id)
var classroomUserList = emptyList<UserInfo>()
val isClassroom = !(classroom.grade == null && classroom.classNum == null)

if (isClassroom) {
classroomUserList = userSpi.queryUserInfoByGradeAndClassNum(
grade = classroom.grade,
classNum = classroom.classNum,
)
}

isUserExist = !(classroomMovementUsers.isEmpty() && classroomUserList.isEmpty())

val selfStudyRooms = ResponsibleClassroomElement(
id = it.id,
name = it.name,
description = "",
isUserExist = isUserExist,
)
classrooms.add(selfStudyRooms)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.util.UUID

open class ClubRoomVO(
val classroomId: UUID,
val clubId: UUID,
val clubInfoId: UUID,
val name: String,
val description: String,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pickdsm.pickserverspring.domain.selfstudydirector.api.dto.request

import java.time.LocalDate
import java.util.*
import java.util.UUID

data class DomainDeleteSelfStudyDirectorRequest(
val teacherId: UUID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pickdsm.pickserverspring.domain.selfstudydirector.api.dto.request

import java.time.LocalDate
import java.util.*
import java.util.UUID

data class DomainRegisterSelfStudyDirectorRequest(
val teacherId: UUID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.pickdsm.pickserverspring.domain.selfstudydirector.spi

import com.pickdsm.pickserverspring.domain.selfstudydirector.SelfStudyDirector
import java.time.LocalDate
import java.util.*
import java.util.UUID

interface QuerySelfStudyDirectorSpi {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pickdsm.pickserverspring.domain.user.dto.request

import java.util.*
import java.util.UUID

data class UserInfoRequest(
val userIds: List<UUID>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pickdsm.pickserverspring.domain.admin.presentation.dto.request

import java.time.LocalDate
import java.util.*
import java.util.UUID

data class DeleteSelfStudyDirectorRequest(
val teacherId: UUID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pickdsm.pickserverspring.domain.admin.presentation.dto.request

import java.time.LocalDate
import java.util.*
import java.util.UUID

data class RegisterSelfStudyDirectorRequest(
val teacherId: UUID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.pickdsm.pickserverspring.domain.afterschool.persistence
import com.pickdsm.pickserverspring.domain.afterschool.persistence.entity.AfterSchoolInfoEntity
import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository
import java.util.*
import java.util.UUID

@Repository
interface AfterSchoolInfoRepository : CrudRepository<AfterSchoolInfoEntity, UUID>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pickdsm.pickserverspring.domain.afterschool.persistence.entity

import com.pickdsm.pickserverspring.global.entity.BaseUUIDEntity
import java.util.*
import java.util.UUID
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.FetchType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.pickdsm.pickserverspring.domain.afterschool.persistence.vo

import com.pickdsm.pickserverspring.domain.afterschool.vo.AfterSchoolRoomVO
import com.querydsl.core.annotations.QueryProjection
import java.util.*
import java.util.UUID

class QueryAfterSchoolRoomVO @QueryProjection constructor(
classroomId: UUID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.pickdsm.pickserverspring.domain.application.persistence.entity.Status
import com.pickdsm.pickserverspring.domain.classroom.persistence.entity.ClassroomMovementEntity
import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository
import java.util.*
import java.util.UUID

@Repository
interface ClassroomMovementRepository : CrudRepository<ClassroomMovementEntity, UUID> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pickdsm.pickserverspring.domain.classroom.persistence.adapter

import com.pickdsm.pickserverspring.domain.application.Status
import com.pickdsm.pickserverspring.domain.application.StatusType
import com.pickdsm.pickserverspring.domain.application.persistence.entity.QStatusEntity.statusEntity
import com.pickdsm.pickserverspring.domain.classroom.ClassroomMovement
import com.pickdsm.pickserverspring.domain.classroom.mapper.ClassroomMovementMapper
Expand Down Expand Up @@ -71,4 +72,18 @@ class ClassroomMovementPersistenceAdapter(
.from(classroomMovementEntity)
.where(classroomMovementEntity.statusEntity.id.eq(statusId))
.fetchOne()

override fun queryClassroomMovementListByClassroomId(classroomId: UUID): List<ClassroomMovement> =
jpaQueryFactory
.selectFrom(classroomMovementEntity)
.join(classroomEntity)
.on(classroomMovementEntity.classroomEntity.id.eq(classroomId))
.join(statusEntity)
.on(classroomMovementEntity.statusEntity.id.eq(statusEntity.id))
.where(
statusEntity.date.eq(LocalDate.now()),
statusEntity.type.eq(StatusType.MOVEMENT),
)
.fetch()
.map(classroomMovementMapper::entityToDomain)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.pickdsm.pickserverspring.domain.club.persistence
import com.pickdsm.pickserverspring.domain.club.persistence.entity.ClubInfoEntity
import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository
import java.util.*
import java.util.UUID

@Repository
interface ClubInfoRepository : CrudRepository<ClubInfoEntity, UUID>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pickdsm.pickserverspring.domain.club.persistence.entity

import com.pickdsm.pickserverspring.global.entity.BaseUUIDEntity
import java.util.*
import java.util.UUID
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.FetchType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.pickdsm.pickserverspring.domain.club.persistence.entity
import com.pickdsm.pickserverspring.domain.classroom.persistence.entity.ClassroomEntity
import com.pickdsm.pickserverspring.global.entity.BaseUUIDEntity
import org.hibernate.annotations.ColumnDefault
import java.util.*
import java.util.UUID
import javax.persistence.Column
import javax.persistence.Entity
import javax.persistence.FetchType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import java.util.UUID

class QueryClubRoomVO @QueryProjection constructor(
classroomId: UUID,
clubId: UUID,
clubInfoId: UUID,
name: String,
description: String,
) : ClubRoomVO(
classroomId = classroomId,
clubId = clubId,
clubInfoId = clubInfoId,
name = name,
description = description,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.pickdsm.pickserverspring.domain.user.dto.UserInfo
import com.pickdsm.pickserverspring.domain.user.spi.UserSpi
import com.pickdsm.pickserverspring.global.annotation.Adapter
import org.springframework.security.core.context.SecurityContextHolder
import java.util.*
import java.util.UUID

@Adapter
class UserPersistenceAdapter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.pickdsm.pickserverspring.global.filter
import com.fasterxml.jackson.databind.ObjectMapper
import com.pickdsm.pickserverspring.common.error.ErrorProperty
import com.pickdsm.pickserverspring.common.error.PickException
import com.pickdsm.pickserverspring.global.error.ErrorResponse
import com.pickdsm.pickserverspring.global.error.of
import com.pickdsm.pickserverspring.global.exception.InternalServerErrorException
import io.sentry.Sentry
Expand Down

0 comments on commit 005a5bc

Please sign in to comment.