Skip to content

Commit

Permalink
feat: 숙박 일에 따른 숙소 예상 가격 계산 추가
Browse files Browse the repository at this point in the history
할인 정책이 여러개이므로 리스트에 저장해둠. 추후 Map이나 enum을 활용하는 등의 방법으로 리팩토링 생각해봐야할듯. 논리적으로는 list보다 set이 더 어울림. 가격정책이 세분화되면 인터페이스로 변경하는 식으로 추가해볼 수 있음.
인원 수에 따른 가격 계산 추가시켜야함.

Dae-Hwa/airbnb/#45
  • Loading branch information
Dae-Hwa committed May 31, 2021
1 parent bfa7ada commit fc737c2
Show file tree
Hide file tree
Showing 22 changed files with 456 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public List<AccommodationPriceStats> priceStats() {
}

@GetMapping("/accommodations/{id}/reservation")
public AccommodationReservationInfo reservationRequestInfo(@PathVariable long id, @RequestParam int nights) {
//TODO: nights로 박수 계산
return DummyDataFactory.accommodationReservationInfo();
public AccommodationReservationInfo reservationRequestInfo(@PathVariable long id, @Valid AccommodationRequest accommodationRequest) {
return accommodationService.accommodationReservationInfo(id, accommodationRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,20 @@ public static AccommodationDTO from(Accommodation accommodation) {
return builder().id(accommodation.getId())
.name(accommodation.getName())
.accommodationOption(accommodation.getAccommodationOption())
.totalPrice(accommodation.getTotalPrice())
.reviewRating(accommodation.getReviewRating())
.reviewCounts(accommodation.getReviewCounts())
.mainImage(accommodation.getMainImage())
.images(accommodation.getImages())
.description(accommodation.getDescription())
.accommodationHost(accommodation.getAccommodationHost())
.build();
}

public static AccommodationDTO from(Accommodation accommodation, int nights) {
return builder().id(accommodation.getId())
.name(accommodation.getName())
.accommodationOption(accommodation.getAccommodationOption())
.totalPrice(accommodation.totalPrice(nights))
.reviewRating(accommodation.getReviewRating())
.reviewCounts(accommodation.getReviewCounts())
.mainImage(accommodation.getMainImage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import java.util.Objects;

public class AccommodationRequest {
private static final int DEFAULT_NUMBER_OF_NIGHTS = 1;
private static final int DEFAULT_NUMBER_OF_ADULTS = 1;
private static final int DEFAULT_NUMBER_OF_CHILDREN = 0;
private static final int DEFAULT_NUMBER_OF_BABIES = 0;

@FutureOrPresent
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
Expand Down Expand Up @@ -39,9 +43,9 @@ public AccommodationRequest(LocalDate checkinDate, LocalDate checkoutDate, Integ
this.checkoutDate = checkoutDate;
this.startPrice = startPrice;
this.endPrice = endPrice;
this.numberOfAdults = numberOfAdults != null ? numberOfAdults : 1;
this.numberOfChildren = numberOfChildren != null ? numberOfChildren : 0;
this.numberOfBabies = numberOfBabies != null ? numberOfBabies : 0;
this.numberOfAdults = numberOfAdults != null ? numberOfAdults : DEFAULT_NUMBER_OF_ADULTS;
this.numberOfChildren = numberOfChildren != null ? numberOfChildren : DEFAULT_NUMBER_OF_CHILDREN;
this.numberOfBabies = numberOfBabies != null ? numberOfBabies : DEFAULT_NUMBER_OF_BABIES;
}

public static AccommodationRequestBuilder builder() {
Expand All @@ -50,7 +54,7 @@ public static AccommodationRequestBuilder builder() {

@AssertTrue(message = "체크인 날짜가 체크아웃 날짜 이전이어야 합니다.")
private boolean isCheckInDateBeforeCheckOutDate() {
if (checkinDate != null && checkoutDate != null) {
if (isCheckInDateAndCheckOutDateExists()) {
return checkinDate.isBefore(checkoutDate);
}

Expand All @@ -66,6 +70,18 @@ private boolean isStartPriceLessThanOrEqualToEndPrice() {
return true;
}

private boolean isCheckInDateAndCheckOutDateExists() {
return checkinDate != null && checkoutDate != null;
}

public int nights() {
if (isCheckInDateAndCheckOutDateExists()) {
return checkinDate.until(checkoutDate).getDays();
}

return DEFAULT_NUMBER_OF_NIGHTS;
}

public LocalDate getCheckinDate() {
return checkinDate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class AccommodationReservationInfo {
private Long id;
private int pricePerNight;
private int priceForNights;
private int salePrice;
private int cleaningPrice;
private int discountPrice;
private int cleaningFee;
private int serviceFee;
private int accommodationTax;
private int totalPrice;
Expand All @@ -18,27 +18,27 @@ public class AccommodationReservationInfo {
private AccommodationReservationInfo() {
}

protected AccommodationReservationInfo(Long id, int pricePerNight, int priceForNights, int salePrice, int cleaningPrice, int serviceFee, int accommodationTax, int totalPrice, int reviewCounts) {
protected AccommodationReservationInfo(Long id, int pricePerNight, int priceForNights, int discountPrice, int cleaningFee, int serviceFee, int accommodationTax, int totalPrice, int reviewCounts) {
this.id = id;
this.pricePerNight = pricePerNight;
this.priceForNights = priceForNights;
this.salePrice = salePrice;
this.cleaningPrice = cleaningPrice;
this.discountPrice = discountPrice;
this.cleaningFee = cleaningFee;
this.serviceFee = serviceFee;
this.accommodationTax = accommodationTax;
this.totalPrice = totalPrice;
this.reviewCounts = reviewCounts;
}

public static AccommodationReservationInfo from(Accommodation accommodation) {
public static AccommodationReservationInfo of(Accommodation accommodation, int nights) {
return builder().id(accommodation.getId())
.pricePerNight(accommodation.getAccommodationOption().getPricePerNight())
.priceForNights(accommodation.getPriceForNights())
.salePrice(accommodation.getSalePrice())
.cleaningPrice(accommodation.getCleaningPrice())
.serviceFee(accommodation.getServiceFee())
.accommodationTax(accommodation.getAccommodationTax())
.totalPrice(accommodation.getTotalPrice())
.priceForNights(accommodation.priceForNights(nights))
.discountPrice(accommodation.discountPrice(nights))
.cleaningFee(accommodation.cleaningFee(nights))
.serviceFee(accommodation.serviceFee(nights))
.accommodationTax(accommodation.accommodationTax(nights))
.totalPrice(accommodation.totalPrice(nights))
.reviewCounts(accommodation.getReviewCounts())
.build();
}
Expand All @@ -59,12 +59,12 @@ public int getPriceForNights() {
return priceForNights;
}

public int getSalePrice() {
return salePrice;
public int getDiscountPrice() {
return discountPrice;
}

public int getCleaningPrice() {
return cleaningPrice;
public int getCleaningFee() {
return cleaningFee;
}

public int getServiceFee() {
Expand All @@ -88,12 +88,12 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AccommodationReservationInfo that = (AccommodationReservationInfo) o;
return pricePerNight == that.pricePerNight && priceForNights == that.priceForNights && salePrice == that.salePrice && cleaningPrice == that.cleaningPrice && serviceFee == that.serviceFee && accommodationTax == that.accommodationTax && totalPrice == that.totalPrice && reviewCounts == that.reviewCounts && Objects.equals(id, that.id);
return pricePerNight == that.pricePerNight && priceForNights == that.priceForNights && discountPrice == that.discountPrice && cleaningFee == that.cleaningFee && serviceFee == that.serviceFee && accommodationTax == that.accommodationTax && totalPrice == that.totalPrice && reviewCounts == that.reviewCounts && Objects.equals(id, that.id);
}

@Override
public int hashCode() {
return Objects.hash(id, pricePerNight, priceForNights, salePrice, cleaningPrice, serviceFee, accommodationTax, totalPrice, reviewCounts);
return Objects.hash(id, pricePerNight, priceForNights, discountPrice, cleaningFee, serviceFee, accommodationTax, totalPrice, reviewCounts);
}

@Override
Expand All @@ -102,8 +102,8 @@ public String toString() {
"id=" + id +
", pricePerNight=" + pricePerNight +
", priceForNights=" + priceForNights +
", salePrice=" + salePrice +
", cleaningPrice=" + cleaningPrice +
", discountPrice=" + discountPrice +
", cleaningFee=" + cleaningFee +
", serviceFee=" + serviceFee +
", accommodationTax=" + accommodationTax +
", totalPrice=" + totalPrice +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ public final class AccommodationReservationInfoBuilder {
private Long id;
private int pricePerNight;
private int priceForNights;
private int salePrice;
private int cleaningPrice;
private int discountPrice;
private int cleaningFee;
private int serviceFee;
private int accommodationTax;
private int totalPrice;
Expand Down Expand Up @@ -33,13 +33,13 @@ public AccommodationReservationInfoBuilder priceForNights(int priceForNights) {
return this;
}

public AccommodationReservationInfoBuilder salePrice(int salePrice) {
this.salePrice = salePrice;
public AccommodationReservationInfoBuilder discountPrice(int discountPrice) {
this.discountPrice = discountPrice;
return this;
}

public AccommodationReservationInfoBuilder cleaningPrice(int cleaningPrice) {
this.cleaningPrice = cleaningPrice;
public AccommodationReservationInfoBuilder cleaningFee(int cleaningFee) {
this.cleaningFee = cleaningFee;
return this;
}

Expand All @@ -64,6 +64,6 @@ public AccommodationReservationInfoBuilder reviewCounts(int reviewCounts) {
}

public AccommodationReservationInfo build() {
return new AccommodationReservationInfo(id, pricePerNight, priceForNights, salePrice, cleaningPrice, serviceFee, accommodationTax, totalPrice, reviewCounts);
return new AccommodationReservationInfo(id, pricePerNight, priceForNights, discountPrice, cleaningFee, serviceFee, accommodationTax, totalPrice, reviewCounts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ public static AccommodationResponse from(Accommodation accommodation) {
return builder().id(accommodation.getId())
.name(accommodation.getName())
.accommodationOption(accommodation.getAccommodationOption())
.totalPrice(accommodation.getTotalPrice())
.reviewRating(accommodation.getReviewRating())
.reviewCounts(accommodation.getReviewCounts())
.mainImage(accommodation.getMainImage())
.build();
}

public static AccommodationResponse from(Accommodation accommodation, int nights) {
return builder().id(accommodation.getId())
.name(accommodation.getName())
.accommodationOption(accommodation.getAccommodationOption())
.totalPrice(accommodation.totalPrice(nights))
.reviewRating(accommodation.getReviewRating())
.reviewCounts(accommodation.getReviewCounts())
.mainImage(accommodation.getMainImage())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,63 @@
package com.codesquad.airbnb.accommodation.domain;

import com.codesquad.airbnb.accommodation.controller.AccommodationHost;
import com.codesquad.airbnb.accommodation.domain.price.Price;

import java.util.List;

public class Accommodation {
private Long id;
private String name;
private AccommodationOption accommodationOption;
private Integer totalPrice;
private double reviewRating;
private int reviewCounts;
private String mainImage;
private List<String> images;
private String description;
private AccommodationHost accommodationHost;
private int priceForNights;
private int salePrice;
private int cleaningPrice;
private int serviceFee;
private int accommodationTax;
private Price price;

protected Accommodation(Long id, String name, AccommodationOption accommodationOption, Integer totalPrice, double reviewRating, int reviewCounts, String mainImage, List<String> images, String description, AccommodationHost accommodationHost, int priceForNights, int salePrice, int cleaningPrice, int serviceFee, int accommodationTax) {
protected Accommodation(Long id, String name, AccommodationOption accommodationOption, double reviewRating, int reviewCounts, String mainImage, List<String> images, String description, AccommodationHost accommodationHost, Price price) {
this.id = id;
this.name = name;
this.accommodationOption = accommodationOption;
this.totalPrice = totalPrice;
this.reviewRating = reviewRating;
this.reviewCounts = reviewCounts;
this.mainImage = mainImage;
this.images = images;
this.description = description;
this.accommodationHost = accommodationHost;
this.priceForNights = priceForNights;
this.salePrice = salePrice;
this.cleaningPrice = cleaningPrice;
this.serviceFee = serviceFee;
this.accommodationTax = accommodationTax;
this.price = price;
}

public static AccommodationBuilder builder() {
return AccommodationBuilder.anAccommodation();
}

public int priceForNights(int nights) {
return price.priceForNights(nights);
}

public int discountPrice(int nights) {
return price.discountPrice(nights);
}

public int cleaningFee(int nights) {
return price.cleaningFee(nights);
}

public int serviceFee(int nights) {
return price.serviceFee(nights);
}

public int accommodationTax(int nights) {
return price.accommodationTax(nights);
}

public int totalPrice(int nights) {
return priceForNights(nights) - discountPrice(nights) + cleaningFee(nights) + serviceFee(nights) + accommodationTax(nights);
}

public Long getId() {
return id;
}
Expand All @@ -55,10 +70,6 @@ public AccommodationOption getAccommodationOption() {
return accommodationOption;
}

public Integer getTotalPrice() {
return totalPrice;
}

public double getReviewRating() {
return reviewRating;
}
Expand All @@ -82,24 +93,4 @@ public String getDescription() {
public AccommodationHost getAccommodationHost() {
return accommodationHost;
}

public int getPriceForNights() {
return priceForNights;
}

public int getSalePrice() {
return salePrice;
}

public int getCleaningPrice() {
return cleaningPrice;
}

public int getServiceFee() {
return serviceFee;
}

public int getAccommodationTax() {
return accommodationTax;
}
}
Loading

0 comments on commit fc737c2

Please sign in to comment.