From b486dd65867c7d92ce303a36c356cc2650e58684 Mon Sep 17 00:00:00 2001 From: suyeoniii Date: Fri, 30 Aug 2024 23:37:29 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20#75=20=EA=B8=B0=EB=A1=9D=EC=A4=91?= =?UTF-8?q?=EC=9D=B8=20=EB=A3=A8=ED=8A=B8=20=EC=97=AC=EB=B6=80=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20=EC=BF=BC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/route/CheckProgressRouteUseCase.kt | 5 ++--- .../route/dto/CheckProgressRouteCommand.kt | 8 -------- .../controller/route/RouteCommandController.kt | 14 ++------------ .../routebox/routebox/domain/route/RouteService.kt | 4 ++-- .../infrastructure/route/RouteRepository.kt | 3 +-- 5 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 src/main/kotlin/com/routebox/routebox/application/route/dto/CheckProgressRouteCommand.kt diff --git a/src/main/kotlin/com/routebox/routebox/application/route/CheckProgressRouteUseCase.kt b/src/main/kotlin/com/routebox/routebox/application/route/CheckProgressRouteUseCase.kt index 761fffe..3f889c9 100644 --- a/src/main/kotlin/com/routebox/routebox/application/route/CheckProgressRouteUseCase.kt +++ b/src/main/kotlin/com/routebox/routebox/application/route/CheckProgressRouteUseCase.kt @@ -1,6 +1,5 @@ package com.routebox.routebox.application.route -import com.routebox.routebox.application.route.dto.CheckProgressRouteCommand import com.routebox.routebox.domain.route.RouteService import org.springframework.stereotype.Component import org.springframework.transaction.annotation.Transactional @@ -17,8 +16,8 @@ class CheckProgressRouteUseCase( * @throws */ @Transactional(readOnly = true) - operator fun invoke(command: CheckProgressRouteCommand): Long? { - val route = routeService.getProgressRouteByUserId(command.userLocalTime, command.userId).let { + operator fun invoke(userId: Long): Long? { + val route = routeService.getProgressRouteByUserId(userId).let { it ?: return null } return route.id diff --git a/src/main/kotlin/com/routebox/routebox/application/route/dto/CheckProgressRouteCommand.kt b/src/main/kotlin/com/routebox/routebox/application/route/dto/CheckProgressRouteCommand.kt deleted file mode 100644 index 0eba321..0000000 --- a/src/main/kotlin/com/routebox/routebox/application/route/dto/CheckProgressRouteCommand.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.routebox.routebox.application.route.dto - -import java.time.LocalDateTime - -data class CheckProgressRouteCommand( - val userId: Long, - val userLocalTime: LocalDateTime, -) diff --git a/src/main/kotlin/com/routebox/routebox/controller/route/RouteCommandController.kt b/src/main/kotlin/com/routebox/routebox/controller/route/RouteCommandController.kt index ad70922..d27f5e4 100644 --- a/src/main/kotlin/com/routebox/routebox/controller/route/RouteCommandController.kt +++ b/src/main/kotlin/com/routebox/routebox/controller/route/RouteCommandController.kt @@ -11,10 +11,8 @@ import com.routebox.routebox.application.route.GetMyRouteListUseCase import com.routebox.routebox.application.route.UpdateRouteActivityUseCase import com.routebox.routebox.application.route.UpdateRoutePublicUseCase import com.routebox.routebox.application.route.UpdateRouteUseCase -import com.routebox.routebox.application.route.dto.CheckProgressRouteCommand import com.routebox.routebox.application.route.dto.DeleteRouteActivityCommand import com.routebox.routebox.application.route.dto.DeleteRouteCommand -import com.routebox.routebox.controller.route.dto.CheckProgressRouteRequest import com.routebox.routebox.controller.route.dto.CheckProgressRouteResponse import com.routebox.routebox.controller.route.dto.CreateRouteActivityRequest import com.routebox.routebox.controller.route.dto.CreateRouteActivityResponse @@ -40,7 +38,6 @@ import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.security.SecurityRequirement import io.swagger.v3.oas.annotations.tags.Tag import jakarta.validation.Valid -import org.springdoc.core.annotations.ParameterObject import org.springframework.http.MediaType import org.springframework.security.core.annotation.AuthenticationPrincipal import org.springframework.validation.annotation.Validated @@ -54,7 +51,6 @@ import org.springframework.web.bind.annotation.PutMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController -import java.time.LocalDateTime import kotlin.random.Random @Tag(name = "내루트 관련 API") @@ -225,21 +221,15 @@ class RouteCommandController( @Operation( summary = "기록 진행중인 루트 여부 조회", - description = "

