diff --git a/go/06-airport/airport/baggageHandlingSystem.go b/go/06-airport/airport/baggageHandlingSystem.go index 9c81002..e800172 100644 --- a/go/06-airport/airport/baggageHandlingSystem.go +++ b/go/06-airport/airport/baggageHandlingSystem.go @@ -2,6 +2,8 @@ package airport import ( "time" + + "gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport" ) type BaggageProcessor interface { @@ -12,6 +14,7 @@ type BaggageHandlingSystem struct { processingTime time.Duration sinks map[FlightNumber]BaggageProcessor //TODO: extend + baggae airport.Baggage } type LostBaggage struct { diff --git a/go/06-airport/airport/baggageHandlingSystem_test.go b/go/06-airport/airport/baggageHandlingSystem_test.go index 673ef56..e198976 100644 --- a/go/06-airport/airport/baggageHandlingSystem_test.go +++ b/go/06-airport/airport/baggageHandlingSystem_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "gitty.informatik.hs-mannheim.de/steger/pr3-code/go/06-airport/airport" + "gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport" ) type BaggageSpyData struct { diff --git a/go/06-airport/airport/checkin_test.go b/go/06-airport/airport/checkin_test.go index 2c3488a..9f5cd2d 100644 --- a/go/06-airport/airport/checkin_test.go +++ b/go/06-airport/airport/checkin_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "gitty.informatik.hs-mannheim.de/steger/pr3-code/go/06-airport/airport" + "gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport" ) type FlightProviderStub struct { diff --git a/go/06-airport/airport/gate_test.go b/go/06-airport/airport/gate_test.go index 0e8f626..03eed5c 100644 --- a/go/06-airport/airport/gate_test.go +++ b/go/06-airport/airport/gate_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "gitty.informatik.hs-mannheim.de/steger/pr3-code/go/06-airport/airport" + "gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport" ) func TestGateSingleFlight(t *testing.T) { diff --git a/go/06-airport/airport/securityCheck.go b/go/06-airport/airport/securityCheck.go index 85ff4ad..e86c904 100644 --- a/go/06-airport/airport/securityCheck.go +++ b/go/06-airport/airport/securityCheck.go @@ -1,6 +1,7 @@ package airport import ( + "fmt" "time" ) @@ -9,17 +10,57 @@ var prohibitedItems = map[string]bool{"Knife": true, "Gun": true, "Explosives": type SecurityCheck struct { processingTime time.Duration //TODO: extend + queue chan passengerSecurityCheck +} + +type passengerSecurityCheck struct { + p *Passenger + err chan error } func NewSecurityCheck(processingTime time.Duration) SecurityCheck { return SecurityCheck{ processingTime: processingTime, + queue: make(chan passengerSecurityCheck), } } +func findProhibitedItem(items []string) (string, bool) { + for _, item := range items { + if prohibitedItems[item] { + return item, true + } + } + return "", false +} + // processes one passenger at a time. Each passenger must at least spend the processingTime at the security check func (sc *SecurityCheck) Start() { - //TODO: implement + for element := range sc.queue { + + time.Sleep(sc.processingTime) + + // Passagier hat keinen Boarding Pass (muss vor dem Namensvergleich kommen) + if element.p.BoardingPass == nil { + element.err <- fmt.Errorf("%s has no boarding pass", element.p.Name) + continue + } + + // Name stimmt nicht mit dem Boarding Pass überein + if element.p.Name != element.p.BoardingPass.Name { + element.err <- fmt.Errorf("name %s does not match boarding pass name %s", element.p.Name, element.p.BoardingPass.Name) + continue + } + + // Verbotener Gegenstand im Handgepäck + if item, found := findProhibitedItem(element.p.CarryOnItems); found { + element.err <- fmt.Errorf("%s carries prohibited item %s", element.p.Name, item) + continue + } + + // Alles in Ordnung + element.err <- nil + } } // returns an error if @@ -27,6 +68,7 @@ func (sc *SecurityCheck) Start() { // - the passenger's boardings pass does not match the name // - the passenger carries a prohibited item func (sc SecurityCheck) Process(p Passenger) error { - //TODO: implement - return nil + err := make(chan error) + sc.queue <- passengerSecurityCheck{p: &p, err: err} + return <-err } diff --git a/go/06-airport/airport/securityCheck_test.go b/go/06-airport/airport/securityCheck_test.go index 31b8029..f60d044 100644 --- a/go/06-airport/airport/securityCheck_test.go +++ b/go/06-airport/airport/securityCheck_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "gitty.informatik.hs-mannheim.de/steger/pr3-code/go/06-airport/airport" + "gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport" ) func TestSecurityCheck(t *testing.T) { diff --git a/go/06-airport/go.mod b/go/06-airport/go.mod index 970693f..0e3e87d 100644 --- a/go/06-airport/go.mod +++ b/go/06-airport/go.mod @@ -1,4 +1,4 @@ -module gitty.informatik.hs-mannheim.de/steger/pr3-code/go/06-airport +module gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport go 1.25.0 diff --git a/go/06-airport/main.go b/go/06-airport/main.go index 39d0587..4760dce 100644 --- a/go/06-airport/main.go +++ b/go/06-airport/main.go @@ -6,7 +6,7 @@ import ( "os" "strings" - "gitty.informatik.hs-mannheim.de/steger/pr3-code/go/06-airport/airport" + "gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport" ) func main() {