Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #75 기록중인 루트 여부 조회 API 오류 수정 및 쿼리 변경 #76

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -225,21 +221,15 @@ class RouteCommandController(

@Operation(
summary = "기록 진행중인 루트 여부 조회",
description = "<p>기록 진행중인 루트가 존재하는 경우 <code>routeId: Int</code>반환, 없는 경우 <code>routeId : null</code> 반환</p>" +
"<p>사용자 기기 기준 시간 = <code>userLocalTime: yyyy-MM-ddTHH:mm:ss</code> 형식의 문자열로 전달해야 함 (optional)</p>",
description = "<p>기록 진행중인 루트가 존재하는 경우 <code>routeId: Int</code>반환, 없는 경우 <code>routeId : null</code> 반환</p>",
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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

/**
* 내 루트 목록조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +22,7 @@ interface RouteRepository : JpaRepository<Route, Long> {
fun findAllFiltered(userId: Long, pageable: Pageable): Page<Route>

fun countByUser_Id(userId: Long): Int
fun findByEndTimeIsAfterAndUser_Id(endTime: LocalDateTime, userId: Long): Route?
fun findByRecordFinishedAtIsNullAndUser_Id(userId: Long): List<Route>
fun findByUser_IdAndRecordFinishedAtIsNotNullOrderByRecordFinishedAtDesc(userId: Long): List<Route>
fun findByUser_IdAndIsPublicOrderByRecordFinishedAtDesc(userId: Long, isPublic: Boolean): List<Route>
}
Loading