Browse Source

refactor Person

feature-pr-PersonAndItinerary
Sona Markosyan 3 years ago
parent
commit
6ab9545d1a
  1. 8
      src/main/java/hs/fulda/de/ci/exam/project/Admin.java
  2. 4
      src/main/java/hs/fulda/de/ci/exam/project/Customer.java
  3. 15
      src/main/java/hs/fulda/de/ci/exam/project/Person.java

8
src/main/java/hs/fulda/de/ci/exam/project/Admin.java

@ -28,14 +28,6 @@ public class Admin extends Person{
return aircraftDetails; return aircraftDetails;
} }
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 { 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(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(departure.equals(null)) throw new RuntimeException("Departure cannot be null or empty");

4
src/main/java/hs/fulda/de/ci/exam/project/Customer.java

@ -6,7 +6,6 @@ import java.util.ArrayList;
public class Customer extends Person{ public class Customer extends Person{
private String frequentFlyerNumber; private String frequentFlyerNumber;
private ItineraryRepository itineraryRepository;
@ -22,7 +21,4 @@ public class Customer extends Person{
return frequentFlyerNumber; return frequentFlyerNumber;
} }
public ArrayList<Itinerary> getItineraries() {
return itineraryRepository.findAll();
}
} }

15
src/main/java/hs/fulda/de/ci/exam/project/Person.java

@ -1,5 +1,6 @@
package hs.fulda.de.ci.exam.project; package hs.fulda.de.ci.exam.project;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -9,6 +10,8 @@ public class Person {
private Address address; private Address address;
private String email; private String email;
private String phone; private String phone;
private FlightRepository flightRepository;
private ItineraryRepository itineraryRepository;
public Person(String name, Address address, String email, String phone) { public Person(String name, Address address, String email, String phone) {
this.name = name; this.name = name;
@ -67,4 +70,16 @@ public class Person {
throw new RuntimeException("Phone Number should start with 0"); throw new RuntimeException("Phone Number should start with 0");
} }
} }
public String searchFlights(String flightNumber){
String flightDetails = flightRepository.findFlightByFlightNumber(flightNumber);
if(flightDetails.isBlank()){
throw new RuntimeException("Flight does not exist.");
}
return flightDetails;
}
public ArrayList<Itinerary> getItineraries() {
return itineraryRepository.findAll();
}
} }
Loading…
Cancel
Save