-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
BE/airbnb/src/main/java/airbnb/controller/BookingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package airbnb.controller; | ||
|
||
import airbnb.domain.Booking; | ||
import airbnb.domain.Image; | ||
import airbnb.domain.Room; | ||
import airbnb.domain.User; | ||
import airbnb.request.BookingRequest; | ||
import airbnb.response.BookingResponse; | ||
import airbnb.service.BookingService; | ||
import airbnb.service.RoomService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api") | ||
public class BookingController { | ||
private final RoomService roomService; | ||
private final BookingService bookingService; | ||
|
||
@PostMapping("/book/rooms/{roomId}") | ||
public ResponseEntity<BookingResponse> reserve(@PathVariable Long roomId, @RequestBody BookingRequest reservationInfo) { | ||
User user = new User(); | ||
Room room = roomService.findRoomById(roomId); | ||
BookingResponse bookingResponse = bookingService.reserve(user, room, reservationInfo); | ||
return ResponseEntity.ok(bookingResponse); | ||
} | ||
|
||
@DeleteMapping("/cancel/rooms/{roomId}") | ||
public ResponseEntity<String> cancel() { | ||
return new ResponseEntity<>("예약이 성공적으로 취소되었습니다.", HttpStatus.OK); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
BE/airbnb/src/main/java/airbnb/request/BookingRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package airbnb.request; | ||
|
||
import airbnb.domain.Guest; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BookingRequest { | ||
private String checkIn; | ||
private String checkOut; | ||
private int adults; | ||
private int children; | ||
private int infants; | ||
private int totalPrice; | ||
|
||
public static Guest createGuest(BookingRequest bookingRequest) { | ||
return Guest.builder() | ||
.adults(bookingRequest.adults) | ||
.children(bookingRequest.children) | ||
.infants(bookingRequest.infants) | ||
.build(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
BE/airbnb/src/main/java/airbnb/response/BookingResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package airbnb.response; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
public class BookingResponse { | ||
private final String name; | ||
private final List<String> roomImages; | ||
private final String place; | ||
private final String host; | ||
private final LocalDateTime checkIn; | ||
private final LocalDateTime checkOut; | ||
private final int numberOfGuests; | ||
private final int totalPrice; | ||
} |
22 changes: 22 additions & 0 deletions
22
BE/airbnb/src/main/java/airbnb/service/BookingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package airbnb.service; | ||
|
||
import airbnb.domain.Booking; | ||
import airbnb.domain.Room; | ||
import airbnb.domain.User; | ||
import airbnb.repository.BookingRepository; | ||
import airbnb.request.BookingRequest; | ||
import airbnb.response.BookingResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BookingService { | ||
private final BookingRepository bookingRepository; | ||
|
||
public BookingResponse reserve(User user, Room room, BookingRequest reservationInfo) { | ||
Booking booking = Room.createBooking(user, room, reservationInfo); | ||
bookingRepository.save(booking); | ||
return Booking.createBookingResponse(booking); | ||
} | ||
} |