feat: add universities and restaurants
This commit is contained in:
@ -2,8 +2,11 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"git.bissendorf.co/bissendorf/unifood/m/v2/core/handler/meals"
|
||||
"git.bissendorf.co/bissendorf/unifood/m/v2/core/handler/universities"
|
||||
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces"
|
||||
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces/params"
|
||||
"git.bissendorf.co/bissendorf/unifood/m/v2/core/services/stwhbclient"
|
||||
@ -15,28 +18,56 @@ import (
|
||||
var availableResources = []interfaces.ResourceCommand[any]{
|
||||
{
|
||||
Name: "resources",
|
||||
Aliases: []string{"resource", "r"},
|
||||
Description: "A meta resource representing all other object kinds of this CLI",
|
||||
Aliases: []string{"resource"},
|
||||
Description: "A meta resource representing all other object kinds of this CLI.",
|
||||
Verbs: []interfaces.Verb{interfaces.VerbGet},
|
||||
Handler: ®isteredResourcesHandler{},
|
||||
},
|
||||
{
|
||||
Name: "meals",
|
||||
Aliases: []string{"meal", "m"},
|
||||
Description: "A meal represents a cooked combination of ingredients that can be bought and consumed",
|
||||
Description: "A meal represents a cooked combination of ingredients that can be bought and consumed.",
|
||||
Verbs: []interfaces.Verb{interfaces.VerbGet},
|
||||
Handler: &meals.MealsHandler{
|
||||
QueryClient: stwhbclient.New[[]stwbremen.Meal](),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "universities",
|
||||
Aliases: []string{"university", "unis", "uni", "u"},
|
||||
Description: "A facility that is hosting one or multiple restaurants.",
|
||||
Verbs: []interfaces.Verb{interfaces.VerbGet},
|
||||
Handler: &universities.UniversityHandler{
|
||||
QueryClient: stwhbclient.New[stwbremen.RestaurantList](),
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "restaurants",
|
||||
Aliases: []string{"restaurant", "r"},
|
||||
Description: "A place to eat meals",
|
||||
Verbs: []interfaces.Verb{interfaces.VerbGet},
|
||||
Handler: &universities.RestaurantHandler{
|
||||
QueryClient: stwhbclient.New[stwbremen.RestaurantList](),
|
||||
QueryClientRestaurant: stwhbclient.New[stwbremen.Restaurant](),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
type registeredResourcesHandler struct{}
|
||||
|
||||
func (h *registeredResourcesHandler) Get(ctx context.Context, params params.Container) (*interfaces.ResourceList, error) {
|
||||
func (h *registeredResourcesHandler) Get(ctx context.Context, name string, params params.Container) (*interfaces.ResourceList, error) {
|
||||
lowerName := strings.ToLower(name)
|
||||
list := util.Select(availableResources, func(i *interfaces.ResourceCommand[any]) bool {
|
||||
return name == "" || i.Name == lowerName
|
||||
})
|
||||
|
||||
slices.SortFunc(list, func(a, b interfaces.ResourceCommand[any]) int {
|
||||
return strings.Compare(a.Name, b.Name)
|
||||
})
|
||||
|
||||
return &interfaces.ResourceList{
|
||||
ItemKind: resources.ResourceResource,
|
||||
Items: util.Transform(availableResources, func(i *interfaces.ResourceCommand[any]) interfaces.Resource {
|
||||
Items: util.Transform(list, func(i *interfaces.ResourceCommand[any]) interfaces.Resource {
|
||||
return &resources.Resource{
|
||||
ResourceName: i.Name,
|
||||
Aliases: i.Aliases,
|
||||
|
||||
Reference in New Issue
Block a user