From 6ab9545d1a90f5c3804da93c03e6297aa8b06deb Mon Sep 17 00:00:00 2001 From: Sona Markosyan Date: Thu, 17 Feb 2022 15:47:15 +0100 Subject: [PATCH] refactor Person --- .../java/hs/fulda/de/ci/exam/project/Admin.java | 8 -------- .../hs/fulda/de/ci/exam/project/Customer.java | 4 ---- .../java/hs/fulda/de/ci/exam/project/Person.java | 15 +++++++++++++++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Admin.java b/src/main/java/hs/fulda/de/ci/exam/project/Admin.java index ce8cb1e..236cd83 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Admin.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/Admin.java @@ -28,14 +28,6 @@ public class Admin extends Person{ 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 { 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"); diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Customer.java b/src/main/java/hs/fulda/de/ci/exam/project/Customer.java index 4d8491f..a092797 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Customer.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/Customer.java @@ -6,7 +6,6 @@ import java.util.ArrayList; public class Customer extends Person{ private String frequentFlyerNumber; - private ItineraryRepository itineraryRepository; @@ -22,7 +21,4 @@ public class Customer extends Person{ return frequentFlyerNumber; } - public ArrayList getItineraries() { - return itineraryRepository.findAll(); - } } diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Person.java b/src/main/java/hs/fulda/de/ci/exam/project/Person.java index f8aad64..31d72dd 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Person.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/Person.java @@ -1,5 +1,6 @@ package hs.fulda.de.ci.exam.project; +import java.util.ArrayList; import java.util.HashSet; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -9,6 +10,8 @@ public class Person { private Address address; private String email; private String phone; + private FlightRepository flightRepository; + private ItineraryRepository itineraryRepository; public Person(String name, Address address, String email, String phone) { this.name = name; @@ -67,4 +70,16 @@ public class Person { 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 getItineraries() { + return itineraryRepository.findAll(); + } }