feat: add resource handler

This commit is contained in:
2025-07-20 19:45:22 +02:00
parent ec66365b5e
commit 79c1759799
2 changed files with 52 additions and 3 deletions

View File

@ -1,19 +1,51 @@
package cmd package cmd
import ( import (
"context"
"git.bissendorf.co/bissendorf/unifood/m/v2/core/handler/dishes" "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"
"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/core/services/stwhbclient"
"git.bissendorf.co/bissendorf/unifood/m/v2/model/external/stwbremen" "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]{ 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", Name: "dishes",
Aliases: []string{"dish", "d"}, Aliases: []string{"dish", "d"},
Description: "A dish represents a cooked combination of ingredients that can be bought and consumed",
Verbs: []interfaces.Verb{interfaces.VerbGet}, Verbs: []interfaces.Verb{interfaces.VerbGet},
Handler: &dishes.DishesHandler{ Handler: &dishes.DishesHandler{
QueryClient: stwhbclient.New[[]stwbremen.Dish](), 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{}
}

View File

@ -0,0 +1,17 @@
package resources
import "strings"
type Resource struct {
ResourceName string
Aliases []string
Description string
}
func (r *Resource) Kind() string { return "Resource" }
func (r *Resource) Name() string { return r.ResourceName }
func (r *Resource) ColumnNames() []string { return []string{"Aliases", "Description"} }
func (r *Resource) Columns() []any {
return []any{strings.Join(r.Aliases, ", "), r.Description}
}