Skip to content

Commit

Permalink
issue resolved: favorite flights appear to all
Browse files Browse the repository at this point in the history
issue resolved: favorite flights doesn't belong to user appears in his account

Co-Authored-By: imane_quabbou <103893606+imane12j@users.noreply.github.com>
  • Loading branch information
youssef-amazzal and imane12j committed Aug 31, 2022
1 parent 782b9cd commit 66853af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions FlightBookingApplication/src/main/java/data/FavoriteDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,31 @@ public List<Favorite> readAll() {
}
}

public List<Favorite> readAll(Account account) {
Connection conn = DataSource.getConnection();
List<Favorite> list = new ArrayList<>();

try {
PreparedStatement query = conn.prepareStatement("SELECT * FROM favorites WHERE id_account = ?;");
query.setInt(1, account.getId());
ResultSet res = query.executeQuery();

while (res.next()) {
Favorite favorite = new Favorite();
favorite.setId(res.getInt("id"));
favorite.setFlight(flightDao.read(res.getInt("id_flight")));
favorite.setAccount((res.getInt("id_account")));

list.add(favorite);
favoritesMap.put(res.getInt("id_flight"), favorite);
}
return list;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}

@Override
public void update(int id, Favorite favorite) {
Connection conn = DataSource.getConnection();
Expand Down
2 changes: 1 addition & 1 deletion FlightBookingApplication/src/main/java/models/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Reservation getReservation(Flight flight) {

public ObservableList<Flight> getFavoriteFlights() {
FavoriteDao favoriteDao = new FavoriteDao();
List<Favorite> favoriteList = favoriteDao.readAll();
List<Favorite> favoriteList = favoriteDao.readAll(this);
List<Flight> favoriteFlights = new ArrayList<>();
favoriteList.forEach(favorite -> favoriteFlights.add(favorite.getFlight()));
return FXCollections.observableList(favoriteFlights);
Expand Down

0 comments on commit 66853af

Please sign in to comment.