Skip to content

Commit

Permalink
Merge pull request #13 from DO-SOPT-CDS-TEAM-WEB7/refactor/#12
Browse files Browse the repository at this point in the history
[Refactor] 명세서랑 다른 점 수정 및 로직 변경
  • Loading branch information
sss4920 authored Nov 27, 2023
2 parents 6321dbd + f7e0a46 commit e47137c
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.util.Date;

public record TicketRequestDto(Date startDate, Date endDate, Long airId) {
public static TicketRequestDto of(Date startDate, Date endDate, Long airId){
return new TicketRequestDto(startDate,endDate,airId);
public record TicketRequestDto(Date startDate, Date endDate, Long reservationId) {
public static TicketRequestDto of(Date startDate, Date endDate, Long reservationId){
return new TicketRequestDto(startDate,endDate,reservationId);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.third.thirdseminar.controller.dto.response;
import org.third.thirdseminar.domain.TimeRange;

public record AirResultDto(DateDto dateDto, Long airId, String airName, TimeRange startTime, TimeRange endTime) {
public static AirResultDto of(DateDto dateDto, Long airId, String airName, TimeRange startTime, TimeRange endTime) {
return new AirResultDto(dateDto, airId, airName, startTime, endTime);
public record AirResultDto(DateDto dateDto, Long reservationId, String airName, TimeRangeDto startTime, TimeRangeDto endTime) {
public static AirResultDto of(DateDto dateDto, Long reservationId, String airName, TimeRangeDto startTime, TimeRangeDto endTime) {
return new AirResultDto(dateDto, reservationId, airName, startTime, endTime);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum Error {
*/
DUMMY_NOT_FOUND(HttpStatus.NOT_FOUND, "더미에 데이터가 덜 들어간 것 같아요"),

AIR_NOT_FOUND(HttpStatus.NOT_FOUND, "항공사를 찾지 못했어요."),
RESERVATION_NOT_FOUND(HttpStatus.NOT_FOUND, "예약정보를 찾지 못했어요"),
/**
* 500 INTERNAL_SERVER_ERROR
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import org.third.thirdseminar.domain.Reservation;

import java.util.List;
import java.util.Optional;

public interface ReservationJpaRepository extends JpaRepository<Reservation, Long> {
@Query("SELECT r FROM Reservation r WHERE r.cityName <> :cityName")
List<Reservation> findAllExcludingCity(@Param("cityName") String cityName);

Reservation findByAir_AirId(@Param("airId") Long airId);
Optional<Reservation> findById(Long reservationId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public class MainService {

public List<CardDto> getCards(){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd E");
NumberFormat priceFormat = NumberFormat.getCurrencyInstance();
priceFormat.setCurrency(Currency.getInstance("KRW"));
NumberFormat priceFormat = NumberFormat.getInstance(Locale.getDefault());

return reservationJpaRepository.findAllExcludingCity("삿포로").stream().map((reservation)->
CardDto.of(reservation.getCityName(),
reservation.getCountry(),
format.format(reservation.getStartDate()),
format.format(reservation.getEndDate()),
reservation.getAir().getAirName(),
priceFormat.format(providerMinPrice(reservation.getTickets()))+"원")
priceFormat.format(providerMinPrice(reservation.getTickets()))+"원 출발")
).collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private TimeRangeDto TimeRangeFormat(TimeRange timeRange){
String endTime = timeRange.getEnd().format( DateTimeFormatter.ofPattern( "H:mm" ));
String during = timeRange.getDuring().format(DateTimeFormatter.ofPattern("H시간 mm분"));


return new TimeRangeDto(startTime, endTime, during);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
package org.third.thirdseminar.service;

import java.text.DecimalFormat;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.third.thirdseminar.controller.dto.request.TicketRequestDto;
import org.third.thirdseminar.controller.dto.response.DateDto;
import org.third.thirdseminar.controller.dto.response.TicketDto;
import org.third.thirdseminar.controller.dto.response.TimeRangeDto;
import org.third.thirdseminar.domain.Air;
import org.third.thirdseminar.controller.dto.response.AirResultDto;
import org.third.thirdseminar.domain.Reservation;
import org.third.thirdseminar.domain.TimeRange;
import org.third.thirdseminar.exception.Error;
import org.third.thirdseminar.exception.model.NotFoundException;
import org.third.thirdseminar.infrastructure.AirJpaRepository;
import org.third.thirdseminar.infrastructure.ReservationJpaRepository;
import org.third.thirdseminar.infrastructure.TicketJpaRepository;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
@RequiredArgsConstructor
public class TicketService {
private final ReservationJpaRepository reservationJpaRepository;
private final AirJpaRepository airJpaRepository;
private final TicketJpaRepository ticketJpaRepository;
private final DecimalFormat df = new DecimalFormat("###,###");


public List<TicketDto> getTicketList(){
return ticketJpaRepository.findAll().stream().map(
(ticket)->
Expand All @@ -41,19 +46,30 @@ public List<TicketDto> getTicketList(){
}

public AirResultDto getAirInformation(TicketRequestDto ticketRequestDto){
Air air= airJpaRepository.findById(ticketRequestDto.airId())
.orElseThrow(()-> new NotFoundException(Error.AIR_NOT_FOUND,Error.AIR_NOT_FOUND.getMessage())); //air 객체 주워오기
Reservation reservation = reservationJpaRepository.findById(ticketRequestDto.reservationId())
.orElseThrow( ()-> new NotFoundException(Error.RESERVATION_NOT_FOUND, Error.RESERVATION_NOT_FOUND.getMessage())
);
Air air= reservation.getAir();
DateDto dateDto = new DateDto(ticketRequestDto.startDate(), ticketRequestDto.endDate()); //date 객체 주워오기
Reservation reservation = reservationJpaRepository.findByAir_AirId(air.getAirId());

return AirResultDto.of(
dateDto,
air.getAirId(),
reservation.getId(),
air.getAirName(),
reservation.getStartTime(),
reservation.getEndTime()
TimeRangeFormat(reservation.getStartTime()),
TimeRangeFormat(reservation.getEndTime())
);
}

private TimeRangeDto TimeRangeFormat(TimeRange timeRange){
String startTime = timeRange.getStart().format( DateTimeFormatter.ofPattern( "HH:mm" ));
String endTime = timeRange.getEnd().format( DateTimeFormatter.ofPattern( "HH:mm" ));
String during = timeRange.getDuring().format(DateTimeFormatter.ofPattern("H시간 mm분"));


return new TimeRangeDto(startTime, endTime, during);
}




Expand Down

0 comments on commit e47137c

Please sign in to comment.