You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
2.0 KiB
48 lines
2.0 KiB
package hs.fulda.de.ci.exam.project;
|
|
|
|
import java.io.IOException;
|
|
|
|
public class Admin extends Person{
|
|
|
|
AccountRepository accountRepository;
|
|
FlightRepository flightRepository;
|
|
AircraftRepository aircraftRepository;
|
|
public Admin(String name, Address address, String email, String phone) {
|
|
super(name, address, email, phone);
|
|
}
|
|
|
|
public Aircraft addAircraft(String name, String model, int manufacturerYear) throws IOException {
|
|
if(name.isBlank()) throw new RuntimeException("Name cannot be null or empty");
|
|
if(model.isBlank()) throw new RuntimeException("Model cannot be null or empty");
|
|
if(manufacturerYear < 0) throw new RuntimeException("Year cannot be zero");
|
|
Aircraft aircraft = new Aircraft(name, model, manufacturerYear);
|
|
aircraftRepository.save(aircraft);
|
|
return aircraft;
|
|
}
|
|
|
|
public String searchAircraft(String name){
|
|
String aircraftDetails = aircraftRepository.findAircraftByAircraftName(name);
|
|
if(aircraftDetails.isBlank()){
|
|
throw new RuntimeException("Aircraft does not exist.");
|
|
}
|
|
return aircraftDetails;
|
|
}
|
|
|
|
public Flight addFlight(String flightNumber, Airport departure, Airport arrival, int durationInMinutes ) throws IOException {
|
|
if(flightNumber.isBlank()) throw new RuntimeException("FlightNumber cannot be null or empty");
|
|
if(departure.equals(null)) throw new RuntimeException("Departure cannot be null or empty");
|
|
if(arrival.equals(null)) throw new RuntimeException("Arrival cannot be null or empty");
|
|
if(durationInMinutes < 0) throw new RuntimeException("Duration cannot be negative");
|
|
Flight flight = new Flight(flightNumber, departure, arrival, durationInMinutes );
|
|
flightRepository.save(flight);
|
|
return flight;
|
|
}
|
|
|
|
public boolean blockUser(Account user){
|
|
if(accountRepository.checkIfAccountAlreadyExist(user)){
|
|
user.setStatus(Account.AccountStatus.BLOCKED);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|