-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#47 루트 생성, 루트 경로 기록 API
- Loading branch information
Showing
20 changed files
with
376 additions
and
19 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/com/routebox/routebox/application/route/CreateRoutePointUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.routebox.routebox.application.route | ||
|
||
import com.routebox.routebox.application.route.dto.CreateRoutePointCommand | ||
import com.routebox.routebox.application.route.dto.CreateRoutePointResult | ||
import com.routebox.routebox.domain.route.RouteService | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class CreateRoutePointUseCase( | ||
private val routeService: RouteService, | ||
) { | ||
/** | ||
* 루트 위치 기록 | ||
* | ||
* @param command user id, route id, latitude, longitude, point order | ||
* @return 루트 point id | ||
* @throws | ||
*/ | ||
operator fun invoke(command: CreateRoutePointCommand): CreateRoutePointResult { | ||
// TODO: 루트 소유자와 요청자가 같은지 확인 | ||
val routePoint = routeService.createRoutePoint( | ||
routeId = command.routeId, | ||
latitude = command.latitude, | ||
longitude = command.longitude, | ||
pointOrder = command.pointOrder, | ||
) | ||
return CreateRoutePointResult.from(routePoint) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/routebox/routebox/application/route/CreateRouteUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.routebox.routebox.application.route | ||
|
||
import com.routebox.routebox.application.route.dto.CreateRouteCommand | ||
import com.routebox.routebox.application.route.dto.CreateRouteResult | ||
import com.routebox.routebox.domain.route.RouteService | ||
import com.routebox.routebox.domain.user.UserService | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class CreateRouteUseCase( | ||
private val routeService: RouteService, | ||
private val userService: UserService, | ||
) { | ||
/** | ||
* 루트 등록 | ||
* | ||
* @param command user id, startTime, endTime | ||
* @return 루트 id | ||
* @throws | ||
*/ | ||
operator fun invoke(command: CreateRouteCommand): CreateRouteResult { | ||
val user = userService.getUserById(command.userId) | ||
val route = routeService.createRoute(user = user, startTime = command.startTime, endTime = command.endTime) | ||
return CreateRouteResult.from(route) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/routebox/routebox/application/route/dto/CreateRouteCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.routebox.routebox.application.route.dto | ||
|
||
import java.time.LocalDateTime | ||
|
||
data class CreateRouteCommand( | ||
val userId: Long, | ||
val startTime: LocalDateTime, | ||
val endTime: LocalDateTime, | ||
) |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/routebox/routebox/application/route/dto/CreateRoutePointCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.routebox.routebox.application.route.dto | ||
|
||
data class CreateRoutePointCommand( | ||
val userId: Long, | ||
val routeId: Long, | ||
val latitude: String, | ||
val longitude: String, | ||
val pointOrder: Int, | ||
) |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/com/routebox/routebox/application/route/dto/CreateRoutePointResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.routebox.routebox.application.route.dto | ||
|
||
import com.routebox.routebox.domain.route.RoutePoint | ||
|
||
data class CreateRoutePointResult( | ||
val pointId: Long, | ||
) { | ||
companion object { | ||
fun from(point: RoutePoint): CreateRoutePointResult = CreateRoutePointResult( | ||
pointId = point.id, | ||
) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/com/routebox/routebox/application/route/dto/CreateRouteResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.routebox.routebox.application.route.dto | ||
|
||
import com.routebox.routebox.domain.route.Route | ||
|
||
data class CreateRouteResult( | ||
val routeId: Long, | ||
) { | ||
companion object { | ||
fun from(route: Route): CreateRouteResult = CreateRouteResult( | ||
routeId = route.id, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/kotlin/com/routebox/routebox/controller/route/RouteCommandController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.routebox.routebox.controller.route | ||
|
||
import com.routebox.routebox.application.route.CreateRoutePointUseCase | ||
import com.routebox.routebox.application.route.CreateRouteUseCase | ||
import com.routebox.routebox.controller.route.dto.CreateRoutePointRequest | ||
import com.routebox.routebox.controller.route.dto.CreateRoutePointResponse | ||
import com.routebox.routebox.controller.route.dto.CreateRouteRequest | ||
import com.routebox.routebox.controller.route.dto.CreateRouteResponse | ||
import com.routebox.routebox.security.UserPrincipal | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import jakarta.validation.Valid | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal | ||
import org.springframework.validation.annotation.Validated | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@Tag(name = "내루트 관련 API") | ||
@RestController | ||
@Validated | ||
@RequestMapping("/api") | ||
class RouteCommandController( | ||
private val createRouteUseCase: CreateRouteUseCase, | ||
private val createRoutePointUseCase: CreateRoutePointUseCase, | ||
) { | ||
@Operation( | ||
summary = "루트 생성 (루트 기록 시작)", | ||
description = "루트 기록 시작일시, 종료일시 등록", | ||
security = [SecurityRequirement(name = "access-token")], | ||
) | ||
@ApiResponses( | ||
ApiResponse(responseCode = "200"), | ||
) | ||
@PostMapping("/v1/routes/start") | ||
fun createRoute( | ||
@AuthenticationPrincipal userPrincipal: UserPrincipal, | ||
@RequestBody @Valid request: CreateRouteRequest, | ||
): CreateRouteResponse { | ||
val routeResponse = createRouteUseCase(request.toCommand(userId = userPrincipal.userId)) | ||
return CreateRouteResponse.from(routeResponse.routeId) | ||
} | ||
|
||
@Operation( | ||
summary = "루트 경로(점) 기록", | ||
description = "1분마다 현재 위치 보내서 루트 경로의 점 찍는데 사용", | ||
security = [SecurityRequirement(name = "access-token")], | ||
) | ||
@ApiResponses( | ||
ApiResponse(responseCode = "200"), | ||
) | ||
@PostMapping("/v1/routes/{routeId}/point") | ||
fun createRoutePoint( | ||
@AuthenticationPrincipal userPrincipal: UserPrincipal, | ||
@PathVariable routeId: Long, | ||
@RequestBody @Valid request: CreateRoutePointRequest, | ||
): CreateRoutePointResponse { | ||
val routeResponse = createRoutePointUseCase(request.toCommand(userId = userPrincipal.userId, routeId = routeId)) | ||
return CreateRoutePointResponse.from(routeResponse.pointId) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/com/routebox/routebox/controller/route/dto/CreateRoutePointRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.routebox.routebox.controller.route.dto | ||
|
||
import com.routebox.routebox.application.route.dto.CreateRoutePointCommand | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
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, | ||
) { | ||
fun toCommand(userId: Long, routeId: Long): CreateRoutePointCommand = | ||
CreateRoutePointCommand( | ||
userId = userId, | ||
routeId = routeId, | ||
latitude = latitude, | ||
longitude = longitude, | ||
pointOrder = pointOrder, | ||
) | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/routebox/routebox/controller/route/dto/CreateRoutePointResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.routebox.routebox.controller.route.dto | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
data class CreateRoutePointResponse( | ||
@Schema(description = "위치 점 id", example = "1") | ||
val pointId: Long, | ||
) { | ||
companion object { | ||
fun from(pointId: Long): CreateRoutePointResponse = CreateRoutePointResponse( | ||
pointId = pointId, | ||
) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/com/routebox/routebox/controller/route/dto/CreateRouteRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.routebox.routebox.controller.route.dto | ||
|
||
import com.routebox.routebox.application.route.dto.CreateRouteCommand | ||
import com.routebox.routebox.util.DateTimeUtil | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
import org.springframework.format.annotation.DateTimeFormat | ||
|
||
data class CreateRouteRequest( | ||
@Schema(description = "루트 기록 시작일시", example = "2024-08-01T00:00:00") | ||
@field:DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") | ||
val startTime: String, | ||
@Schema(description = "루트 기록 종료일시", example = "2024-08-01T00:00:00") | ||
@field:DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") | ||
val endTime: String, | ||
) { | ||
fun toCommand(userId: Long): CreateRouteCommand = | ||
CreateRouteCommand( | ||
userId = userId, | ||
startTime = DateTimeUtil.parseToLocalDateTime(startTime), | ||
endTime = DateTimeUtil.parseToLocalDateTime(endTime), | ||
) | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/routebox/routebox/controller/route/dto/CreateRouteResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.routebox.routebox.controller.route.dto | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
data class CreateRouteResponse( | ||
@Schema(description = "루트 id", example = "1") | ||
val routeId: Long, | ||
) { | ||
companion object { | ||
fun from(routeId: Long): CreateRouteResponse = CreateRouteResponse( | ||
routeId = routeId, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/kotlin/com/routebox/routebox/domain/route/RoutePoint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.routebox.routebox.domain.route | ||
|
||
import com.routebox.routebox.domain.common.TimeTrackedBaseEntity | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.FetchType | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.JoinColumn | ||
import jakarta.persistence.ManyToOne | ||
import jakarta.persistence.Table | ||
|
||
@Table(name = "route_points") | ||
@Entity | ||
class RoutePoint( | ||
id: Long = 0, | ||
route: Route, | ||
latitude: String, | ||
longitude: String, | ||
pointOrder: Int, | ||
) : TimeTrackedBaseEntity() { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "point_id") | ||
val id: Long = id | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "route_id", nullable = false) | ||
val route: Route = route | ||
|
||
@Column(name = "latitude", nullable = false) | ||
var latitude: String = latitude | ||
|
||
@Column(name = "longitude", nullable = false) | ||
var longitude: String = longitude | ||
|
||
@Column(name = "point_order", nullable = false) | ||
var pointOrder: Int = pointOrder | ||
} |
Oops, something went wrong.