Skip to content

Commit

Permalink
feat: 여정 기록 관련기능구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ypd06021 committed Oct 27, 2023
1 parent e25106c commit a51717c
Show file tree
Hide file tree
Showing 27 changed files with 706 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.fc.toy_project2.domain.itinerary.controller;

import com.fc.toy_project2.domain.itinerary.dto.request.createDTO.ItineraryAccommodationCreateDTO;
import com.fc.toy_project2.domain.itinerary.dto.request.createDTO.ItineraryTransportationCreateDTO;
import com.fc.toy_project2.domain.itinerary.dto.request.createDTO.ItineraryVisitCreateDTO;
import com.fc.toy_project2.domain.itinerary.dto.request.patchDTO.ItineraryAccommodationPatchDTO;
import com.fc.toy_project2.domain.itinerary.dto.request.patchDTO.ItineraryVisitPatchDTO;
import com.fc.toy_project2.domain.itinerary.dto.request.patchDTO.ItineraryTransportationPatchDTO;
import com.fc.toy_project2.domain.itinerary.dto.response.ItineraryAccommodationResponseDTO;
import com.fc.toy_project2.domain.itinerary.dto.response.ItineraryTransportationResponseDTO;
import com.fc.toy_project2.domain.itinerary.dto.response.ItineraryVisitResponseDTO;
import com.fc.toy_project2.domain.itinerary.service.ItineraryPostUpdateService;
import com.fc.toy_project2.global.DTO.ResponseDTO;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/itinerary")
public class ItineraryPatchController {

private final ItineraryPostUpdateService itinerarypostUpdateService;

@PatchMapping("/accommodation/{tripId}/{itineraryId}")
public ResponseEntity<ResponseDTO<ItineraryAccommodationResponseDTO>> updateAccommodation(@PathVariable Long tripId, @PathVariable Long itineraryId,
@Valid @RequestBody ItineraryAccommodationPatchDTO ItineraryAccommodationPatchDTO) {
return ResponseEntity.status(HttpStatus.CREATED).body(ResponseDTO.res(HttpStatus.OK,
itinerarypostUpdateService.patchAccommodation(ItineraryAccommodationPatchDTO, tripId, itineraryId),
"숙박 여정을 성공적으로 수정했습니다."));
}

@PatchMapping("/transportation/{tripId}/{itineraryId}")
public ResponseEntity<ResponseDTO<ItineraryTransportationResponseDTO>> updateTransportation(@PathVariable Long tripId, @PathVariable Long itineraryId,
@Valid @RequestBody ItineraryTransportationPatchDTO itineraryTransportationPatchDTO) {
return ResponseEntity.status(HttpStatus.CREATED).body(ResponseDTO.res(HttpStatus.OK,
itinerarypostUpdateService.patchTransportation(itineraryTransportationPatchDTO, tripId, itineraryId),
"이동 여정을 성공적으로 수정했습니다."));
}

@PatchMapping("/visit/{tripId}/{itineraryId}")
public ResponseEntity<ResponseDTO<ItineraryVisitResponseDTO>> updateVisit(@PathVariable Long tripId, @PathVariable Long itineraryId,
@Valid @RequestBody ItineraryVisitPatchDTO itineraryVisitPatchDTO) {
return ResponseEntity.status(HttpStatus.CREATED).body(ResponseDTO.res(HttpStatus.OK,
itinerarypostUpdateService.patchVisit(itineraryVisitPatchDTO, tripId, itineraryId),
"체류 여정을 성공적으로 수정했습니다."));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.fc.toy_project2.domain.itinerary.controller;

import com.fc.toy_project2.domain.itinerary.dto.request.createDTO.ItineraryAccommodationCreateDTO;
import com.fc.toy_project2.domain.itinerary.dto.request.createDTO.ItineraryTransportationCreateDTO;
import com.fc.toy_project2.domain.itinerary.dto.request.createDTO.ItineraryVisitCreateDTO;
import com.fc.toy_project2.domain.itinerary.dto.response.ItineraryAccommodationResponseDTO;
import com.fc.toy_project2.domain.itinerary.dto.response.ItineraryTransportationResponseDTO;
import com.fc.toy_project2.domain.itinerary.dto.response.ItineraryVisitResponseDTO;
import com.fc.toy_project2.domain.itinerary.service.ItineraryPostUpdateService;
import com.fc.toy_project2.global.DTO.ResponseDTO;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/itinerary")
public class ItineraryPostController {

private final ItineraryPostUpdateService itinerarypostUpdateService;


@PostMapping("/accommodation/{tripId}")
public ResponseEntity<ResponseDTO<ItineraryAccommodationResponseDTO>> createAccommodation(@PathVariable Long tripId,
@Valid @RequestBody ItineraryAccommodationCreateDTO itineraryAccommodationCreateDTO) {
return ResponseEntity.status(HttpStatus.CREATED).body(ResponseDTO.res(HttpStatus.CREATED,
itinerarypostUpdateService.createAccommodation(itineraryAccommodationCreateDTO, tripId),
"숙박 여정을 성공적으로 등록했습니다."));
}

@PostMapping("/transportation/{tripId}")
public ResponseEntity<ResponseDTO<ItineraryTransportationResponseDTO>> createTransportation(@PathVariable Long tripId,
@Valid @RequestBody ItineraryTransportationCreateDTO itineraryTransportationCreateDTO) {
return ResponseEntity.status(HttpStatus.CREATED).body(ResponseDTO.res(HttpStatus.CREATED,
itinerarypostUpdateService.createTransportation(itineraryTransportationCreateDTO, tripId),
"이동 여정을 성공적으로 등록했습니다."));
}

@PostMapping("/visit/{tripId}")
public ResponseEntity<ResponseDTO<ItineraryVisitResponseDTO>> createVisit(@PathVariable Long tripId,
@Valid @RequestBody ItineraryVisitCreateDTO itineraryVisitCreateDTO) {
return ResponseEntity.status(HttpStatus.CREATED).body(ResponseDTO.res(HttpStatus.CREATED,
itinerarypostUpdateService.createVisit(itineraryVisitCreateDTO, tripId),
"체류 여정을 성공적으로 등록했습니다."));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.fc.toy_project2.domain.itinerary.controller;

import com.fc.toy_project2.domain.itinerary.dto.response.ItineraryGetResponseDTO;
import com.fc.toy_project2.domain.itinerary.exception.InvalidAccommodationException;
import com.fc.toy_project2.domain.itinerary.exception.InvalidTransportationException;
import com.fc.toy_project2.domain.itinerary.exception.InvalidVisitException;
import com.fc.toy_project2.global.DTO.ResponseDTO;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ItineraryPostControllerAdvice {

@ExceptionHandler
public ResponseEntity<ResponseDTO<ItineraryGetResponseDTO>> invalidAccommodationException(
InvalidAccommodationException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(ResponseDTO.res(HttpStatus.BAD_REQUEST, e.getMessage()));
}

@ExceptionHandler
public ResponseEntity<ResponseDTO<ItineraryGetResponseDTO>> invalidTransportationException(
InvalidTransportationException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(ResponseDTO.res(HttpStatus.BAD_REQUEST, e.getMessage()));
}

@ExceptionHandler
public ResponseEntity<ResponseDTO<ItineraryGetResponseDTO>> invalidVisitException(
InvalidVisitException e) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(ResponseDTO.res(HttpStatus.BAD_REQUEST, e.getMessage()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.fc.toy_project2.domain.itinerary.dto.request.createDTO;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class ItineraryAccommodationCreateDTO {

@NotNull
private String accommodationName;

@NotNull
private String accommodationRoadAddressName;

@NotBlank
private String checkIn;

@NotBlank
private String checkOut;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.fc.toy_project2.domain.itinerary.dto.request.createDTO;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class ItineraryTransportationCreateDTO {
@NotNull
private String transportation;

@NotNull
private String departurePlace;

@NotNull
private String departurePlaceRoadAddressName;

@NotNull
private String destinationRoadAddressName;

@NotNull
private String destination;

@NotBlank
private String departureTime;

@NotBlank
private String arrivalTime;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.fc.toy_project2.domain.itinerary.dto.request.createDTO;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class ItineraryVisitCreateDTO {
@NotNull
private String placeName;
@NotNull
private String placeRoadAddressName;
@NotBlank
private String arrivalTime;
@NotBlank
private String departureTime;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.fc.toy_project2.domain.itinerary.dto.request.patchDTO;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class ItineraryAccommodationPatchDTO {

private String accommodationName;
private String accommodationRoadAddressName;
private String checkIn;
private String checkOut;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.fc.toy_project2.domain.itinerary.dto.response;
package com.fc.toy_project2.domain.itinerary.dto.request.patchDTO;

import java.time.LocalDateTime;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
@Builder
public class ItineraryTransportationDTO {
public class ItineraryTransportationPatchDTO {

private String transportation;
private String departurePlace;
Expand All @@ -16,4 +16,4 @@ public class ItineraryTransportationDTO {
private String destinationRoadAddressName;
private LocalDateTime departureTime;
private LocalDateTime arrivalTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.fc.toy_project2.domain.itinerary.dto.request.patchDTO;

import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
@Builder
public class ItineraryVisitPatchDTO {

private String placeName;
private String placeRoadAddressName;
private LocalDateTime arrivalTime;
private LocalDateTime departureTime;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.fc.toy_project2.domain.itinerary.dto.response;

import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
@Builder
public class ItineraryAccommodationResponseDTO {

private String accommodationName;
private String accommodationRoadAddressName;
private LocalDateTime checkIn;
private LocalDateTime checkOut;

public static ItineraryAccommodationResponseDTO of(String accommodationName,
String accommodationRoadAddressName, LocalDateTime checkIn, LocalDateTime checkOut) {
return ItineraryAccommodationResponseDTO.builder()
.accommodationName(accommodationName)
.accommodationRoadAddressName(accommodationRoadAddressName)
.checkIn(checkIn)
.checkOut(checkOut)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.fc.toy_project2.domain.itinerary.dto.response;

import com.fc.toy_project2.domain.trip.entity.Trip;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class ItineraryGetResponseDTO {

private Long itineraryId;
}
private Long id;
private Trip trip;
public static ItineraryGetResponseDTO of(Long id, Trip trip) {
return ItineraryGetResponseDTO.builder()
.id(id)
.trip(trip)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package com.fc.toy_project2.domain.itinerary.dto.response;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import lombok.*;

@Getter
@Builder
Expand All @@ -16,4 +11,14 @@ public class ItinerarySearchResponseDTO {
private String placeName;
private String roadAddressName;
private String placeUrl;
}

public static ItinerarySearchResponseDTO of(String placeName, String roadAddressName,
String placeUrl) {
return ItinerarySearchResponseDTO.builder()
.placeName(placeName)
.roadAddressName(roadAddressName)
.placeUrl(placeUrl)
.build();
}

}
Loading

0 comments on commit a51717c

Please sign in to comment.