Skip to content

Commit

Permalink
๐Ÿ”€ :: (#10) ์™ธ์ถœ ์‹ ์ฒญ ์ค‘๋ณต ๋ฐฉ์ง€ && ์ฃผ๋ง์— ์™ธ์ถœ ์‹ ์ฒญ ๋ชปํ•˜๋„๋ก ์ˆ˜์ •
Browse files Browse the repository at this point in the history
๐Ÿ”€ :: (#10) ์™ธ์ถœ ์‹ ์ฒญ ์ค‘๋ณต ๋ฐฉ์ง€ && ์ฃผ๋ง์— ์™ธ์ถœ ์‹ ์ฒญ ๋ชปํ•˜๋„๋ก ์ˆ˜์ •
  • Loading branch information
jeongho1209 authored Apr 24, 2023
2 parents fa01563 + c4ce32a commit 964c92f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ enum class ApplicationErrorCode(
private val message: String,
) : ErrorProperty {

APPLICATION_NOT_FOUND(404, "Application Not Found"), ;
CANNOT_APPLICATION_WEEKEND(401, "Cannot Application Weekend"),

APPLICATION_NOT_FOUND(404, "Application Not Found"),

ALREADY_APPLICATION_PICNIC_OR_ALREADY_PICNIC(409, "Already Application Picnic Or Already Picnic"), ;

override fun status() = status
override fun message() = message
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.pickdsm.pickserverspring.domain.application.exception

import com.pickdsm.pickserverspring.common.error.PickException
import com.pickdsm.pickserverspring.domain.application.error.ApplicationErrorCode

object AlreadyApplicationPicnicOrAlreadyPicnicException : PickException(
ApplicationErrorCode.ALREADY_APPLICATION_PICNIC_OR_ALREADY_PICNIC,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.pickdsm.pickserverspring.domain.application.exception

import com.pickdsm.pickserverspring.common.error.PickException
import com.pickdsm.pickserverspring.domain.application.error.ApplicationErrorCode

object CannotApplicationWeekendException : PickException(
ApplicationErrorCode.CANNOT_APPLICATION_WEEKEND,
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ interface QueryStatusSpi {
fun queryMovementStatusSizeByFloorAndToday(floor: Int): Int

fun queryPicnicStatusSizeByToday(): Int

fun existAwaitOrPicnicStatusByStudentId(studentId: UUID): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import com.pickdsm.pickserverspring.domain.application.api.dto.response.QueryPic
import com.pickdsm.pickserverspring.domain.application.api.dto.response.QueryPicnicStudentList
import com.pickdsm.pickserverspring.domain.application.api.dto.response.QueryStudentStatusElement
import com.pickdsm.pickserverspring.domain.application.api.dto.response.QueryStudentStatusList
import com.pickdsm.pickserverspring.domain.application.exception.AlreadyApplicationPicnicOrAlreadyPicnicException
import com.pickdsm.pickserverspring.domain.application.exception.ApplicationNotFoundException
import com.pickdsm.pickserverspring.domain.application.exception.CannotApplicationWeekendException
import com.pickdsm.pickserverspring.domain.application.exception.StatusNotFoundException
import com.pickdsm.pickserverspring.domain.application.spi.CommandApplicationSpi
import com.pickdsm.pickserverspring.domain.application.spi.QueryApplicationSpi
Expand All @@ -34,6 +36,7 @@ import com.pickdsm.pickserverspring.domain.teacher.spi.TimeQueryTeacherSpi
import com.pickdsm.pickserverspring.domain.time.exception.TimeNotFoundException
import com.pickdsm.pickserverspring.domain.user.exception.UserNotFoundException
import com.pickdsm.pickserverspring.domain.user.spi.UserSpi
import java.time.DayOfWeek
import java.time.LocalDate
import java.util.UUID

Expand All @@ -55,6 +58,9 @@ class ApplicationUseCase(

override fun saveApplicationToGoOut(request: DomainApplicationGoOutRequest) {
val studentId = userSpi.getCurrentUserId()
checkIsExistAwaitOrPicnicStatus(studentId)
checkIsWeekends()

val status = Status(
studentId = studentId,
teacherId = UUID(0, 0), // TODO: ์„ ์ƒ๋‹˜ ์•„์ด๋”” ๋ญ๋กœ ๋„ฃ์„์ง€ ๋‚˜์ค‘์— ์ •ํ•˜๊ธฐ
Expand All @@ -71,6 +77,18 @@ class ApplicationUseCase(
)
}

private fun checkIsExistAwaitOrPicnicStatus(studentId: UUID) {
if (queryStatusSpi.existAwaitOrPicnicStatusByStudentId(studentId)) {
throw AlreadyApplicationPicnicOrAlreadyPicnicException
}
}

private fun checkIsWeekends() {
if (LocalDate.now().dayOfWeek > DayOfWeek.FRIDAY) {
throw CannotApplicationWeekendException
}
}

override fun queryPicnicApplicationListByGradeAndClassNum(
grade: String?,
classNum: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.pickdsm.pickserverspring.domain.application.spi.StatusSpi
import com.pickdsm.pickserverspring.domain.classroom.persistence.entity.QClassroomEntity.classroomEntity
import com.pickdsm.pickserverspring.domain.classroom.persistence.entity.QClassroomMovementEntity.classroomMovementEntity
import com.pickdsm.pickserverspring.global.annotation.Adapter
import com.querydsl.core.types.dsl.BooleanExpression
import com.querydsl.jpa.impl.JPAQueryFactory
import java.time.LocalDate
import java.util.UUID
Expand Down Expand Up @@ -188,4 +189,17 @@ class StatusPersistenceAdapter(
statusEntity.type.eq(StatusType.PICNIC),
)
.fetch().size

override fun existAwaitOrPicnicStatusByStudentId(studentId: UUID): Boolean =
jpaQueryFactory
.select(statusEntity.id)
.from(statusEntity)
.where(
checkIsExistAwaitOrPicnic(),
statusEntity.studentId.eq(studentId),
)
.fetchFirst() != null

private fun checkIsExistAwaitOrPicnic(): BooleanExpression =
statusEntity.type.eq(StatusType.AWAIT).or(statusEntity.type.eq(StatusType.PICNIC))
}

0 comments on commit 964c92f

Please sign in to comment.