Skip to content
Snippets Groups Projects
Commit 5d433864 authored by Martin Slovík's avatar Martin Slovík
Browse files

Adding update for Flight

parent a41e6275
No related branches found
No related tags found
No related merge requests found
......@@ -19,4 +19,6 @@ public interface FlightFacade<K> {
List<FlightDto> findAll();
void deleteById(K id);
FlightDto update(Long id, NewFlightDtoRequest newFlightDtoRequest);
}
......@@ -71,4 +71,15 @@ public class FlightFacadeImpl implements FlightFacade<Long> {
public void deleteById(Long id) {
flightService.deleteById(id);
}
@Override
public FlightDto update(Long id, NewFlightDtoRequest newFlightDtoRequest) {
var newFlightEntity = flightMapper.toEntityFromNewRequest(newFlightDtoRequest);
var updatedFlightEntity = flightService.update(id, newFlightEntity);
var flightDto = flightMapper.toDto(updatedFlightEntity);
flightDto.setStewards(mapStewardDtos(updatedFlightEntity));
return flightDto;
}
}
......@@ -86,6 +86,6 @@ public class FlightController implements FlightApiDelegate {
*/
@Override
public ResponseEntity<FlightDto> updateFlight(Long id, NewFlightDtoRequest newFlightDtoRequest) {
return FlightApiDelegate.super.updateFlight(id, newFlightDtoRequest);
return ResponseEntity.ok(flightFacade.update(id, newFlightDtoRequest));
}
}
......@@ -8,4 +8,6 @@ import java.util.Optional;
public interface FlightService extends BaseService<Flight, Long> {
Optional<Flight> findByIdWithStewards(Long id);
Flight update(Long id, Flight newFlight);
}
......@@ -2,6 +2,7 @@ package cz.muni.fi.pa165.core.service.flight;
import cz.muni.fi.pa165.core.data.domain.Flight;
import cz.muni.fi.pa165.core.data.repository.flight.FlightRepository;
import cz.muni.fi.pa165.core.exceptions.ResourceNotFoundException;
import cz.muni.fi.pa165.core.service.common.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -23,4 +24,15 @@ public class FlightServiceImpl extends BaseServiceImpl<Flight, Long> implements
public Optional<Flight> findByIdWithStewards(Long id) {
return flightRepository.findByIdWithStewards(id);
}
@Override
public Flight update(Long id, Flight newFlight) {
var entityToUpdate = flightRepository.findById(id)
.orElseThrow(() -> new ResourceNotFoundException("Not Found."));
entityToUpdate.setDepartureTime(newFlight.getDepartureTime());
entityToUpdate.setArrivalTime(newFlight.getArrivalTime());
return flightRepository.save(entityToUpdate);
}
}
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