Skip to content

Commit

Permalink
feat: Add RoomService (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
janeljs committed May 29, 2021
1 parent f97ac0a commit 683640a
Show file tree
Hide file tree
Showing 19 changed files with 315 additions and 73 deletions.
44 changes: 44 additions & 0 deletions BE/airbnb/src/main/java/airbnb/controller/RoomController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package airbnb.controller;

import airbnb.request.SearchRequest;
import airbnb.response.RoomDetailPageResponse;
import airbnb.response.RoomResponses;
import airbnb.service.RoomService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class RoomController {
private final RoomService roomService;

@GetMapping("/rooms")
public ResponseEntity<RoomResponses> search(SearchRequest searchRequest) {
return new ResponseEntity<>(roomService.findRoomsFilteredBy(searchRequest), HttpStatus.OK);
}

@GetMapping("/rooms/{roomId}")
public ResponseEntity<RoomDetailPageResponse> viewDetailPage(@PathVariable Long roomId) {
List<String> roomImages = new ArrayList<>();
roomImages.add("https://a0.muscache.com/im/pictures/a317fbfd-e121-4bcb-ac8b-f5720aaa016d.jpg?im_w=1200");
roomImages.add("https://a0.muscache.com/im/pictures/8a518449-1d87-4f5b-91db-e40e759db974.jpg?im_w=720");
roomImages.add("https://a0.muscache.com/im/pictures/cd05cf09-c7cf-4058-b6eb-f030bd4b76f4.jpg?im_w=720");
roomImages.add("https://a0.muscache.com/im/pictures/4725d94b-3f3b-4567-b5d1-bb08a3a131a0.jpg?im_w=720");
roomImages.add("https://a0.muscache.com/im/pictures/9273d0a4-a6de-422f-a33b-ea7f78c36504.jpg?im_w=720");
String title = "Seoul Sunday House (동대문/동묘역 가족 친구여행 2인기준, 주차 불가)";
String roomDescription = "서울 동대문 상가 위치에 있고 ,도매시장 두타 면세점 ,동묘역 빈티지시장 등 과 가깝습니다. 공항버스랑 지하철 역 도보 5분입니다\n" +
"성인 2명 가격기준, 아이 6살 이하 무료,성인 한명 추가시 20000 원 추가 됩니다.";
double rating = 4.7;
String host = "제인";
String hostImage = "https://a0.muscache.com/im/pictures/user/524726c2-8633-479c-b7a7-88d964f3c713.jpg?im_w=240";
int pricePerNight = 85000;
RoomDetailPageResponse detailPage = new RoomDetailPageResponse(roomImages, title, roomDescription, rating, host, hostImage, pricePerNight);
return ResponseEntity.ok(detailPage);
}
}
34 changes: 8 additions & 26 deletions BE/airbnb/src/main/java/airbnb/domain/Amenity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,14 @@

import lombok.Getter;

@Getter
public enum Amenity {
KITCHEN("주방"),
HEATING("난방"),
AIR_CONDITIONING("에어컨"),
WASHER("세탁기"),
DRYER("건조기"),
WIFI("무선 인터넷"),
BREAKFAST("아침식사"),
INDOOR_FIREPLACE("실내 벽난로"),
IRON("다리미"),
HAIR_DRYER("헤어드라이어"),
DEDICATED_WORKSPACE("업무 전용 공간"),
TV("TV"),
CRIB("아기 침대"),
HIGH_CHAIR("유아용 식탁의자"),
SELF_CHECK_IN("셀프 체크인"),
SMOKE_ALARM("화재경보기"),
CARBON_MONOXIDE_ALARM("일산화탄소 경보기"),
PRIVATE_BATHROOM("욕실 단독 사용"),
BEACHFRONT("해변에 인접"),
WATERFROMNT("수변에 인접");
import javax.persistence.*;

private final String name;

Amenity(String name) {
this.name = name;
}
@Embeddable
@Getter
public class Amenity {
private boolean kitchen;
private boolean wifi;
private boolean airConditioning;
private boolean dryer;
}
51 changes: 51 additions & 0 deletions BE/airbnb/src/main/java/airbnb/domain/AmenityEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package airbnb.domain;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Getter
@RequiredArgsConstructor
public enum AmenityEnum {
KITCHEN("주방"),
HEATING("난방"),
AIR_CONDITIONING("에어컨"),
WASHER("세탁기"),
DRYER("건조기"),
WIFI("무선 인터넷"),
BREAKFAST("아침식사"),
INDOOR_FIREPLACE("실내 벽난로"),
IRON("다리미"),
HAIR_DRYER("헤어드라이어"),
DEDICATED_WORKSPACE("업무 전용 공간"),
TV("TV"),
CRIB("아기 침대"),
HIGH_CHAIR("유아용 식탁의자"),
SELF_CHECK_IN("셀프 체크인"),
SMOKE_ALARM("화재경보기"),
CARBON_MONOXIDE_ALARM("일산화탄소 경보기"),
PRIVATE_BATHROOM("욕실 단독 사용"),
BEACHFRONT("해변에 인접"),
WATERFRONT("수변에 인접");

private final String name;

public static List<String> getAmenityList(Amenity amenity) {
List<String> amenities = new ArrayList<>();
if (amenity.isKitchen()) {
amenities.add(WIFI.name);
}
if (amenity.isWifi()) {
amenities.add(WIFI.name);
}
if (amenity.isAirConditioning()) {
amenities.add(AIR_CONDITIONING.name);
}
if (amenity.isDryer()) {
amenities.add(DRYER.name);
}
return amenities;
}
}
18 changes: 11 additions & 7 deletions BE/airbnb/src/main/java/airbnb/domain/Booking.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package airbnb.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;

import javax.persistence.*;

import java.time.LocalDate;

import static javax.persistence.FetchType.LAZY;

@Entity
Expand All @@ -12,22 +15,23 @@
@AllArgsConstructor
@Builder
public class Booking {
@Id @GeneratedValue
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@JsonIgnore
@ManyToOne(fetch = LAZY)
@JoinColumn
private User user;

@JsonIgnore
@ManyToOne(fetch = LAZY)
@JoinColumn
private Room room;

int adults;
int children;
int infants;
@Embedded
private Guest guest;

int pricePerNight;
String checkInTime;
String checkOutTime;
private LocalDate checkIn;
private LocalDate checkOut;
}
11 changes: 10 additions & 1 deletion BE/airbnb/src/main/java/airbnb/domain/City.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package airbnb.domain;

import airbnb.response.CityResponse;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -17,7 +18,7 @@ public class City {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
protected String name;
private double driveTime;
private String image;

Expand All @@ -35,4 +36,12 @@ public String getProcessedDriveTime() {
}
return df.format(driveTime) + MINUTE.getName();
}

public static CityResponse of(City city) {
return CityResponse.builder()
.name(city.name)
.driveTime(city.getProcessedDriveTime())
.image(city.image)
.build();
}
}
20 changes: 20 additions & 0 deletions BE/airbnb/src/main/java/airbnb/domain/Guest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package airbnb.domain;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;

import javax.persistence.Embeddable;

@Embeddable
@NoArgsConstructor
@Getter
public class Guest {
private Integer adults;
private Integer children;
private Integer infants;

public int numberOfGuests() {
return adults + children + infants;
}
}
8 changes: 6 additions & 2 deletions BE/airbnb/src/main/java/airbnb/domain/Host.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package airbnb.domain;


import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor
public class Host {
@Id
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;
private String profileImage;
private int numberOfReviews;

@OneToMany(mappedBy = "host", cascade = CascadeType.ALL)
@JsonIgnore
@OneToMany(mappedBy = "host")
private List<Room> rooms = new ArrayList<>();
}
2 changes: 0 additions & 2 deletions BE/airbnb/src/main/java/airbnb/domain/Image.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package airbnb.domain;

import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Embeddable;

@Getter
@NoArgsConstructor
@Embeddable
public class Image {
private String image;
Expand Down
6 changes: 2 additions & 4 deletions BE/airbnb/src/main/java/airbnb/domain/Location.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package airbnb.domain;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;

import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -12,8 +11,7 @@
@NoArgsConstructor
@Getter
public class Location {
private String placeId;
private double latitude;
private double longitude;
private String city;
private String street;
}
8 changes: 4 additions & 4 deletions BE/airbnb/src/main/java/airbnb/domain/PropertyType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package airbnb.domain;

import com.querydsl.core.annotations.QueryProjection;
import lombok.Getter;

@Getter
public enum PropertyType {
HOUSE("주택"),
APARTMENT("아파트"),
Expand All @@ -14,8 +18,4 @@ public enum PropertyType {
PropertyType(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
Loading

0 comments on commit 683640a

Please sign in to comment.