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

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

View File

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

View File

@ -17,9 +17,10 @@ type Vehicle struct {
} }
type VehicleFilters struct { type VehicleFilters struct {
Types []string Types []string
AvailableFrom time.Time Administrators []string
AvailableTo time.Time AvailableFrom time.Time
AvailableTo time.Time
} }
func (v Vehicle) Free(start time.Time, end time.Time) bool { func (v Vehicle) Free(start time.Time, end time.Time) bool {
@ -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) { if !v.Free(filters.AvailableFrom, filters.AvailableTo) {
return false return false
} }