@Override public List<Apartment> getAllByUser(int id) { List<Apartment> list = new LinkedList<>(); for (Apartment apartment : SortOfDataBase.apartments.values()) { if (apartment.getHost().getId() == id) { list.add(apartment); } } return list; }
@Override public List<Apartment> getByCity(String city) { List<Apartment> list = new LinkedList<>(); for (Apartment apartment : SortOfDataBase.apartments.values()) { if (apartment.getCity().equals(city)) { list.add(apartment); } } return list; }
public void save(Apartment apartment) { try { Connection conn = DBUtils.getConnection(); } catch (SQLException e) { e.printStackTrace(); } SortOfDataBase.apartments.put(apartment.getId(), apartment); }
private void logReservationRejected( User user, Apartment apartment, Date start, Date end, String message) { SimpleDateFormat format = new SimpleDateFormat("dd.MM.yy"); log.info( Joiner.on("") .join( "Reservation rejected: UserID='", user.getId(), "', apartmentID='", apartment.getId(), "', start='", format.format(start), "', end='", format.format(end), "' | Reason - ", message)); }
public boolean makeReservation( User user, Apartment apartment, Date start, Date end, String comment) { if (end.before(start)) { if (log.isInfoEnabled()) { logReservationRejected(user, apartment, start, end, "Invalid date"); } return false; } if (isAvailable(apartment, start, end)) { if (log.isInfoEnabled()) { SimpleDateFormat format = new SimpleDateFormat("dd.MM.yy"); log.info( Joiner.on("") .join( "Reservation accepted: UserID='", user.getId(), "', apartmentID='", apartment.getId(), "', start='", format.format(start), "', end='", format.format(end), "'")); } Reservation reservation = new Reservation(user, apartment, start, end, comment); SortOfDataBase.reservations.put(reservation.getId(), reservation); return true; } if (log.isInfoEnabled()) { logReservationRejected( user, apartment, start, end, "Apartment is unavailable for this dates"); } return false; }