feat: add resource handler #2
@ -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: "dishes",
|
Name: "resources",
|
||||||
Aliases: []string{"dish", "d"},
|
Aliases: []string{"resource", "r"},
|
||||||
Verbs: []interfaces.Verb{interfaces.VerbGet},
|
Description: "A meta representation of a usable resources of this CLI",
|
||||||
|
Verbs: []interfaces.Verb{interfaces.VerbGet},
|
||||||
|
Handler: ®isteredResourcesHandler{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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{
|
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{}
|
||||||
|
}
|
||||||
|
|||||||
17
model/resources/resources.go
Normal file
17
model/resources/resources.go
Normal 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}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user