예제 #1
0
  @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;
  }
예제 #2
0
  @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;
  }
예제 #3
0
 public void save(Apartment apartment) {
   try {
     Connection conn = DBUtils.getConnection();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   SortOfDataBase.apartments.put(apartment.getId(), apartment);
 }
예제 #4
0
 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));
 }
예제 #5
0
  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;
  }