기록 진행중인 루트가 존재하는 경우 routeId: Int반환, 없는 경우 routeId : null 반환

" + - "

사용자 기기 기준 시간 = userLocalTime: yyyy-MM-ddTHH:mm:ss 형식의 문자열로 전달해야 함 (optional)

", + description = "

기록 진행중인 루트가 존재하는 경우 routeId: Int반환, 없는 경우 routeId : null 반환

", security = [SecurityRequirement(name = "access-token")], ) @GetMapping("/v1/routes/progress") fun checkProgressRoute( @AuthenticationPrincipal userPrincipal: UserPrincipal, - @ParameterObject request: CheckProgressRouteRequest, ): CheckProgressRouteResponse { - val localTime: LocalDateTime = LocalDateTime.parse(request.userLocalTime) val routeId = checkProgressRouteUseCase( - CheckProgressRouteCommand( - userId = userPrincipal.userId, - userLocalTime = localTime, - ), + userPrincipal.userId, ) return CheckProgressRouteResponse(routeId) } diff --git a/src/main/kotlin/com/routebox/routebox/domain/route/RouteService.kt b/src/main/kotlin/com/routebox/routebox/domain/route/RouteService.kt index 012c5ee..16d8608 100644 --- a/src/main/kotlin/com/routebox/routebox/domain/route/RouteService.kt +++ b/src/main/kotlin/com/routebox/routebox/domain/route/RouteService.kt @@ -308,8 +308,8 @@ class RouteService( * 기록중인 루트 조회 */ @Transactional(readOnly = true) - fun getProgressRouteByUserId(now: LocalDateTime, userId: Long): Route? = - routeRepository.findByEndTimeIsAfterAndUser_Id(now, userId) + fun getProgressRouteByUserId(userId: Long): Route? = + routeRepository.findByRecordFinishedAtIsNullAndUser_Id(userId).firstOrNull() /** * 내 루트 목록조회 diff --git a/src/main/kotlin/com/routebox/routebox/infrastructure/route/RouteRepository.kt b/src/main/kotlin/com/routebox/routebox/infrastructure/route/RouteRepository.kt index 838054b..bc3e606 100644 --- a/src/main/kotlin/com/routebox/routebox/infrastructure/route/RouteRepository.kt +++ b/src/main/kotlin/com/routebox/routebox/infrastructure/route/RouteRepository.kt @@ -6,7 +6,6 @@ import org.springframework.data.domain.Pageable import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.Query import org.springframework.stereotype.Repository -import java.time.LocalDateTime @Suppress("ktlint:standard:function-naming") @Repository @@ -23,7 +22,7 @@ interface RouteRepository : JpaRepository { fun findAllFiltered(userId: Long, pageable: Pageable): Page fun countByUser_Id(userId: Long): Int - fun findByEndTimeIsAfterAndUser_Id(endTime: LocalDateTime, userId: Long): Route? + fun findByRecordFinishedAtIsNullAndUser_Id(userId: Long): List fun findByUser_IdAndRecordFinishedAtIsNotNullOrderByRecordFinishedAtDesc(userId: Long): List fun findByUser_IdAndIsPublicOrderByRecordFinishedAtDesc(userId: Long, isPublic: Boolean): List }