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.
42 lines
1.5 KiB
42 lines
1.5 KiB
package hs.fulda.de.ci.exam.project;
|
|
|
|
import java.io.IOException;
|
|
|
|
public class Admin extends Person{
|
|
|
|
AccountRepository accountRepository;
|
|
FlightRepository flightRepository;
|
|
public Admin(String name, Address address, String email, String phone) {
|
|
super(name, address, email, phone);
|
|
}
|
|
|
|
public void addAircraft(){
|
|
|
|
}
|
|
|
|
public String searchFlights(String flightNumber){
|
|
String flightDetails = flightRepository.findFlightByFlightNumber(flightNumber);
|
|
if(flightDetails.isBlank()){
|
|
throw new RuntimeException("Flight does not exist.");
|
|
}
|
|
return flightDetails;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|