feat: get handlers return object slices
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"git.bissendorf.co/bissendorf/unifood/m/v2/core/handler/menu"
|
||||
"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/services/stwhbclient"
|
||||
"git.bissendorf.co/bissendorf/unifood/m/v2/model/external/stwbremen"
|
||||
@ -9,10 +9,10 @@ import (
|
||||
|
||||
var availableResources = []interfaces.ResourceCommand[any]{
|
||||
{
|
||||
Name: "menu",
|
||||
Aliases: []string{"m"},
|
||||
Name: "dishes",
|
||||
Aliases: []string{"dish", "d"},
|
||||
Verbs: []interfaces.Verb{interfaces.VerbGet},
|
||||
Handler: &menu.MenuHandler{
|
||||
Handler: &dishes.DishesHandler{
|
||||
QueryClient: stwhbclient.New[[]stwbremen.Dish](),
|
||||
},
|
||||
},
|
||||
|
||||
@ -37,7 +37,5 @@ func initRootCmd() {
|
||||
logger := jlog.New(slog.LevelDebug)
|
||||
ctx := jlog.ContextWith(context.Background(), logger)
|
||||
|
||||
logger.Debug("Register verb commands")
|
||||
rootCmd.AddCommand(getVerbs(ctx, &appConfig)...)
|
||||
logger.Debug("Verb commands registered successfully")
|
||||
}
|
||||
|
||||
10
cmd/verbs.go
10
cmd/verbs.go
@ -33,8 +33,8 @@ var verbs = []VerbItem{
|
||||
return fmt.Errorf("resource does not support GET")
|
||||
}
|
||||
|
||||
// Get item
|
||||
item, err := h.Get(ctx, params)
|
||||
// Get items
|
||||
items, err := h.Get(ctx, params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("retrieving item failed: %w", err)
|
||||
}
|
||||
@ -46,7 +46,7 @@ var verbs = []VerbItem{
|
||||
}
|
||||
|
||||
// Format and output
|
||||
formatted, err := formatter.Format(item)
|
||||
formatted, err := formatter.Format(items)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to format output: %w", err)
|
||||
}
|
||||
@ -61,8 +61,6 @@ var verbs = []VerbItem{
|
||||
}
|
||||
|
||||
func getVerbs(ctx context.Context, config *AppConfig) (commands []*cobra.Command) {
|
||||
logger := jlog.FromContext(ctx)
|
||||
|
||||
for _, v := range verbs {
|
||||
verbCommand := &cobra.Command{
|
||||
Use: strings.ToLower(string(v.Name)),
|
||||
@ -115,8 +113,6 @@ func getVerbs(ctx context.Context, config *AppConfig) (commands []*cobra.Command
|
||||
)
|
||||
}
|
||||
verbCommand.AddCommand(resourceCommand)
|
||||
|
||||
logger.Debug(fmt.Sprintf("Registered %s %s", strings.ToUpper(string(v.Name)), r.Name))
|
||||
}
|
||||
|
||||
commands = append(commands, verbCommand)
|
||||
|
||||
Reference in New Issue
Block a user