Skip to content

Commit

Permalink
feat: #77 루트 기록할 때, pointOrder 대신 recordAt 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
suyeoniii committed Sep 6, 2024
1 parent b486dd6 commit 154c07e
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ 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(
userId = userId,
routeId = routeId,
latitude = latitude,
longitude = longitude,
pointOrder = pointOrder,
recordAt = recordAt,
)
}
10 changes: 10 additions & 0 deletions src/main/kotlin/com/routebox/routebox/domain/route/Route.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,14 @@ class Route(
this.description = description
this.recordFinishedAt = LocalDateTime.now()
}

fun getRoutePath(): List<Map<String, String>> {
return routePoints.map {
mapOf(
"latitude" to it.latitude,
"longitude" to it.longitude,
"recordAt" to it.recordAt.toString(),
)
}.sortedBy { it["recordAt"] }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +19,7 @@ class RoutePoint(
route: Route,
latitude: String,
longitude: String,
pointOrder: Int,
recordAt: LocalDateTime,
) : TimeTrackedBaseEntity() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down

0 comments on commit 154c07e

Please sign in to comment.