Skip to content

Commit

Permalink
[BE] feat : 예약하는 기능 구현 시작
Browse files Browse the repository at this point in the history
- reservation service 분리
- reservation dto, dao 분리
- 일차적으로 cookie에서 user 정보값을 가져온다고 생각하고 controller에서 @cookievalue를 활용, default값을 none으로 하였습니다.
- reservation service에서 properties_id, checkin, checkout,name을 받아서
  해당 properties에 대한 예약을 진행하고자 합니다.

issue : #10

-------------------------
-------------------------
  • Loading branch information
haveagood committed May 28, 2020
1 parent 05afadc commit 754cdcd
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 263 deletions.
186 changes: 0 additions & 186 deletions be/out/production/resources/data/images.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4918,189 +4918,3 @@ https://airbnb-codesquad.s3.ap-northeast-2.amazonaws.com/7.jpg,615
https://airbnb-codesquad.s3.ap-northeast-2.amazonaws.com/8.jpg,615
https://airbnb-codesquad.s3.ap-northeast-2.amazonaws.com/9.jpg,615
https://airbnb-codesquad.s3.ap-northeast-2.amazonaws.com/10.jpg,615
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ public class CommonStaticsProperties {
public static final Double DEFAULT_MAX_LATITUDE = 47.72741971;
public static final Double DEFAULT_MIN_LONGITUDE = -122.4129798;
public static final Double DEFAULT_MAX_LONGITUDE = -122.2604426;

// 손님 기본값 세팅
public static final Integer DEFAULT_GUESTS_NUM = 1;
//-----------------------------------------------------------------------------
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import com.airbnb3.codesquad.airbnb3.dto.DetailDtoAlex;
import com.airbnb3.codesquad.airbnb3.dto.PropertiesDtoAlex;
import com.airbnb3.codesquad.airbnb3.service.AirBnbService;
import com.airbnb3.codesquad.airbnb3.service.ReservationServiceAlex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

Expand All @@ -20,6 +23,9 @@ public class AirBnbControllerAlex {
@Autowired
private AirBnbService airBnbService;

@Autowired
private ReservationServiceAlex reservationService;

@GetMapping("/properties")
public ResponseEntity<List<PropertiesDtoAlex>> stayedPage(
@RequestParam(value = "offset", required = false, defaultValue = "1") String pageNum,
Expand Down Expand Up @@ -47,9 +53,10 @@ public ResponseEntity<DetailDtoAlex> detailPage(@PathVariable("id") Long id) {
public ResponseEntity<Object> bookingRequest(@PathVariable("id") Long id,
@RequestParam(value = "checkin") String checkIn,
@RequestParam(value = "checkout") String checkOut,
@RequestParam(value = "guests") String guests
@RequestParam(value = "guests") String guests,
@CookieValue(value = "name", defaultValue = "None", required = false) String name
) {

reservationService.propertyReservation(id,checkIn,checkOut,guests,name);
return new ResponseEntity<>("TEST", HttpStatus.OK);
}
}
120 changes: 78 additions & 42 deletions be/src/main/java/com/airbnb3/codesquad/airbnb3/dao/DetailDaoAlex.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.Arrays;

Expand All @@ -34,48 +37,81 @@ public DetailDtoAlex getDetailProperties(Long id) {
.reservable(rs.getBoolean("reservable"))
.saved(rs.getBoolean("saved"))
.images(Arrays.asList(rs.getString("image").split(",")))
.hostInfo(HostDto.builder()
.hostAbout(rs.getString("host_about"))
.hostLocation(rs.getString("host_location"))
.hostName(rs.getString("host_name"))
.hostSince(rs.getString("host_since"))
.isSuperHost(rs.getBoolean("is_super_host"))
.notes(rs.getString("notes"))
.build())
.locationInfo(LocationDto.builder()
.address(rs.getString("address"))
.cityOverView(rs.getString("city_overview"))
.latitude(rs.getDouble("latitude"))
.longitude(rs.getDouble("longitude"))
.transit(rs.getString("transit"))
.build())
.priceInfo(PriceDto.builder()
.cleaningFee(rs.getDouble("cleaning_fee"))
.price(rs.getDouble("price"))
.serviceFee(rs.getDouble("service_fee"))
.tax(rs.getDouble("tax"))
.build())
.reviewInfo(ReviewDto.builder()
.reviewAverage(rs.getDouble("review_average"))
.numberOfReviews(rs.getInt("number_of_reviews"))
.reviewScoresAccuracy(rs.getDouble("review_scores_accuracy"))
.reviewScoresCheckin(rs.getDouble("review_scores_checkin"))
.reviewScoresCleanliness(rs.getDouble("review_scores_cleanliness"))
.reviewScoresCommunication(rs.getDouble("review_scores_communication"))
.reviewScoresLocation(rs.getDouble("review_scores_location"))
.reviewScoresValue(rs.getDouble("review_scores_value"))
.build())
.roomInfo(RoomDto.builder()
.accommodates(rs.getInt("accommodates"))
.amenities(rs.getString("amenity"))
.bathrooms(rs.getInt("bathrooms"))
.bedrooms(rs.getInt("bedrooms"))
.beds(rs.getInt("beds"))
.bedType(rs.getString("bed_type"))
.placeType(rs.getString("place_type"))
.space(rs.getString("space"))
.summary(rs.getString("summary"))
.build())
.hostInfo(hostDtoBuilder(rs))
.locationInfo(locationDtoBuilder(rs))
.priceInfo(priceDtoBuilder(rs))
.reviewInfo(reviewDtoBuilder(rs))
.roomInfo(roomDtoBuilder(rs))
.build());
}

public PriceDto getPrices(Long id) {
String sql = "SELECT d.cleaning_fee,d.service_fee,d.tax,p.price FROM detail d LEFT JOIN properties p ON d.id = p.id WHERE p.id = :id";
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
parameterSource.addValue("id", id);
return jdbcTemplate.queryForObject(sql, parameterSource, ((rs, rowNum) ->
PriceDto.builder()
.cleaningFee(rs.getDouble("cleaning_fee"))
.price(rs.getDouble("price"))
.serviceFee(rs.getDouble("service_fee"))
.tax(rs.getDouble("tax"))
.build()));
}

private RoomDto roomDtoBuilder(ResultSet rs) throws SQLException {
return RoomDto.builder()
.accommodates(rs.getInt("accommodates"))
.amenities(rs.getString("amenity"))
.bathrooms(rs.getInt("bathrooms"))
.bedrooms(rs.getInt("bedrooms"))
.beds(rs.getInt("beds"))
.bedType(rs.getString("bed_type"))
.placeType(rs.getString("place_type"))
.space(rs.getString("space"))
.summary(rs.getString("summary"))
.build();
}

private ReviewDto reviewDtoBuilder(ResultSet rs) throws SQLException {
return ReviewDto.builder()
.reviewAverage(rs.getDouble("review_average"))
.numberOfReviews(rs.getInt("number_of_reviews"))
.reviewScoresAccuracy(rs.getDouble("review_scores_accuracy"))
.reviewScoresCheckin(rs.getDouble("review_scores_checkin"))
.reviewScoresCleanliness(rs.getDouble("review_scores_cleanliness"))
.reviewScoresCommunication(rs.getDouble("review_scores_communication"))
.reviewScoresLocation(rs.getDouble("review_scores_location"))
.reviewScoresValue(rs.getDouble("review_scores_value"))
.build();
}

private PriceDto priceDtoBuilder(ResultSet rs) throws SQLException {
return PriceDto.builder()
.cleaningFee(rs.getDouble("cleaning_fee"))
.price(rs.getDouble("price"))
.serviceFee(rs.getDouble("service_fee"))
.tax(rs.getDouble("tax"))
.build();
}

private LocationDto locationDtoBuilder(ResultSet rs) throws SQLException {
return LocationDto.builder()
.address(rs.getString("address"))
.cityOverView(rs.getString("city_overview"))
.latitude(rs.getDouble("latitude"))
.longitude(rs.getDouble("longitude"))
.transit(rs.getString("transit"))
.build();
}

private HostDto hostDtoBuilder(ResultSet rs) throws SQLException {
return HostDto.builder()
.hostAbout(rs.getString("host_about"))
.hostLocation(rs.getString("host_location"))
.hostName(rs.getString("host_name"))
.hostSince(rs.getString("host_since"))
.isSuperHost(rs.getBoolean("is_super_host"))
.notes(rs.getString("notes"))
.build();
}
}
Loading

0 comments on commit 754cdcd

Please sign in to comment.