Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

여정 등록, 조회, 수정 수정 #28

Merged
merged 3 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,22 @@ public List<ItinerarySearchResponseDTO> getPlaceByKeyword(String query) throws E
/**
* 숙박과 관련된 여정을 생성합니다.
*
* @param itineraryAccommodationCreateDTO 숙박 여정 생성 요청 DTO
* @param accommodationCreateRequestDTO 숙박 여정 생성 요청 DTO
* @return 생성된 숙박 여정 응답 DTO
*/
public AccommodationResponseDTO createAccommodation(
AccommodationCreateRequestDTO itineraryAccommodationCreateDTO) {
Trip trip = tripService.getTrip(itineraryAccommodationCreateDTO.getTripId());
AccommodationCreateRequestDTO accommodationCreateRequestDTO) {
Trip trip = tripService.getTrip(accommodationCreateRequestDTO.getTripId());
LocalDateTime checkIn = DateTypeFormatterUtil.dateTimeFormatter(
itineraryAccommodationCreateDTO.getCheckIn());
accommodationCreateRequestDTO.getCheckIn());
LocalDateTime checkOut = DateTypeFormatterUtil.dateTimeFormatter(
itineraryAccommodationCreateDTO.getCheckOut());
accommodationCreateRequestDTO.getCheckOut());
checkAccommodationDate(trip, checkIn, checkOut);
return itineraryRepository.save(Itinerary.builder().trip(trip).type(0) // 숙박 여정 유형
.accommodationName(itineraryAccommodationCreateDTO.getAccommodationName())
return itineraryRepository.save(Itinerary.builder().trip(trip).type(0)
.itineraryName(accommodationCreateRequestDTO.getItineraryName())
.accommodationName(accommodationCreateRequestDTO.getAccommodationName())
.accommodationRoadAddressName(
itineraryAccommodationCreateDTO.getAccommodationRoadAddressName()).checkIn(checkIn)
accommodationCreateRequestDTO.getAccommodationRoadAddressName()).checkIn(checkIn)
.checkOut(checkOut).build()).toAccommodationResponseDTO();
}

