-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] - 여행 계획 상세 조회 API 구현 (#56)
* fix: TravelPlanController Swagger label 여행기 -> 여행 계획으로 변경 * fix: PlanPlaceCreateRequest 장소명과 설명 예시 바뀐 곳 수정 * feat: 여행 계획 상세 조회 API 구현 * feat: 여행 계획 상세 조회 swagger 설명 추가 * feat: TravelPlanController Swagger에 Error 응답 추가 * feat: GlobalExceptionHandler 추가 * feat: TravelPlan 응답에서 날짜, 장소 순서별로 정렬 추가 * fix: TravelPlanResponse에 TravelPlan id 추가 * test: TravelPlanController 테스트 추가 * test: TravelPlanService 테스트 추가
- Loading branch information
Showing
17 changed files
with
510 additions
and
22 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/woowacourse/touroot/global/exception/GlobalExceptionHandler.java
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,20 @@ | ||
package woowacourse.touroot.global.exception; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import woowacourse.touroot.global.exception.dto.ExceptionResponse; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(BadRequestException.class) | ||
public ResponseEntity<ExceptionResponse> handleBadRequestException(BadRequestException exception) { | ||
log.info("BAD_REQUEST_EXCEPTION :: message = {}", exception.getMessage()); | ||
ExceptionResponse data = new ExceptionResponse(exception.getMessage()); | ||
return ResponseEntity.badRequest() | ||
.body(data); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
backend/src/main/java/woowacourse/touroot/global/exception/dto/ExceptionResponse.java
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,4 @@ | ||
package woowacourse.touroot.global.exception.dto; | ||
|
||
public record ExceptionResponse(String message) { | ||
} |
53 changes: 42 additions & 11 deletions
53
backend/src/main/java/woowacourse/touroot/travelplan/controller/TravelPlanController.java
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 |
---|---|---|
@@ -1,31 +1,62 @@ | ||
package woowacourse.touroot.travelplan.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
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; | ||
import woowacourse.touroot.travelplan.dto.TravelPlanCreateRequest; | ||
import woowacourse.touroot.travelplan.dto.TravelPlanCreateResponse; | ||
import org.springframework.web.bind.annotation.*; | ||
import woowacourse.touroot.global.exception.dto.ExceptionResponse; | ||
import woowacourse.touroot.travelplan.dto.request.TravelPlanCreateRequest; | ||
import woowacourse.touroot.travelplan.dto.response.TravelPlanCreateResponse; | ||
import woowacourse.touroot.travelplan.dto.response.TravelPlanResponse; | ||
import woowacourse.touroot.travelplan.service.TravelPlanService; | ||
|
||
@Tag(name = "여행기") | ||
@Tag(name = "여행 계획") | ||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/travel-plans") | ||
public class TravelPlanController { | ||
|
||
private final TravelPlanService travelPlanService; | ||
|
||
@Operation(summary = "여행기 생성") | ||
@Operation( | ||
summary = "여행 계획 생성", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "Body에 유효하지 않은 값이 존재하거나 지난 날짜에 대한 계획을 생성할 때", | ||
content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) | ||
) | ||
} | ||
) | ||
@PostMapping | ||
public ResponseEntity<TravelPlanCreateResponse> createTravelPlan(@Valid @RequestBody TravelPlanCreateRequest request) { | ||
public ResponseEntity<TravelPlanCreateResponse> createTravelPlan( | ||
@Valid @RequestBody TravelPlanCreateRequest request | ||
) { | ||
TravelPlanCreateResponse data = travelPlanService.createTravelPlan(request); | ||
return ResponseEntity.ok() | ||
.body(data); | ||
return ResponseEntity.ok(data); | ||
} | ||
|
||
@Operation( | ||
summary = "여행 계획 상세 조회", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "400", | ||
description = "존재하지 않은 여행 계획을 조회할 때", | ||
content = @Content(schema = @Schema(implementation = ExceptionResponse.class)) | ||
) | ||
} | ||
) | ||
@GetMapping("/{id}") | ||
public ResponseEntity<TravelPlanResponse> readTravelPlan( | ||
@Parameter(description = "여행 계획 id") @PathVariable Long id | ||
) { | ||
TravelPlanResponse data = travelPlanService.readTravelPlan(id); | ||
return ResponseEntity.ok(data); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
.../travelplan/dto/PlanDayCreateRequest.java → ...lan/dto/request/PlanDayCreateRequest.java
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
2 changes: 1 addition & 1 deletion
2
...elplan/dto/PlanLocationCreateRequest.java → ...to/request/PlanLocationCreateRequest.java
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
8 changes: 5 additions & 3 deletions
8
...ravelplan/dto/PlanPlaceCreateRequest.java → ...n/dto/request/PlanPlaceCreateRequest.java
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
4 changes: 3 additions & 1 deletion
4
...avelplan/dto/TravelPlanCreateRequest.java → .../dto/request/TravelPlanCreateRequest.java
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
2 changes: 1 addition & 1 deletion
2
...velplan/dto/TravelPlanCreateResponse.java → ...to/response/TravelPlanCreateResponse.java
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
25 changes: 25 additions & 0 deletions
25
backend/src/main/java/woowacourse/touroot/travelplan/dto/response/TravelPlanDayResponse.java
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,25 @@ | ||
package woowacourse.touroot.travelplan.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import woowacourse.touroot.travelplan.domain.TravelPlanDay; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Builder | ||
public record TravelPlanDayResponse( | ||
@Schema(description = "여행 일자") LocalDate date, | ||
@Schema(description = "여행 장소별 정보") List<TravelPlanPlaceResponse> places | ||
) { | ||
|
||
public static TravelPlanDayResponse of( | ||
TravelPlanDay planDay, | ||
List<TravelPlanPlaceResponse> places | ||
) { | ||
return TravelPlanDayResponse.builder() | ||
.date(planDay.getCurrentDate()) | ||
.places(places) | ||
.build(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...src/main/java/woowacourse/touroot/travelplan/dto/response/TravelPlanLocationResponse.java
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,19 @@ | ||
package woowacourse.touroot.travelplan.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import woowacourse.touroot.place.domain.Place; | ||
|
||
@Builder | ||
public record TravelPlanLocationResponse( | ||
@Schema(description = "여행 장소 위도") String lat, | ||
@Schema(description = "여행 계획 경도") String lng | ||
) { | ||
|
||
public static TravelPlanLocationResponse from(Place place) { | ||
return TravelPlanLocationResponse.builder() | ||
.lat(place.getLatitude()) | ||
.lng(place.getLongitude()) | ||
.build(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...nd/src/main/java/woowacourse/touroot/travelplan/dto/response/TravelPlanPlaceResponse.java
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,25 @@ | ||
package woowacourse.touroot.travelplan.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import woowacourse.touroot.place.domain.Place; | ||
import woowacourse.touroot.travelplan.domain.TravelPlanPlace; | ||
|
||
@Builder | ||
public record TravelPlanPlaceResponse( | ||
@Schema(description = "여행 장소 이름") String placeName, | ||
@Schema(description = "여행 장소 위치") TravelPlanLocationResponse location, | ||
@Schema(description = "여행 장소 설명") String description | ||
) { | ||
|
||
public static TravelPlanPlaceResponse from(TravelPlanPlace planPlace) { | ||
Place place = planPlace.getPlace(); | ||
TravelPlanLocationResponse locationResponse = TravelPlanLocationResponse.from(place); | ||
|
||
return TravelPlanPlaceResponse.builder() | ||
.placeName(place.getName()) | ||
.location(locationResponse) | ||
.description(planPlace.getDescription()) | ||
.build(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/woowacourse/touroot/travelplan/dto/response/TravelPlanResponse.java
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 woowacourse.touroot.travelplan.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Builder; | ||
import woowacourse.touroot.travelplan.domain.TravelPlan; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Builder | ||
public record TravelPlanResponse( | ||
@Schema(description = "여행 계획 id") Long id, | ||
@Schema(description = "여행 계획 제목") String title, | ||
@Schema(description = "여행 시작일") LocalDate startDate, | ||
@Schema(description = "여행 계획 날짜별 정보") List<TravelPlanDayResponse> days | ||
) { | ||
|
||
public static TravelPlanResponse of(TravelPlan travelPlan, List<TravelPlanDayResponse> days) { | ||
return TravelPlanResponse.builder() | ||
.id(travelPlan.getId()) | ||
.title(travelPlan.getTitle()) | ||
.startDate(travelPlan.getStartDate()) | ||
.days(days) | ||
.build(); | ||
} | ||
} |
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
Oops, something went wrong.