Skip to content

Commit

Permalink
add :: 조기귀가신청 중복확인
Browse files Browse the repository at this point in the history
  • Loading branch information
rudeh2926 committed Feb 7, 2024
1 parent e644fd5 commit 688764d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dsm.pick2024.domain.application.exception

import dsm.pick2024.global.error.exception.ErrorCode
import dsm.pick2024.global.error.exception.PickException

object AlreadyApplyingForEarlyReturnException : PickException(
ErrorCode.ALREADY_APPLYING_EARLY_RETURN
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ class EarlyReturnPersistenceAdapter(
override fun save(earlyReturn: EarlyReturn) {
earlyReturnRepository.save(earlyReturnMapper.toEntity(earlyReturn))
}

override fun existsByUsername(username: String) =
earlyReturnRepository.existsByUsername(username)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import dsm.pick2024.domain.application.entity.EarlyReturnJpaEntity
import org.springframework.data.jpa.repository.JpaRepository
import java.util.UUID

interface EarlyReturnRepository : JpaRepository<EarlyReturnJpaEntity, UUID>
interface EarlyReturnRepository : JpaRepository<EarlyReturnJpaEntity, UUID> {
fun existsByUsername(username: String): Boolean
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package dsm.pick2024.domain.application.port.out

interface EarlyReturnPort : SaveEarlyReturnPort
interface EarlyReturnPort :
SaveEarlyReturnPort,
ExistsEarlyReturnByUsernamePort
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dsm.pick2024.domain.application.port.out

interface ExistsEarlyReturnByUsernamePort {
fun existsByUsername(username: String): Boolean?
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package dsm.pick2024.domain.application.service

import dsm.pick2024.domain.application.domain.EarlyReturn
import dsm.pick2024.domain.application.enums.Status
import dsm.pick2024.domain.application.exception.AlreadyApplyingForEarlyReturnException
import dsm.pick2024.domain.application.port.`in`.CreateEarlyReturnUseCase
import dsm.pick2024.domain.application.port.out.ExistsEarlyReturnByUsernamePort
import dsm.pick2024.domain.application.port.out.SaveEarlyReturnPort
import dsm.pick2024.domain.application.presentation.dto.request.CreateEarlyReturnRequest
import dsm.pick2024.domain.user.port.`in`.UserFacadeUseCase
Expand All @@ -12,12 +14,18 @@ import org.springframework.transaction.annotation.Transactional
@Service
class CreateEarlyReturnService(
private val saveEarlyReturnPort: SaveEarlyReturnPort,
private val existsEarlyReturnByUsernamePort: ExistsEarlyReturnByUsernamePort,
private val userFacadeUseCase: UserFacadeUseCase
) : CreateEarlyReturnUseCase {

@Transactional
override fun createEarlyReturn(request: CreateEarlyReturnRequest) {
val user = userFacadeUseCase.currentUser()

if (existsEarlyReturnByUsernamePort.existsByUsername(user.name) == true) {
throw AlreadyApplyingForEarlyReturnException
}

saveEarlyReturnPort.save(
EarlyReturn(
username = user.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ enum class ErrorCode(
SELF_STUDY_NOT_FOUND(404, "Self Study Not Found"),
EXISTS_SELF_STUDY_TEACHER(409, "Exists Self Study Teacher"),

ALREADY_APPLYING_EARLY_RETURN(409, "Already applying For Early Return Application"),

ALREADY_APPLYING_MOVEMENT(409, "Already applying for movement"),

INVALID_TOKEN(401, "Invalid Token"),
Expand Down

0 comments on commit 688764d

Please sign in to comment.