Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public class ScheduledFlightNotificationDatabaseProvider {

private final ScheduledFlightNotificationRepository scheduledFlightNotificationRepository;

public boolean isNotificationSent(String flightId) {
return scheduledFlightNotificationRepository.existsByScheduledFlightId(flightId);
public boolean isNotificationSent(String flightId, UserEntity userEntity) {
return scheduledFlightNotificationRepository.existsByScheduledFlightIdAndUserId(
flightId, userEntity.getId());
}

public List<ScheduledFlightNotificationEntity> findActiveForEligibleUsers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public interface ScheduledFlightNotificationRepository
extends JpaRepository<ScheduledFlightNotificationEntity, UUID> {

boolean existsByScheduledFlightId(String scheduledFlightId);
boolean existsByScheduledFlightIdAndUserId(String scheduledFlightId, UUID userId);

@Query(
"""
Expand Down
12 changes: 10 additions & 2 deletions flightradar-api-lambdas/get_scheduled_flights_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,16 @@ def get_filtered_flights_for_airport(code: str, aircraft_filter_codes: list[str]
total_filtered_arrivals_count += len(raw_filtered_arrivals)
total_flights.extend([vars(ScheduledFlight.create_from_raw_flight(flight, converted_aircraft_images)) for flight in raw_filtered_arrivals])

seen = set()
unique_flights = []
for flight in total_flights:
key = (flight['row_id'], flight['scheduled_departure_time'])
if key not in seen:
seen.add(key)
unique_flights.append(flight)

return {
'arrivals_count': total_arrivals_count,
'filtered_arrivals_count': total_filtered_arrivals_count,
'flights': total_flights
'filtered_arrivals_count': len(unique_flights),
'flights': unique_flights
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ScheduledFlightsNotificationSender {
public void notifyScheduledFlights(UserEntity user, AirportResponse airportResponse) {
List<ScheduledFlight> scheduledFlights = airportResponse.getFlights();
List<ScheduledFlight> unnotifiedScheduledFlights =
getUnnotifiedScheduledFlights(scheduledFlights);
getUnnotifiedScheduledFlights(scheduledFlights, user);

if (unnotifiedScheduledFlights.isEmpty()) {
return;
Expand Down Expand Up @@ -167,13 +167,15 @@ private String buildScheduledFlightMessage(
getValueOrUnknown(formattedScheduledArrivalTime));
}

private List<ScheduledFlight> getUnnotifiedScheduledFlights(List<ScheduledFlight> flights) {
private List<ScheduledFlight> getUnnotifiedScheduledFlights(
List<ScheduledFlight> flights, UserEntity user) {
return flights.stream()
.filter(
flight ->
!scheduledFlightNotificationDatabaseProvider.isNotificationSent(
ScheduledFlightEntity.constructId(
flight.getRowId(), flight.getScheduledDepartureTime())))
flight.getRowId(), flight.getScheduledDepartureTime()),
user))
.toList();
}
}
Loading