Skip to content

Commit

Permalink
Merge pull request #31 from FC-Toy-Project-9/bugfix/trip-get
Browse files Browse the repository at this point in the history
여정 조회 및 특정 여행 조회 수정
  • Loading branch information
JeongUijeong authored Oct 29, 2023
2 parents 6f01266 + b96ea7a commit b823097
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public AccommodationResponseDTO createAccommodation(
accommodationCreateRequestDTO.getCheckOut());
checkAccommodationDate(trip, checkIn, checkOut);
return itineraryRepository.save(Itinerary.builder().trip(trip).type(0)
.itineraryName(accommodationCreateRequestDTO.getItineraryName())
.itineraryName(accommodationCreateRequestDTO.getItineraryName())
.accommodationName(accommodationCreateRequestDTO.getAccommodationName())
.accommodationRoadAddressName(
accommodationCreateRequestDTO.getAccommodationRoadAddressName()).checkIn(checkIn)
Expand Down Expand Up @@ -157,11 +157,10 @@ public VisitResponseDTO createVisit(VisitCreateRequestDTO visitCreateRequestDTO)
visitCreateRequestDTO.getArrivalTime());
checkVisitDate(trip, departureTime, arrivalTime);
return itineraryRepository.save(Itinerary.builder().trip(trip).type(2)
.itineraryName(visitCreateRequestDTO.getItineraryName())
.placeName(visitCreateRequestDTO.getPlaceName())
.placeRoadAddressName(visitCreateRequestDTO.getPlaceRoadAddressName())
.arrivalTime(arrivalTime).departureTime(departureTime).build())
.toVisitResponseDTO();
.itineraryName(visitCreateRequestDTO.getItineraryName())
.placeName(visitCreateRequestDTO.getPlaceName())
.placeRoadAddressName(visitCreateRequestDTO.getPlaceRoadAddressName())
.arrivalTime(arrivalTime).departureTime(departureTime).build()).toVisitResponseDTO();
}

