Skip to content

Commit

Permalink
πŸ”€ :: (#13) ꡐ싀 이동 μžμ‹ μ˜ κ΅μ‹€λ‘œ 이동 λͺ»ν•˜λ„둝 μ—λŸ¬ 핸듀링
Browse files Browse the repository at this point in the history
πŸ”€ :: (#13) ꡐ싀 이동 μžμ‹ μ˜ κ΅μ‹€λ‘œ 이동 λͺ»ν•˜λ„둝 μ—λŸ¬ 핸듀링
  • Loading branch information
jeongho1209 authored Apr 20, 2023
2 parents db7dc34 + cca7e4c commit 3d3ad63
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ enum class ClassroomErrorCode(

CANNOT_MOVEMENT(400, "Cannot Movement"),

CANNOT_MOVEMENT_MY_CLASSROOM(401, "Cannot Movement My Classroom"),

CLASS_NOT_FOUND(404, "Class not found"),
FLOOR_NOT_FOUND(404, "Floor not found"),
CLASSROOM_MOVEMENT_STUDENT_NOT_FOUND(404, "Classroom Movement Student Not Found"), ;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.pickdsm.pickserverspring.domain.classroom.exception

import com.pickdsm.pickserverspring.common.error.PickException
import com.pickdsm.pickserverspring.domain.classroom.error.ClassroomErrorCode

object CannotMovementMyClassroom : PickException(
ClassroomErrorCode.CANNOT_MOVEMENT_MY_CLASSROOM,
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import com.pickdsm.pickserverspring.domain.application.exception.StatusNotFoundE
import com.pickdsm.pickserverspring.domain.application.spi.CommandStatusSpi
import com.pickdsm.pickserverspring.domain.application.spi.QueryStatusSpi
import com.pickdsm.pickserverspring.domain.application.spi.UserQueryApplicationSpi
import com.pickdsm.pickserverspring.domain.classroom.Classroom
import com.pickdsm.pickserverspring.domain.classroom.ClassroomMovement
import com.pickdsm.pickserverspring.domain.classroom.api.ClassroomMovementApi
import com.pickdsm.pickserverspring.domain.classroom.api.dto.request.DomainClassroomMovementRequest
import com.pickdsm.pickserverspring.domain.classroom.api.dto.response.MovementStudentElement
import com.pickdsm.pickserverspring.domain.classroom.api.dto.response.QueryClassroomMovementLocationResponse
import com.pickdsm.pickserverspring.domain.classroom.api.dto.response.QueryMovementStudentList
import com.pickdsm.pickserverspring.domain.classroom.exception.CannotMovementException
import com.pickdsm.pickserverspring.domain.classroom.exception.CannotMovementMyClassroom
import com.pickdsm.pickserverspring.domain.classroom.exception.ClassroomMovementStudentNotFoundException
import com.pickdsm.pickserverspring.domain.classroom.exception.ClassroomNotFoundException
import com.pickdsm.pickserverspring.domain.classroom.spi.CommandClassroomMovementSpi
Expand All @@ -28,6 +30,7 @@ import com.pickdsm.pickserverspring.domain.selfstudydirector.DirectorType
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.spi.UserSpi
import java.time.LocalDate
import java.util.UUID
Expand All @@ -51,21 +54,24 @@ class ClassroomMovementUseCase(
override fun saveClassroomMovement(request: DomainClassroomMovementRequest) {
val classroom = queryClassroomSpi.queryClassroomById(request.classroomId)
?: throw ClassroomNotFoundException
val studentId = userSpi.getCurrentUserId()

val student = userSpi.queryUserInfoByUserId(userSpi.getCurrentUserId())

val timeList = timeQueryTeacherSpi.queryTime(LocalDate.now())
val time = timeList.timeList.find { time -> time.period == request.period }
?: throw TimeNotFoundException

val statusTypes = queryStatusSpi.queryStatusTypesByStudentIdAndEndPeriod(
studentId = studentId,
studentId = student.id,
period = request.period,
)

if (statusTypes.contains(StatusType.PICNIC)) {
throw CannotMovementException
}
checkIsStatusPicnic(statusTypes)

checkIsMovementMyClassroom(student, classroom)

val status = Status(
studentId = studentId,
studentId = student.id,
teacherId = UUID(0, 0), // TODO: ν•΄λ‹Ή μΈ΅ μžμŠ΅κ°λ…μŒ€ 아이디 λ„£κΈ°
startPeriod = time.period,
endPeriod = 10,
Expand All @@ -80,6 +86,21 @@ class ClassroomMovementUseCase(
)
}

private fun checkIsMovementMyClassroom(
user: User,
classroom: Classroom,
) {
if (user.grade == classroom.grade && user.classNum == classroom.classNum) {
throw CannotMovementMyClassroom
}
}

private fun checkIsStatusPicnic(statusTypes: List<StatusType>) {
if (statusTypes.contains(StatusType.PICNIC)) {
throw CannotMovementException
}
}

override fun queryMovementStudentList(
grade: Int?,
classNum: Int?,
Expand Down

0 comments on commit 3d3ad63

Please sign in to comment.