Expand All @@ -128,8 +129,9 @@ public TransportationResponseDTO createTransportation(
transportationCreateRequestDTO.getDepartureTime());
LocalDateTime arrivalTime = DateTypeFormatterUtil.dateTimeFormatter(
transportationCreateRequestDTO.getArrivalTime());
checkTransportationVisitDate(trip, departureTime, arrivalTime);
checkTransportationDate(trip, departureTime, arrivalTime);
return itineraryRepository.save(Itinerary.builder().trip(trip).type(1)
.itineraryName(transportationCreateRequestDTO.getItineraryName())
.transportation(transportationCreateRequestDTO.getTransportation())
.departurePlace(transportationCreateRequestDTO.getDeparturePlace())
.departurePlaceRoadAddressName(
Expand All @@ -149,15 +151,16 @@ public TransportationResponseDTO createTransportation(
*/
public VisitResponseDTO createVisit(VisitCreateRequestDTO visitCreateRequestDTO) {
Trip trip = tripService.getTrip(visitCreateRequestDTO.getTripId());
LocalDateTime visitDepartureTime = DateTypeFormatterUtil.dateTimeFormatter(
LocalDateTime departureTime = DateTypeFormatterUtil.dateTimeFormatter(
visitCreateRequestDTO.getDepartureTime());
LocalDateTime visitArrivalTime = DateTypeFormatterUtil.dateTimeFormatter(
LocalDateTime arrivalTime = DateTypeFormatterUtil.dateTimeFormatter(
visitCreateRequestDTO.getArrivalTime());
checkTransportationVisitDate(trip, visitDepartureTime, visitArrivalTime);
return itineraryRepository.save(
Itinerary.builder().trip(trip).type(1).placeName(visitCreateRequestDTO.getPlaceName())
.placeRoadAddressName(visitCreateRequestDTO.getPlaceRoadAddressName())
.arrivalTime(visitArrivalTime).departureTime(visitDepartureTime).build())
checkVisitDate(trip, departureTime, arrivalTime);
return itineraryRepository.save(Itinerary.builder().trip(trip).type(1)
.itineraryName(visitCreateRequestDTO.getItineraryName())
.placeName(visitCreateRequestDTO.getPlaceName())
.placeRoadAddressName(visitCreateRequestDTO.getPlaceRoadAddressName())
.arrivalTime(arrivalTime).departureTime(departureTime).build())
.toVisitResponseDTO();
}

Expand All @@ -169,7 +172,7 @@ public VisitResponseDTO createVisit(VisitCreateRequestDTO visitCreateRequestDTO)
*/
public List getItineraryByTripId(Long tripId) {
List<Object> itineraryResponseList = new ArrayList<>();
List<Itinerary> itineraryList = itineraryRepository.findAllByTripId(tripId);
List<Itinerary> itineraryList = tripService.getTrip(tripId).getItineraries();
for (Itinerary itinerary : itineraryList) {
if (itinerary.getType() == 0) {
itineraryResponseList.add(
Expand Down Expand Up @@ -246,7 +249,7 @@ public TransportationResponseDTO updateTransportation(
transportationUpdateRequestDTO.getDepartureTime());
LocalDateTime arrivalTime = DateTypeFormatterUtil.dateTimeFormatter(
transportationUpdateRequestDTO.getArrivalTime());
checkTransportationVisitDate(itinerary.getTrip(), departureTime, arrivalTime);
checkTransportationDate(itinerary.getTrip(), departureTime, arrivalTime);
itinerary.updateTransportationInfo(transportationUpdateRequestDTO.getItineraryName(),
transportationUpdateRequestDTO.getTransportation(),
transportationUpdateRequestDTO.getDeparturePlace(),
Expand All @@ -269,7 +272,7 @@ public VisitResponseDTO updateVisit(VisitUpdateRequestDTO visitUpdateRequestDTO)
visitUpdateRequestDTO.getDepartureTime());
LocalDateTime arrivalTime = DateTypeFormatterUtil.dateTimeFormatter(
visitUpdateRequestDTO.getArrivalTime());
checkTransportationVisitDate(itinerary.getTrip(), departureTime, arrivalTime);
checkVisitDate(itinerary.getTrip(), departureTime, arrivalTime);
itinerary.updateVisitInfo(visitUpdateRequestDTO.getItineraryName(),
visitUpdateRequestDTO.getPlaceName(), visitUpdateRequestDTO.getPlaceRoadAddressName(),
departureTime, arrivalTime);
Expand All @@ -296,47 +299,79 @@ private Itinerary getItinerary(Long itineraryId) {
}

/**
* 체류 및 이동에 관한 날짜 유효성 검사
* 숙박 여정의 날짜 유효성 검사
*
* @param trip 여정이 속한 여행
* @param checkIn 숙박 시작일
* @param checkOut 숙박 종료일
* @throws InvalidItineraryException 날짜 유효성 검사 실패 시 발생
*/
private void checkAccommodationDate(Trip trip, LocalDateTime checkIn, LocalDateTime checkOut) {
LocalDateTime tripStartDateTime = trip.getStartDate().atStartOfDay();
LocalDateTime tripEndDateTime = trip.getEndDate().atTime(LocalTime.MAX);
if (checkIn.isAfter(checkOut)) {
throw new InvalidItineraryException("체크인 시간은 체크아웃 시간보다 이른 시간이어야 합니다.");
}
if (checkIn.isBefore(tripStartDateTime)) {
throw new InvalidItineraryException("체크인 시간은 여행 시작일 이후여야 합니다.");
}
if (checkIn.isAfter(tripEndDateTime)) {
throw new InvalidItineraryException("체크인 시간은 여행 종료일보다 빠른 시간이어야 합니다.");
}
if (checkOut.isAfter(tripEndDateTime)) {
throw new InvalidItineraryException("체크아웃 시간은 여행 종료일보다 빠른 시간이어야 합니다.");
}
}

/**
* 이동에 관한 날짜 유효성 검사
*
* @param trip 여정이 속한 여행
* @param departureTime 출발 시간
* @param arrivalTime 도착 시간
* @throws InvalidItineraryException 날짜 유효성 검사 실패 시 발생
*/
private void checkTransportationVisitDate(Trip trip, LocalDateTime departureTime,
private void checkTransportationDate(Trip trip, LocalDateTime departureTime,
LocalDateTime arrivalTime) {
LocalDateTime tripStartDateTime = trip.getStartDate().atStartOfDay();
LocalDateTime tripEndDateTime = trip.getEndDate().atTime(LocalTime.MAX);
if (departureTime.isAfter(arrivalTime)) {
throw new InvalidItineraryException("출발 시간은 도착 시간보다 이른 시간이어야 합니다.");
}
if(departureTime.isBefore(tripStartDateTime)){
throw new InvalidItineraryException("출발 시간은 여행 시작일 이후여야 합니다.");
}
if (departureTime.isAfter(tripEndDateTime)) {
throw new InvalidItineraryException("출발 시간은 여행 종료일보다 빠른 시간이어야 합니다.");
}
if (arrivalTime.isBefore(tripStartDateTime)) {
throw new InvalidItineraryException("도착 시간은 여행 시작일보다 빠른 시간이어야 합니다.");
if(arrivalTime.isAfter(tripEndDateTime)){
throw new InvalidItineraryException("도착 시간은 여행 종료일보다 빠른 시간이어야 합니다.");
}
}

/**
* 숙박 여정의 날짜 유효성 검사
* 체류에 관한 날짜 유효성 검사
*
* @param trip 여정이 속한 여행
* @param checkIn 숙박 시작일
* @param checkOut 숙박 종료일
* @param trip 여정이 속한 여행
* @param departureTime 출발 시간
* @param arrivalTime 도착 시간
* @throws InvalidItineraryException 날짜 유효성 검사 실패 시 발생
*/
private void checkAccommodationDate(Trip trip, LocalDateTime checkIn, LocalDateTime checkOut) {
private void checkVisitDate(Trip trip, LocalDateTime departureTime,
LocalDateTime arrivalTime) {
LocalDateTime tripStartDateTime = trip.getStartDate().atStartOfDay();
LocalDateTime tripEndDateTime = trip.getEndDate().atTime(LocalTime.MAX);
if (checkIn.isAfter(checkOut)) {
throw new InvalidItineraryException("체크인 시간은 체크아웃 시간보다 이른 시간이어야 합니다.");
if (arrivalTime.isAfter(departureTime)) {
throw new InvalidItineraryException("도착 시간은 출발 시간보다 이른 시간이어야 합니다.");
}
if (checkIn.isAfter(tripEndDateTime)) {
throw new InvalidItineraryException("체크인 시간은 여행 종료일보다 빠른 시간이어야 합니다.");
if (arrivalTime.isBefore(tripStartDateTime)) {
throw new InvalidItineraryException("도착 시간은 여행 시작일 이후여야 합니다.");
}
if(arrivalTime.isAfter(tripEndDateTime)){
throw new InvalidItineraryException("도착 시간은 여행 종료일보다 빠른 시간이어야 합니다.");
}
if (checkOut.isBefore(tripStartDateTime)) {
throw new InvalidItineraryException("체크아웃 시간은 여헹 시작일보다 빠른 시간이어야 합니다.");
if (departureTime.isAfter(tripEndDateTime)) {
throw new InvalidItineraryException("출발 시간은 여행 종료일보다 빠른 시간이어야 합니다.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ void createVisit() throws Exception {
// given
VisitCreateRequestDTO request = VisitCreateRequestDTO.builder().tripId(1L)
.itineraryName("제주여정3").placeName("카멜리아힐").placeRoadAddressName("제주 서귀포시 안덕면 병악로 166")
.departureTime("2023-10-26 14:00").arrivalTime("2023-10-26 16:00").build();
.arrivalTime("2023-10-26 14:00").departureTime("2023-10-26 16:00").build();
VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder().itineraryId(1L)
.itineraryName("제주여정3").placeName("카멜리아힐").placeRoadAddressName("제주 서귀포시 안덕면 병악로 166")
.departureTime("2023-10-26 14:00").arrivalTime("2023-10-26 16:00").build();
.arrivalTime("2023-10-26 14:00").departureTime("2023-10-26 16:00").build();
given(itineraryService.createVisit(any(VisitCreateRequestDTO.class))).willReturn(
visitResponseDTO);

Expand Down Expand Up @@ -222,8 +222,8 @@ void getItineraryByTripId() throws Exception {
.departureTime("2023-10-26 12:00").arrivalTime("2023-10-26 13:00").build());
itinerarys.add(
VisitResponseDTO.builder().itineraryId(3L).itineraryName("제주여정3").placeName("카멜리아힐")
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").departureTime("2023-10-26 14:00")
.arrivalTime("2023-10-26 16:00").build());
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").arrivalTime("2023-10-26 14:00")
.departureTime("2023-10-26 16:00").build());

given(itineraryService.getItineraryByTripId(any(Long.TYPE))).willReturn(itinerarys);

Expand Down Expand Up @@ -364,12 +364,12 @@ void updateTransportation() throws Exception {
void updateVisit() throws Exception {
VisitUpdateRequestDTO request = VisitUpdateRequestDTO.builder().itineraryId(1L)
.itineraryName("즐거운 제주여정3").placeName("카멜리아힐")
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").departureTime("2023-10-26 14:00")
.arrivalTime("2023-10-26 16:00").build();
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").arrivalTime("2023-10-26 14:00")
.departureTime("2023-10-26 16:00").build();
VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder().itineraryId(1L)
.itineraryName("즐거운 제주여정3").placeName("카멜리아힐")
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").departureTime("2023-10-26 14:00")
.arrivalTime("2023-10-26 16:00").build();
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").arrivalTime("2023-10-26 14:00")
.departureTime("2023-10-26 16:00").build();
given(itineraryService.updateVisit(any(VisitUpdateRequestDTO.class))).willReturn(
visitResponseDTO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ void _willSuccess() throws Exception {
// given
VisitCreateRequestDTO request = VisitCreateRequestDTO.builder().tripId(1L)
.itineraryName("제주여정3").placeName("카멜리아힐")
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").departureTime("2023-10-26 14:00")
.arrivalTime("2023-10-26 16:00").build();
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").arrivalTime("2023-10-26 14:00")
.departureTime("2023-10-26 16:00").build();
VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder().itineraryId(1L)
.itineraryName("제주여정3").placeName("카멜리아힐")
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").departureTime("2023-10-26 14:00")
.arrivalTime("2023-10-26 16:00").build();
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").arrivalTime("2023-10-26 14:00")
.departureTime("2023-10-26 16:00").build();
given(itineraryService.createVisit(any(VisitCreateRequestDTO.class))).willReturn(
visitResponseDTO);

Expand Down Expand Up @@ -212,8 +212,8 @@ void _willSuccess() throws Exception {
.departureTime("2023-10-26 12:00").arrivalTime("2023-10-26 13:00").build());
itinerarys.add(
VisitResponseDTO.builder().itineraryId(3L).itineraryName("제주여정3").placeName("카멜리아힐")
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").departureTime("2023-10-26 14:00")
.arrivalTime("2023-10-26 16:00").build());
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").arrivalTime("2023-10-26 14:00")
.departureTime("2023-10-26 16:00").build());

given(itineraryService.getItineraryByTripId(any(Long.TYPE))).willReturn(itinerarys);

Expand Down Expand Up @@ -312,12 +312,12 @@ class Context_updateVisit {
void _willSuccess() throws Exception {
VisitUpdateRequestDTO request = VisitUpdateRequestDTO.builder().itineraryId(1L)
.itineraryName("즐거운 제주여정3").placeName("카멜리아힐")
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").departureTime("2023-10-26 14:00")
.arrivalTime("2023-10-26 16:00").build();
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").arrivalTime("2023-10-26 14:00")
.departureTime("2023-10-26 16:00").build();
VisitResponseDTO visitResponseDTO = VisitResponseDTO.builder().itineraryId(1L)
.itineraryName("즐거운 제주여정3").placeName("카멜리아힐")
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").departureTime("2023-10-26 14:00")
.arrivalTime("2023-10-26 16:00").build();
.placeRoadAddressName("제주 서귀포시 안덕면 병악로 166").arrivalTime("2023-10-26 14:00")
.departureTime("2023-10-26 16:00").build();
given(itineraryService.updateVisit(any(VisitUpdateRequestDTO.class))).willReturn(
visitResponseDTO);

Expand Down
Loading