Reviewed-on: #3 Co-authored-by: bdoerfchen <git@bissendorf.co> Co-committed-by: bdoerfchen <git@bissendorf.co>
52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.bissendorf.co/bissendorf/unifood/m/v2/core/handler/meals"
|
|
"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"
|
|
"git.bissendorf.co/bissendorf/unifood/m/v2/model/external/stwbremen"
|
|
"git.bissendorf.co/bissendorf/unifood/m/v2/model/resources"
|
|
"git.bissendorf.co/bissendorf/unifood/m/v2/util"
|
|
)
|
|
|
|
var availableResources = []interfaces.ResourceCommand[any]{
|
|
{
|
|
Name: "resources",
|
|
Aliases: []string{"resource", "r"},
|
|
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",
|
|
Verbs: []interfaces.Verb{interfaces.VerbGet},
|
|
Handler: &meals.MealsHandler{
|
|
QueryClient: stwhbclient.New[[]stwbremen.Meal](),
|
|
},
|
|
},
|
|
}
|
|
|
|
type registeredResourcesHandler struct{}
|
|
|
|
func (h *registeredResourcesHandler) Get(ctx context.Context, params params.Container) (*interfaces.ResourceList, error) {
|
|
return &interfaces.ResourceList{
|
|
ItemKind: resources.ResourceResource,
|
|
Items: util.Transform(availableResources, func(i *interfaces.ResourceCommand[any]) interfaces.Resource {
|
|
return &resources.Resource{
|
|
ResourceName: i.Name,
|
|
Aliases: i.Aliases,
|
|
Description: i.Description,
|
|
}
|
|
}),
|
|
}, nil
|
|
}
|
|
|
|
func (h *registeredResourcesHandler) GetParametersForVerb(verb interfaces.Verb) []params.Registration {
|
|
return []params.Registration{}
|
|
}
|