Skip to content

Commit

Permalink
Merge pull request #75 from nathan29849/be/feature/#40-reservation_in…
Browse files Browse the repository at this point in the history
…fo_search

feat: [40] 숙소 예약 내역 상세 조회
  • Loading branch information
SeokHo Ham committed Jun 7, 2022
2 parents 55ffa5b + 0c1a664 commit 37ec57a
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
import org.springframework.stereotype.Service;
import team15.airbnb.accommodation.domain.Accommodation;
import team15.airbnb.accommodation.infrastructure.AccommodationRepository;
import team15.airbnb.reservation.infrastructure.ReservationRepository;
import team15.airbnb.reservation.presentation.dto.PreviewResponse;
import team15.airbnb.reservation.presentation.dto.ReservationResponse;

@Slf4j
@Service
public class ReservationService {

private final AccommodationRepository accommodationRepository;
private final ReservationRepository reservationRepository;

public ReservationService(AccommodationRepository accommodationRepository) {
public ReservationService(
AccommodationRepository accommodationRepository, ReservationRepository reservationRepository) {
this.accommodationRepository = accommodationRepository;
this.reservationRepository = reservationRepository;
}

public PreviewResponse previewReservationFee(Long accommodationId, LocalDate checkInDate, LocalDate checkOutDate) {
Expand All @@ -24,4 +29,8 @@ public PreviewResponse previewReservationFee(Long accommodationId, LocalDate che
log.info("duration: {}", duration);
return accommodation.previewReservationFee(duration);
}

public ReservationResponse searchReservation(Long userId) {
return new ReservationResponse(reservationRepository.findByUserId(userId));
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package team15.airbnb.reservation.infrastructure;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;
import team15.airbnb.reservation.presentation.dto.ReservationDto;

@Repository
public class ReservationRepository {

@PersistenceContext
private EntityManager em;

public List<ReservationDto> findByUserId(Long userId) {
return em.createQuery(
"select new team15.airbnb.reservation.presentation.dto.ReservationDto("
+ "r.id, r.checkInDate, r.checkOutDate, a.address.city, a.address.firstAddress, a.accommodationName, a.mainImage) "
+ "from Reservation r "
+ "join r.accommodation a "
+ "where r.user.id = :userId and r.isDeleted = false ", ReservationDto.class)
.setParameter("userId", userId)
.getResultList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import org.springframework.web.bind.annotation.RequestParam;
import team15.airbnb.reservation.application.ReservationService;
import team15.airbnb.reservation.presentation.dto.PreviewResponse;
import team15.airbnb.reservation.presentation.dto.ReservationResponse;

@Controller
@RequestMapping("/reservation")
@RequestMapping("/reservations")
public class ReservationController {

private final ReservationService reservationService;
Expand All @@ -20,6 +21,14 @@ public ReservationController(ReservationService reservationService) {
this.reservationService = reservationService;
}

@GetMapping
public ResponseEntity<ReservationResponse> searchReservation() {
/*
TODO : user 정보 체크 후 user id 가져오기 (현재는 default : 4)
*/
return ResponseEntity.ok().body(reservationService.searchReservation(4L));
}

@GetMapping("/preview")
public ResponseEntity<PreviewResponse> previewFeePolicy(
@RequestParam Long id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package team15.airbnb.reservation.presentation.dto;

import java.time.LocalDate;
import lombok.Getter;
import team15.airbnb.accommodation.domain.City;

@Getter
public class ReservationDto {

private Long reservationId;
private LocalDate checkInDate;
private LocalDate checkOutDate;
private String location;
private String accommodationName;
private String mainImage;

public ReservationDto(Long reservationId, LocalDate checkInDate, LocalDate checkOutDate, City city, String firstAddress, String accommodationName, String mainImage) {
this.reservationId = reservationId;
this.checkInDate = checkInDate;
this.checkOutDate = checkOutDate;
this.location = city.getName() + firstAddress;
this.accommodationName = accommodationName;
this.mainImage = mainImage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package team15.airbnb.reservation.presentation.dto;

import java.util.ArrayList;
import java.util.List;
import lombok.Getter;

@Getter
public class ReservationResponse {

private List<ReservationDto> reservations = new ArrayList<>();

public ReservationResponse(List<ReservationDto> reservations) {
this.reservations = reservations;
}
}

0 comments on commit 37ec57a

Please sign in to comment.