Filter vehicle administrators
This commit is contained in:
parent
91991789db
commit
feb935f8bf
|
@ -56,6 +56,7 @@ 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()
|
||||||
|
|
4
main.go
4
main.go
|
@ -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)
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ type Vehicle struct {
|
||||||
|
|
||||||
type VehicleFilters struct {
|
type VehicleFilters struct {
|
||||||
Types []string
|
Types []string
|
||||||
|
Administrators []string
|
||||||
AvailableFrom time.Time
|
AvailableFrom time.Time
|
||||||
AvailableTo 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) {
|
if !v.Free(filters.AvailableFrom, filters.AvailableTo) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue