1
0
Fork 0

baggage handling system implementation

main
Sebastian Steger 2026-04-21 09:49:30 +00:00
parent 89e3c3eab9
commit 5c1338301b
1 changed files with 26 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package airport package airport
import ( import (
"fmt"
"time" "time"
) )
@ -11,7 +12,7 @@ type BaggageProcessor interface {
type BaggageHandlingSystem struct { type BaggageHandlingSystem struct {
processingTime time.Duration processingTime time.Duration
sinks map[FlightNumber]BaggageProcessor sinks map[FlightNumber]BaggageProcessor
//TODO: extend lostBaggage chan LostBaggage
} }
type LostBaggage struct { type LostBaggage struct {
@ -26,19 +27,39 @@ func NewBaggageHandlingSystem(processingTime time.Duration, sinks map[FlightNumb
return BaggageHandlingSystem{ return BaggageHandlingSystem{
processingTime: processingTime, processingTime: processingTime,
sinks: sinks, sinks: sinks,
lostBaggage: make(chan LostBaggage),
} }
} }
func (bhs *BaggageHandlingSystem) ProcessBaggage(fn FlightNumber, b Baggage) error { func (bhs *BaggageHandlingSystem) ProcessBaggage(fn FlightNumber, b Baggage) error {
//TODO: implement sink, ok := bhs.sinks[fn]
if !ok {
return fmt.Errorf("invalid flight %v", fn)
}
go func() {
time.Sleep(bhs.processingTime)
if err := sink.ProcessBaggage(fn, b); err != nil {
bhs.lostBaggage <- LostBaggage{b, fn, err}
}
}()
return nil return nil
} }
func (bhs *BaggageHandlingSystem) CollectLostBaggage() []LostBaggage { func (bhs *BaggageHandlingSystem) CollectLostBaggage() []LostBaggage {
//TODO: implement lostBaggage := []LostBaggage{}
return nil for {
select {
case lb := <-bhs.lostBaggage:
lostBaggage = append(lostBaggage, lb)
default:
return lostBaggage
}
}
} }
func (bhs *BaggageHandlingSystem) Start() { func (bhs *BaggageHandlingSystem) Start() {
//TODO: implement
} }