From 154c07e75d9194da21c69a746b51ee16a2df3d9c Mon Sep 17 00:00:00 2001 From: suyeoniii Date: Fri, 6 Sep 2024 09:04:51 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20#77=20=EB=A3=A8=ED=8A=B8=20=EA=B8=B0?= =?UTF-8?q?=EB=A1=9D=ED=95=A0=20=EB=95=8C,=20pointOrder=20=EB=8C=80?= =?UTF-8?q?=EC=8B=A0=20recordAt=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/route/CreateRoutePointUseCase.kt | 2 +- .../application/route/dto/CreateRoutePointCommand.kt | 4 +++- .../route/dto/GetRouteDetailWithActivitiesResult.kt | 2 +- .../controller/route/dto/CreateRoutePointRequest.kt | 7 ++++--- .../kotlin/com/routebox/routebox/domain/route/Route.kt | 10 ++++++++++ .../com/routebox/routebox/domain/route/RoutePoint.kt | 7 ++++--- .../com/routebox/routebox/domain/route/RouteService.kt | 4 ++-- src/main/resources/schema.sql | 2 +- 8 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/routebox/routebox/application/route/CreateRoutePointUseCase.kt b/src/main/kotlin/com/routebox/routebox/application/route/CreateRoutePointUseCase.kt index 9227dd3..206a6d8 100644 --- a/src/main/kotlin/com/routebox/routebox/application/route/CreateRoutePointUseCase.kt +++ b/src/main/kotlin/com/routebox/routebox/application/route/CreateRoutePointUseCase.kt @@ -24,7 +24,7 @@ class CreateRoutePointUseCase( routeId = command.routeId, latitude = command.latitude, longitude = command.longitude, - pointOrder = command.pointOrder, + recordAt = command.recordAt, ) return CreateRoutePointResult.from(routePoint) } diff --git a/src/main/kotlin/com/routebox/routebox/application/route/dto/CreateRoutePointCommand.kt b/src/main/kotlin/com/routebox/routebox/application/route/dto/CreateRoutePointCommand.kt index 7152334..9c822dd 100644 --- a/src/main/kotlin/com/routebox/routebox/application/route/dto/CreateRoutePointCommand.kt +++ b/src/main/kotlin/com/routebox/routebox/application/route/dto/CreateRoutePointCommand.kt @@ -1,9 +1,11 @@ package com.routebox.routebox.application.route.dto +import java.time.LocalDateTime + data class CreateRoutePointCommand( val userId: Long, val routeId: Long, val latitude: String, val longitude: String, - val pointOrder: Int, + val recordAt: LocalDateTime, ) diff --git a/src/main/kotlin/com/routebox/routebox/application/route/dto/GetRouteDetailWithActivitiesResult.kt b/src/main/kotlin/com/routebox/routebox/application/route/dto/GetRouteDetailWithActivitiesResult.kt index c8036b8..b4adf15 100644 --- a/src/main/kotlin/com/routebox/routebox/application/route/dto/GetRouteDetailWithActivitiesResult.kt +++ b/src/main/kotlin/com/routebox/routebox/application/route/dto/GetRouteDetailWithActivitiesResult.kt @@ -40,7 +40,7 @@ data class GetRouteDetailWithActivitiesResult( transportation = route.transportation, isPublic = route.isPublic, recordFinishedAt = route.recordFinishedAt.toString(), - routePath = route.routePoints.map { mapOf("latitude" to it.latitude, "longitude" to it.longitude) }, + routePath = route.getRoutePath(), routeActivities = route.routeActivities.map { ActivityResult.from(it) }, ) } diff --git a/src/main/kotlin/com/routebox/routebox/controller/route/dto/CreateRoutePointRequest.kt b/src/main/kotlin/com/routebox/routebox/controller/route/dto/CreateRoutePointRequest.kt index 9720106..4574ac0 100644 --- a/src/main/kotlin/com/routebox/routebox/controller/route/dto/CreateRoutePointRequest.kt +++ b/src/main/kotlin/com/routebox/routebox/controller/route/dto/CreateRoutePointRequest.kt @@ -2,14 +2,15 @@ package com.routebox.routebox.controller.route.dto import com.routebox.routebox.application.route.dto.CreateRoutePointCommand import io.swagger.v3.oas.annotations.media.Schema +import java.time.LocalDateTime data class CreateRoutePointRequest( @Schema(description = "위도", example = "37.123456") val latitude: String, @Schema(description = "경도", example = "127.123456") val longitude: String, - @Schema(description = "경로 순서, 1부터 시작, 위치 기록할 때마다 +1 해서 전송", example = "1") - val pointOrder: Int, + @Schema(description = "API 호출 시간", example = "2021-08-01T00:00:00") + val recordAt: LocalDateTime, ) { fun toCommand(userId: Long, routeId: Long): CreateRoutePointCommand = CreateRoutePointCommand( @@ -17,6 +18,6 @@ data class CreateRoutePointRequest( routeId = routeId, latitude = latitude, longitude = longitude, - pointOrder = pointOrder, + recordAt = recordAt, ) } diff --git a/src/main/kotlin/com/routebox/routebox/domain/route/Route.kt b/src/main/kotlin/com/routebox/routebox/domain/route/Route.kt index 0927027..72de77f 100644 --- a/src/main/kotlin/com/routebox/routebox/domain/route/Route.kt +++ b/src/main/kotlin/com/routebox/routebox/domain/route/Route.kt @@ -127,4 +127,14 @@ class Route( this.description = description this.recordFinishedAt = LocalDateTime.now() } + + fun getRoutePath(): List> { + return routePoints.map { + mapOf( + "latitude" to it.latitude, + "longitude" to it.longitude, + "recordAt" to it.recordAt.toString(), + ) + }.sortedBy { it["recordAt"] } + } } diff --git a/src/main/kotlin/com/routebox/routebox/domain/route/RoutePoint.kt b/src/main/kotlin/com/routebox/routebox/domain/route/RoutePoint.kt index 0d7c853..76bb393 100644 --- a/src/main/kotlin/com/routebox/routebox/domain/route/RoutePoint.kt +++ b/src/main/kotlin/com/routebox/routebox/domain/route/RoutePoint.kt @@ -10,6 +10,7 @@ import jakarta.persistence.Id import jakarta.persistence.JoinColumn import jakarta.persistence.ManyToOne import jakarta.persistence.Table +import java.time.LocalDateTime @Table(name = "route_points") @Entity @@ -18,7 +19,7 @@ class RoutePoint( route: Route, latitude: String, longitude: String, - pointOrder: Int, + recordAt: LocalDateTime, ) : TimeTrackedBaseEntity() { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -35,6 +36,6 @@ class RoutePoint( @Column(name = "longitude", nullable = false) var longitude: String = longitude - @Column(name = "point_order", nullable = false) - var pointOrder: Int = pointOrder + @Column(name = "record_at", nullable = false) + var recordAt: LocalDateTime = recordAt } 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 16d8608..4f9c1ca 100644 --- a/src/main/kotlin/com/routebox/routebox/domain/route/RouteService.kt +++ b/src/main/kotlin/com/routebox/routebox/domain/route/RouteService.kt @@ -88,13 +88,13 @@ class RouteService( * 루트 점찍기 */ @Transactional - fun createRoutePoint(routeId: Long, latitude: String, longitude: String, pointOrder: Int): RoutePoint { + fun createRoutePoint(routeId: Long, latitude: String, longitude: String, recordAt: LocalDateTime): RoutePoint { val route = findRouteById(routeId) ?: throw IllegalArgumentException("Route not found") val routePoint = RoutePoint( route = route, latitude = latitude, longitude = longitude, - pointOrder = pointOrder, + recordAt = recordAt, ) return routePointRepository.save(routePoint) } diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql index 167ed20..44456e8 100644 --- a/src/main/resources/schema.sql +++ b/src/main/resources/schema.sql @@ -180,7 +180,7 @@ CREATE TABLE route_points route_id BIGINT NOT NULL, latitude VARCHAR(255) NOT NULL, longitude VARCHAR(255) NOT NULL, - point_order INT NOT NULL, + record_at DATETIME NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL );