Files
unifood/cmd/resources.go
bdoerfchen da2d507629 feat: add resource handler (#2)
Features:
- Adds the new meta-resource "Resource" with its resource handler

Reviewed-on: #2
Co-authored-by: bdoerfchen <git@bissendorf.co>
Co-committed-by: bdoerfchen <git@bissendorf.co>
2025-07-20 17:48:00 +00:00

52 lines
1.7 KiB
Go

package cmd
import (
"context"
"git.bissendorf.co/bissendorf/unifood/m/v2/core/handler/dishes"
"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 representation of a usable resources of this CLI",
Verbs: []interfaces.Verb{interfaces.VerbGet},
Handler: &registeredResourcesHandler{},
},
{
Name: "dishes",
Aliases: []string{"dish", "d"},
Description: "A dish represents a cooked combination of ingredients that can be bought and consumed",
Verbs: []interfaces.Verb{interfaces.VerbGet},
Handler: &dishes.DishesHandler{
QueryClient: stwhbclient.New[[]stwbremen.Dish](),
},
},
}
type registeredResourcesHandler struct{}
func (h *registeredResourcesHandler) Get(ctx context.Context, params params.Container) (*interfaces.ResourceList, error) {
return &interfaces.ResourceList{
ItemKind: "",
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{}
}