Filter vehicle administrators

This commit is contained in:
Arnaud Delcasse 2023-03-10 15:44:46 +01:00
parent 91991789db
commit feb935f8bf
3 changed files with 25 additions and 4 deletions

View File

@ -56,6 +56,7 @@ func (s FleetsServerImpl) GetVehicle(ctx context.Context, req *GetVehicleRequest
func (s FleetsServerImpl) GetVehicles(ctx context.Context, req *GetVehiclesRequest) (*GetVehiclesResponse, error) {
filter := storage.VehicleFilters{
Types: req.Types,
Administrators: req.Administrators,
}
if req.AvailabilityFrom.IsValid() {
filter.AvailableFrom = req.AvailabilityFrom.AsTime()

View File

@ -18,6 +18,7 @@ func main() {
var (
service_name = cfg.GetString("name")
grpc_enable = cfg.GetBool("services.grpc.enable")
dev_env = cfg.GetBool("dev_env")
)
storage, err := storage.NewStorage(cfg)
@ -28,6 +29,9 @@ func main() {
handler := handlers.NewHandler(cfg, storage)
fmt.Println("Running", service_name, ":")
if dev_env {
fmt.Printf("\033]0;%s\007", service_name)
}
failed := make(chan error)

View File

@ -18,6 +18,7 @@ type Vehicle struct {
type VehicleFilters struct {
Types []string
Administrators []string
AvailableFrom time.Time
AvailableTo time.Time
}
@ -49,6 +50,21 @@ func (v Vehicle) MatchesFilters(filters VehicleFilters) bool {
}
}
if len(filters.Administrators) > 0 {
found := false
for _, a := range filters.Administrators {
for _, va := range v.Administrators {
if a == va {
found = true
break
}
}
}
if !found {
return false
}
}
if !v.Free(filters.AvailableFrom, filters.AvailableTo) {
return false
}