Skip to content
Snippets Groups Projects
Verified Commit da555a14 authored by Adam Krídl's avatar Adam Krídl
Browse files

Implement assignments of departing flight

parent f62ac02d
No related branches found
No related tags found
No related merge requests found
......@@ -50,6 +50,14 @@ public class Airport extends DomainEntity {
arrivingFlights.remove(arrivingFlight);
}
public void addDepartingFlight(Flight departingFlight) {
departingFlights.add(departingFlight);
}
public void removeDepartingFlight(Flight departingFlight) {
departingFlights.remove(departingFlight);
}
@Override
public boolean equals(Object o) {
if (this == o) {
......
......@@ -134,12 +134,34 @@ public class AirportFacadeImpl implements AirportFacade<Long> {
@Override
public AirportDto addDepartingFlightAssignment(Long airportId, Long flightId) {
return null;
Airport airport = airportService.findById(airportId)
.orElseThrow(ResourceNotFoundException::new);
Flight flight = flightService.findById(flightId)
.orElseThrow(ResourceNotFoundException::new);
airport.addDepartingFlight(flight);
flight.setDepartingAirport(airport);
Airport updatedAirport = airportService.update(airportId, airport);
flightService.update(flightId, flight);
return airportMapper.toDto(updatedAirport);
}
@Override
public AirportDto deleteDepartingFlightAssignment(Long airportId, Long flightId) {
return null;
Airport airport = airportService.findById(airportId)
.orElseThrow(ResourceNotFoundException::new);
Flight flight = flightService.findById(flightId)
.orElseThrow(ResourceNotFoundException::new);
airport.removeDepartingFlight(flight);
flight.setDepartingAirport(null);
Airport updatedAirport = airportService.update(airportId, airport);
flightService.update(flightId, flight);
return airportMapper.toDto(updatedAirport);
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment