Skip to content

Commit

Permalink
Merge pull request #137 from mash-up-kr/feature/#134-course-patch-api
Browse files Browse the repository at this point in the history
feature: 코스 장소 수정 API
  • Loading branch information
thguss committed Aug 9, 2024
2 parents 470a065 + 10bb461 commit 6f0b6ed
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.piikii.application.domain.course

import com.piikii.application.domain.generic.LongTypeId
import com.piikii.application.domain.generic.UuidTypeId
import com.piikii.application.domain.place.Place
import com.piikii.application.domain.schedule.Schedule
Expand Down Expand Up @@ -56,6 +57,26 @@ class CourseService(
)
}

@Transactional
override fun updateCoursePlace(
roomUid: UuidTypeId,
placeId: LongTypeId,
) {
val place = placeQueryPort.findByPlaceId(placeId)

if (place.isInvalidRoomUid(roomUid)) {
throw PiikiiException(
exceptionCode = ExceptionCode.ILLEGAL_ARGUMENT_EXCEPTION,
detailMessage = "Room UUID: $roomUid, Room UUID in Place: ${place.roomUid}",
)
}

placeQueryPort.findConfirmedByScheduleId(place.scheduleId)?.let { confirmedPlace ->
placeCommandPort.update(confirmedPlace.id, confirmedPlace.copy(confirmed = false))
}
placeCommandPort.update(place.id, place.copy(confirmed = true))
}

private fun getPlaceBySchedule(
schedules: List<Schedule>,
places: List<Place>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ data class Place(
val longitude: Double?,
val latitude: Double?,
) {
fun getCoordinate(): Coordinate? {
fun getCoordinate(): Coordinate {
return Coordinate(this.longitude, this.latitude)
}

fun isInvalidRoomUid(roomUid: UuidTypeId): Boolean {
return this.roomUid != roomUid
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.piikii.application.port.input

import com.piikii.application.domain.generic.LongTypeId
import com.piikii.application.domain.generic.UuidTypeId
import com.piikii.application.port.input.dto.response.CourseResponse

interface CourseUseCase {
fun isCourseExist(roomUid: UuidTypeId): Boolean

fun retrieveCourse(roomUid: UuidTypeId): CourseResponse

fun updateCoursePlace(
roomUid: UuidTypeId,
placeId: LongTypeId,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import com.piikii.application.domain.generic.UuidTypeId
import com.piikii.application.domain.place.Place

interface PlaceQueryPort {
fun findByPlaceId(placeId: LongTypeId): Place?
fun findByPlaceId(placeId: LongTypeId): Place

fun findAllByPlaceIds(placeIds: List<LongTypeId>): List<Place>

fun findAllByRoomUid(roomUid: UuidTypeId): List<Place>

fun findConfirmedByScheduleId(scheduleId: LongTypeId): Place?
}

interface PlaceCommandPort {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.piikii.input.http.controller

import com.piikii.application.domain.generic.LongTypeId
import com.piikii.application.domain.generic.UuidTypeId
import com.piikii.application.port.input.CourseUseCase
import com.piikii.application.port.input.dto.response.CourseResponse
Expand All @@ -10,6 +11,7 @@ import jakarta.validation.constraints.NotNull
import org.springframework.http.HttpStatus
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PatchMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseStatus
Expand Down Expand Up @@ -41,4 +43,14 @@ class CourseApi(
data = courseUseCase.retrieveCourse(UuidTypeId(roomUid)),
)
}

@ResponseStatus(HttpStatus.OK)
@PatchMapping("/place/{placeId}")
override fun updateCoursePlace(
@NotNull @PathVariable roomUid: UUID,
@NotNull @PathVariable placeId: Long,
): ResponseForm<Unit> {
courseUseCase.updateCoursePlace(UuidTypeId(roomUid), LongTypeId(placeId))
return ResponseForm.EMPTY_RESPONSE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,37 @@ interface CourseApiDocs {
fun retrieveCourse(
@Parameter(
name = "roomUid",
description = "코스 생성 여부를 조회할 방 uuid",
description = "코스를 조회할 방 uuid",
required = true,
`in` = ParameterIn.PATH,
)
@NotNull roomUid: UUID,
): ResponseForm<CourseResponse>

@Operation(summary = "코스 장소 수정 API", description = "코스 대상 장소를 수정합니다.")
@ApiResponses(
value = [
ApiResponse(
responseCode = "200",
description = "OK success",
content = [Content(schema = Schema(implementation = ResponseForm::class))],
),
],
)
fun updateCoursePlace(
@Parameter(
name = "roomUid",
description = "코스를 수정할 방 uuid",
required = true,
`in` = ParameterIn.PATH,
)
@NotNull roomUid: UUID,
@Parameter(
name = "placeId",
description = "코스 장소로 선정할 장소 id",
required = true,
`in` = ParameterIn.PATH,
)
@NotNull placeId: Long,
): ResponseForm<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,13 @@ class PlaceAdapter(
override fun findAllByRoomUid(roomUid: UuidTypeId): List<Place> {
return placeRepository.findAllByRoomUid(roomUid).map { it.toDomain() }
}

override fun findConfirmedByScheduleId(scheduleId: LongTypeId): Place? {
val places = placeRepository.findByScheduleIdAndConfirmed(scheduleId, true)
return places.singleOrNull()?.toDomain()
?: throw PiikiiException(
exceptionCode = ExceptionCode.ACCESS_DENIED,
detailMessage = "중복된 장소 코스가 있습니다. 데이터를 확인하세요. Schedule ID : $scheduleId",
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ import org.springframework.data.jpa.repository.JpaRepository

interface PlaceRepository : JpaRepository<PlaceEntity, LongTypeId> {
fun findAllByRoomUid(roomUid: UuidTypeId): List<PlaceEntity>

fun findByScheduleIdAndConfirmed(
scheduleId: LongTypeId,
confirmed: Boolean,
): List<PlaceEntity>
}

0 comments on commit 6f0b6ed

Please sign in to comment.