2020-07-19 16:51:16 +05:30
|
|
|
package com.ashishtrivedi16.transactionscript;
|
|
|
|
|
2020-07-19 22:20:15 +05:30
|
|
|
import com.ashishtrivedi16.transactionscript.db.HotelDAOImpl;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
2020-07-19 16:51:16 +05:30
|
|
|
public class Hotel {
|
2020-07-19 22:20:15 +05:30
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(TransactionScriptApp.class);
|
2020-07-19 16:51:16 +05:30
|
|
|
|
2020-07-19 22:20:15 +05:30
|
|
|
private HotelDAOImpl hotelDAO;
|
|
|
|
|
|
|
|
public Hotel(HotelDAOImpl hotelDAO) {
|
|
|
|
this.hotelDAO = hotelDAO;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void bookRoom(int roomNumber) throws Exception {
|
2020-07-19 16:51:16 +05:30
|
|
|
/*
|
2020-07-19 20:33:52 +05:30
|
|
|
TODO
|
|
|
|
-> Check if room is available
|
|
|
|
-> Book the room
|
|
|
|
-> Commit transaction
|
2020-07-19 16:51:16 +05:30
|
|
|
*/
|
2020-07-19 22:20:15 +05:30
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2020-07-19 16:51:16 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
public void cancelRoomBooking(int roomNumber) {
|
|
|
|
/*
|
2020-07-19 20:33:52 +05:30
|
|
|
|
2020-07-19 16:51:16 +05:30
|
|
|
TODO
|
2020-07-19 20:33:52 +05:30
|
|
|
-> Check if room is booked
|
|
|
|
-> Calculate refund price
|
|
|
|
-> Cancel the room booking
|
|
|
|
-> Commit transaction
|
2020-07-19 16:51:16 +05:30
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|