Skip to content

Commit

Permalink
Merge pull request #25 from junu0516/feat/detailReservation
Browse files Browse the repository at this point in the history
Feat/detail reservation
  • Loading branch information
leezzangmin authored May 30, 2022
2 parents 8727281 + 20a6664 commit be7c981
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 42 deletions.
12 changes: 7 additions & 5 deletions BE/airbnb/src/main/java/team07/airbnb/address/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import java.math.BigDecimal;
import javax.persistence.Embeddable;
import lombok.Getter;

@Embeddable
@Getter
public class Address {

private String country;
private String state;
private String city;
private BigDecimal longitude;
private BigDecimal latitude;
private String roomCountry;
private String roomState;
private String roomCity;
private BigDecimal roomLongitude;
private BigDecimal roomLatitude;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package team07.airbnb.dto;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import lombok.Getter;
import team07.airbnb.address.Address;
import team07.airbnb.image.Image;
import team07.airbnb.reservation.Reservation;

@Getter
public class ReservationDetailResponse {

private String roomName;
private Address address;
private List<String> images = new ArrayList<>();
private LocalDate startAt;
private LocalDate endAt;
private String hostName;
private int guestAmount;
private int totalPrice;

public ReservationDetailResponse(String roomName, Address address,
List<String> images, LocalDate startAt, LocalDate endAt, String hostName, int guestAmount,
int totalPrice) {
this.roomName = roomName;
this.address = address;
this.images = images;
this.startAt = startAt;
this.endAt = endAt;
this.hostName = hostName;
this.guestAmount = guestAmount;
this.totalPrice = totalPrice;
}

public static ReservationDetailResponse of(Reservation reservation, List<Image> images) {
return new ReservationDetailResponse(
reservation.getRoom().getRoomName(),
reservation.getRoom().getAddress(),
imageEntitiesToStringList(images),
reservation.getStartAt(),
reservation.getEndAt(),
reservation.getRoom().getHost().getUsername(),
reservation.getNumberOfGuest(),
reservation.getTotalPrice());
}

private static List<String> imageEntitiesToStringList(List<Image> images) {
return images.stream().map(i -> i.getImageLink())
.collect(Collectors.toList());
}

}
4 changes: 4 additions & 0 deletions BE/airbnb/src/main/java/team07/airbnb/image/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import team07.airbnb.room.Room;

@Entity
@NoArgsConstructor
@EqualsAndHashCode(of = "id")
@ToString(exclude = "room")
@Getter
public class Image {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
20 changes: 20 additions & 0 deletions BE/airbnb/src/main/java/team07/airbnb/image/ImageRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package team07.airbnb.image;

import java.util.List;
import javax.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class ImageRepository {

private final EntityManager em;

public List<Image> findByRoomId(Long roomId) {
return em.createQuery("select i from Image i where i.room.id=:roomId", Image.class)
.setParameter("roomId", roomId)
.getResultList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@
import java.time.LocalDate;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;
import team07.airbnb.dto.ReservationDetailResponse;
import team07.airbnb.room.Room;
import team07.airbnb.user.User;

@Entity
@NoArgsConstructor
@EqualsAndHashCode(of = "reservationId")
@ToString(exclude = {"room", "user"})
@Getter
public class Reservation {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long reservationId;
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ROOM_ID")
private Room room;
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "GUEST_ID")
private User user;
private LocalDate startAt;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package team07.airbnb.reservation;


import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import team07.airbnb.dto.ReservationDetailResponse;

@RestController
@RequiredArgsConstructor
public class ReservationController {

private final ReservationService reservationService;


@GetMapping("/reserve/{reservationId}")
public ReservationDetailResponse detailReservation(@PathVariable Long reservationId) {
return reservationService.findOne(reservationId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package team07.airbnb.reservation;


import javax.persistence.EntityManager;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class ReservationRepository {

private final EntityManager em;

public Reservation findReservationWithRoomAndHost(Long reservationId) {
return em.createQuery("select re from Reservation re join fetch re.room ro join fetch ro.host where re.reservationId=:reservationId", Reservation.class)
.setParameter("reservationId", reservationId).getSingleResult();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package team07.airbnb.reservation;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import team07.airbnb.dto.ReservationDetailResponse;
import team07.airbnb.image.Image;
import team07.airbnb.image.ImageRepository;

@Service
@RequiredArgsConstructor
@Transactional
public class ReservationService {

private final ReservationRepository reservationRepository;
private final ImageRepository imageRepository;

@Transactional(readOnly = true)
public ReservationDetailResponse findOne(Long reservationId) {
Reservation reservationAndRoom = reservationRepository.findReservationWithRoomAndHost(reservationId);
List<Image> images = imageRepository.findByRoomId(reservationAndRoom.getRoom().getId());
return ReservationDetailResponse.of(reservationAndRoom, images);
}

}
7 changes: 4 additions & 3 deletions BE/airbnb/src/main/java/team07/airbnb/review/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.LocalDate;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
Expand All @@ -15,16 +16,16 @@

@Entity
@NoArgsConstructor
@EqualsAndHashCode(of = "id;")
@EqualsAndHashCode(of = "id")
public class Review {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "REVIEW_ID")
private Long id;
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ROOM_ID")
private Room room;
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "USER_ID")
private User user;

Expand Down
5 changes: 3 additions & 2 deletions BE/airbnb/src/main/java/team07/airbnb/room/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import team07.airbnb.address.Address;
import team07.airbnb.user.User;

@Entity
@EqualsAndHashCode(of = "id")
//@Table(indexes = {@Index(columnList = "address")})
@NoArgsConstructor
@Getter
public class Room {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -31,7 +32,7 @@ public class Room {
private String roomName;
@Embedded
private Address address;
private String description;
private String roomDescription;
private int maxNumberOfGuest;
@Enumerated(EnumType.STRING)
private RoomType roomType;
Expand Down
8 changes: 4 additions & 4 deletions BE/airbnb/src/main/java/team07/airbnb/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@ToString
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(of = "userId")
@Table(name = "airbnb_user")
@Entity
@Getter
public class User {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -27,14 +27,14 @@ public class User {
private String profileImage;
private String userEmail;
@Enumerated(EnumType.STRING)
private UserRole role;
private UserRole userRole;
private String userPhone;


public User(String userEmail, String username, String userPhone, UserRole role) {
this.userEmail = userEmail;
this.username = username;
this.userPhone = userPhone;
this.role = role;
this.userRole = role;
}
}
2 changes: 1 addition & 1 deletion BE/airbnb/src/main/java/team07/airbnb/user/UserRole.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package team07.airbnb.user;

public enum UserRole {
GUEST, HOST
guest, host;
}
5 changes: 3 additions & 2 deletions BE/airbnb/src/main/java/team07/airbnb/wishlist/Wishlist.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
Expand All @@ -19,10 +20,10 @@ public class Wishlist {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "USER_ID")
private User user;
@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ROOM_ID")
private Room room;

Expand Down
53 changes: 53 additions & 0 deletions BE/airbnb/src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

insert into user
(USERNAME, USER_EMAIL, USER_PHONE, USER_ROLE, PROFILE_IMAGE)
values
('sally', 'sally@email.com', '010-1234-1234', 'guest', 'https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/%ED%98%B8%EC%8A%A4%ED%8A%B8+%EC%9D%B4%EB%AF%B8%EC%A7%80/%ED%8C%8C%EC%9D%B4%ED%8C%85.png'),
('zzangmin', 'zzangmin@email.com', '010-7890-1234', 'host','https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/%ED%98%B8%EC%8A%A4%ED%8A%B8+%EC%9D%B4%EB%AF%B8%EC%A7%80/%EC%A7%B1%EA%B5%AC-%ED%94%84%EB%A1%9C%ED%95%84.PNG'),
('공유', 'gongicheol@email.com', '010-2345-1234', 'host','https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/%ED%98%B8%EC%8A%A4%ED%8A%B8+%EC%9D%B4%EB%AF%B8%EC%A7%80/%EA%B3%B5%EC%9C%A0-%ED%94%84%EB%A1%9C%ED%95%84.PNG'),
('BoGum', 'BoGumn@email.com', '010-1111-1234', 'host','https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/%ED%98%B8%EC%8A%A4%ED%8A%B8+%EC%9D%B4%EB%AF%B8%EC%A7%80/%EB%B0%95%EB%B3%B4%EA%B2%80-%ED%94%84%EB%A1%9C%ED%95%84.jpg');

insert into ROOM
(ROOM_PRICE_PER_DAY, ROOM_NAME, MAX_NUMBER_OF_GUEST, ROOM_TYPE, NUMBER_OF_BED, NUMBER_OF_TOILET, ROOM_DESCRIPTION, HOST_ID, ROOM_COUNTRY, ROOM_STATE, ROOM_CITY, ROOM_LONGITUDE, ROOM_LATITUDE)
values
(340000, 'Euji님이 호스팅하는 집 전체', 6, 'residence', 3, 2, '계곡 옆 시냇물 소리와 함께 조용한곳에서 프라이빗하게 힐링하다 가실수 잇는 숙소입니다!', 2, "한국", "경기도", "안양시", 37.5866076, 126.9726223),
(200000, 'Doyle님이 호스팅하는 게스트 스위트 전체', 8,'residence',3,2,'알펜시아 리조트 1km 거리 위치해 있습니다. 겨울엔 스키타러 오시기 좋습니다. 여름에 워터파크 골프장 삼양목장 둘러보시면 좋습니다.', 2, "한국", "충청도", "안양시", 37.5866076, 126.9726223),
(281429,'다솜님이 호스팅하는 펜션',8,'pension',2,2,'사천해변과 가까운 평온한 시골마을 한옥집에서 편안한 시간 보내세요.', 3, "한국", "경상도", "포항시", 37.5866076, 126.9726223),
(212571,'은주님이 호스팅하는 공동 주택 전체',6,'residence',4,2,'거실과 침실에 멋진 바다를 품은 숙소입니다. 고층에서 보이는 바다뷰가 마음을 평온하게 해줄꺼예요. 거실에 가만히 앉아 바다를 바라보며 힐링하셔요.', 3, "한국", "평안남도", "냉면시", 37.5866076, 126.9726223),
(258571,'마당가님이 호스팅하는 전원주택 전체',6,'pension',3,2,'250평 이상의 넓은 앞마당에서의 힐링과 야외 정자에서 오붓한 저녁식사가 가능한 독채 입니다. 앞마당에 펼쳐진 밤 조경도 너무 이쁜 숙소 입니다. 내부 공간 40평으로 온가족 편히 쉬다 가실수 있게 마련해 놓았습니다.', 4, "한국", "제주도", "삼다수시", 37.5866076, 126.9726223),
(550000,'형철님이 호스팅하는 저택 전체',6,'pension',3,2,'강원도 평창 뇌운계곡에 위치한 프라이빗한 풀빌라펜션입니다. 독채펜션으로 주변시선을 신경쓰지않고 오롯이 고객님들만이 프라이빗하게 즐기수있는 펜션입니다.', 4, "한국", "거제도", "꼬막시", 37.5866076, 126.9726223);


insert into IMAGE
(IMAGE_LINK, IMAGE_ORDER, ROOM_ID)
values
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/1-%EC%A7%84%EB%B6%80%EB%A9%B4-%EC%9D%80%EC%A7%801.PNG',1,1),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/1-%EC%A7%84%EB%B6%80%EB%A9%B4-%EC%9D%80%EC%A7%802.PNG',2,1),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/1-%EC%A7%84%EB%B6%80%EB%A9%B4-%EC%9D%80%EC%A7%803.PNG',3,1),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/1-%EC%A7%84%EB%B6%80%EB%A9%B4-%EC%9D%80%EC%A7%804.PNG',4,1),


('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/2-%ED%8F%89%EC%B0%BD-%EB%B3%B4%EB%AF%BC1.PNG',1,2),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/2-room-1.jpg',2,2),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/2-room-3.jpg',3,2),

('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/3-%EA%B0%95%EB%A6%89-%EB%8B%A4%EC%86%9C1.PNG',1,3),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/3-%EA%B0%95%EB%A6%89-%EB%8B%A4%EC%86%9C2.PNG',2,3),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/3-%EA%B0%95%EB%A6%89-%EB%8B%A4%EC%86%9C3.PNG',3,3),

('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/4-%EA%B3%A0%EC%84%B1%EA%B5%B0-%EC%9D%80%EC%A3%BC-1.PNG',1,4),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/4-%EA%B3%A0%EC%84%B1%EA%B5%B0-%EC%9D%80%EC%A3%BC-2.PNG',2,4),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/4-%EA%B3%A0%EC%84%B1%EA%B5%B0-%EC%9D%80%EC%A3%BC-3.PNG',3,4),

('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/5-%EC%B6%98%EC%B2%9C-%EB%A7%88%EB%8B%B9%EA%B0%80-1.PNG',1,5),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/5-%EC%B6%98%EC%B2%9C-%EB%A7%88%EB%8B%B9%EA%B0%80-2.PNG',2,5),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/5-%EC%B6%98%EC%B2%9C-%EB%A7%88%EB%8B%B9%EA%B0%80-3.PNG',3,5),

('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/6-%ED%8F%89%EC%B0%BD-%ED%98%95%EC%B2%A0-1.PNG',1,6),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/6-%ED%8F%89%EC%B0%BD-%ED%98%95%EC%B2%AD-2.PNG',2,6),
('https://sally-airbnb.s3.ap-northeast-2.amazonaws.com/6-%ED%8F%89%EC%B0%BD-%ED%98%95%EC%B2%A0-3.PNG',3,6);

insert into RESERVATION
(ROOM_ID, GUEST_ID, START_AT, END_AT, NUMBER_OF_GUEST, TOTAL_PRICE)
VALUES
(1, 1, '2022-05-15', '2022-05-17', 3, 1020000);
Loading

0 comments on commit be7c981

Please sign in to comment.