/**
Expand Down Expand Up @@ -199,18 +198,13 @@ public List getItineraryByTripId(Long tripId) {
DateTypeFormatterUtil.localDateTimeToString(itinerary.getArrivalTime()))
.build());
} else if (itinerary.getType() == 2) {
itineraryResponseList.add(
TransportationResponseDTO.builder().itineraryId(itinerary.getId())
.itineraryName(itinerary.getItineraryName())
.transportation(itinerary.getTransportation())
.departurePlace(itinerary.getDeparturePlace())
.departurePlaceRoadAddressName(itinerary.getDeparturePlaceRoadAddressName())
.destination(itinerary.getDestination())
.destinationRoadAddressName(itinerary.getDestinationRoadAddressName())
.departureTime(DateTypeFormatterUtil.localDateTimeToString(
itinerary.getDepartureTime())).arrivalTime(
DateTypeFormatterUtil.localDateTimeToString(itinerary.getArrivalTime()))
.build());
itineraryResponseList.add(VisitResponseDTO.builder().itineraryId(itinerary.getId())
.itineraryName(itinerary.getItineraryName()).placeName(itinerary.getPlaceName())
.placeRoadAddressName(itinerary.getPlaceRoadAddressName()).arrivalTime(
DateTypeFormatterUtil.localDateTimeToString(itinerary.getArrivalTime()))
.departureTime(
DateTypeFormatterUtil.localDateTimeToString(itinerary.getDepartureTime()))
.build());
}
}
return itineraryResponseList;
Expand Down Expand Up @@ -338,13 +332,13 @@ private void checkTransportationDate(Trip trip, LocalDateTime departureTime,
if (departureTime.isAfter(arrivalTime)) {
throw new InvalidItineraryException("출발 시간은 도착 시간보다 이른 시간이어야 합니다.");
}
if(departureTime.isBefore(tripStartDateTime)){
if (departureTime.isBefore(tripStartDateTime)) {
throw new InvalidItineraryException("출발 시간은 여행 시작일 이후여야 합니다.");
}
if (departureTime.isAfter(tripEndDateTime)) {
throw new InvalidItineraryException("출발 시간은 여행 종료일보다 빠른 시간이어야 합니다.");
}
if(arrivalTime.isAfter(tripEndDateTime)){
if (arrivalTime.isAfter(tripEndDateTime)) {
throw new InvalidItineraryException("도착 시간은 여행 종료일보다 빠른 시간이어야 합니다.");
}
}
Expand All @@ -357,8 +351,7 @@ private void checkTransportationDate(Trip trip, LocalDateTime departureTime,
* @param arrivalTime 도착 시간
* @throws InvalidItineraryException 날짜 유효성 검사 실패 시 발생
*/
private void checkVisitDate(Trip trip, LocalDateTime departureTime,
LocalDateTime arrivalTime) {
private void checkVisitDate(Trip trip, LocalDateTime departureTime, LocalDateTime arrivalTime) {
LocalDateTime tripStartDateTime = trip.getStartDate().atStartOfDay();
LocalDateTime tripEndDateTime = trip.getEndDate().atTime(LocalTime.MAX);
if (arrivalTime.isAfter(departureTime)) {
Expand All @@ -367,7 +360,7 @@ private void checkVisitDate(Trip trip, LocalDateTime departureTime,
if (arrivalTime.isBefore(tripStartDateTime)) {
throw new InvalidItineraryException("도착 시간은 여행 시작일 이후여야 합니다.");
}
if(arrivalTime.isAfter(tripEndDateTime)){
if (arrivalTime.isAfter(tripEndDateTime)) {
throw new InvalidItineraryException("도착 시간은 여행 종료일보다 빠른 시간이어야 합니다.");
}
if (departureTime.isAfter(tripEndDateTime)) {
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/com/fc/toy_project2/domain/trip/entity/Trip.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fc.toy_project2.domain.itinerary.dto.response.AccommodationResponseDTO;
import com.fc.toy_project2.domain.itinerary.dto.response.TransportationResponseDTO;
import com.fc.toy_project2.domain.itinerary.dto.response.VisitResponseDTO;
import com.fc.toy_project2.domain.itinerary.entity.Itinerary;
import com.fc.toy_project2.domain.trip.dto.request.UpdateTripRequestDTO;
import com.fc.toy_project2.domain.trip.dto.response.GetTripResponseDTO;
Expand Down Expand Up @@ -143,17 +144,12 @@ public List<Object> getItineraryResponseDTO() {
DateTypeFormatterUtil.localDateTimeToString(itinerary.getArrivalTime()))
.build());
} else if (itinerary.getType() == 2) {
itineraryList.add(TransportationResponseDTO.builder().itineraryId(itinerary.getId())
.itineraryName(itinerary.getItineraryName())
.transportation(itinerary.getTransportation())
.departurePlace(itinerary.getDeparturePlace())
.departurePlaceRoadAddressName(itinerary.getDeparturePlaceRoadAddressName())
.destination(itinerary.getDestination())
.destinationRoadAddressName(itinerary.getDestinationRoadAddressName())
itineraryList.add(VisitResponseDTO.builder().itineraryId(itinerary.getId())
.itineraryName(itinerary.getItineraryName()).placeName(itinerary.getPlaceName())
.placeRoadAddressName(itinerary.getPlaceRoadAddressName()).arrivalTime(
DateTypeFormatterUtil.localDateTimeToString(itinerary.getArrivalTime()))
.departureTime(
DateTypeFormatterUtil.localDateTimeToString(itinerary.getDepartureTime()))
.arrivalTime(
DateTypeFormatterUtil.localDateTimeToString(itinerary.getArrivalTime()))
.build());
}
}
Expand Down

0 comments on commit b823097

Please sign in to comment.