mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-16 20:59:07 +00:00
This commit is contained in:
@@ -1,15 +1,41 @@
|
||||
package com.ashishtrivedi16.transactionscript;
|
||||
|
||||
public class Hotel {
|
||||
import com.ashishtrivedi16.transactionscript.db.HotelDAOImpl;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public void bookRoom(int roomNumber) {
|
||||
import java.util.Optional;
|
||||
|
||||
public class Hotel {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TransactionScriptApp.class);
|
||||
|
||||
private HotelDAOImpl hotelDAO;
|
||||
|
||||
public Hotel(HotelDAOImpl hotelDAO) {
|
||||
this.hotelDAO = hotelDAO;
|
||||
}
|
||||
|
||||
public void bookRoom(int roomNumber) throws Exception {
|
||||
/*
|
||||
TODO
|
||||
-> Check if room is available
|
||||
-> Calculate price
|
||||
-> Book the room
|
||||
-> Commit transaction
|
||||
*/
|
||||
|
||||
Optional<Room> room = hotelDAO.getById(roomNumber);
|
||||
|
||||
if (!room.isPresent()) {
|
||||
LOGGER.info(roomNumber + " does not exist");
|
||||
} else {
|
||||
if (room.get().isBooked()) {
|
||||
LOGGER.info("Room already booked!");
|
||||
} else {
|
||||
Room updateRoomBooking = room.get();
|
||||
updateRoomBooking.setBooked(true);
|
||||
hotelDAO.update(updateRoomBooking);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void cancelRoomBooking(int roomNumber) {
|
||||
|
||||
Reference in New Issue
Block a user