feat: add universities and restaurants (#4)

Features:
- Allow to search for individual resources by their name
- Add new resources and their handler: Universities, Restaurants
- Added new parameter to reverse output order

Reviewed-on: #4
Co-authored-by: bdoerfchen <git@bissendorf.co>
Co-committed-by: bdoerfchen <git@bissendorf.co>
This commit is contained in:
2025-07-20 22:13:03 +00:00
committed by bissendorf
parent e395b0b4ca
commit 4b7866da03
20 changed files with 408 additions and 33 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"time"
"git.bissendorf.co/bissendorf/unifood/m/v2/core/handler"
"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/model/external/stwbremen"
@ -19,20 +20,15 @@ type MealsHandler struct {
QueryClient interfaces.QueryClient[[]stwbremen.Meal]
}
const (
paramDate = "date"
paramLocation = "location"
)
func (h *MealsHandler) Get(ctx context.Context, params params.Container) (*interfaces.ResourceList, error) {
func (h *MealsHandler) Get(ctx context.Context, name string, params params.Container) (*interfaces.ResourceList, error) {
// Read parameters
p, err := params.GetValue(paramDate)
p, err := params.GetValue(handler.ParamDate)
if err != nil {
return nil, fmt.Errorf("unable to parse date parameter: %w", err)
}
date := p.(time.Time)
location, err := params.GetValue(paramLocation)
location, err := params.GetValue(handler.ParamLocation)
if err != nil {
return nil, fmt.Errorf("unable to parse location parameter: %w", err)
}
@ -72,16 +68,16 @@ func (h *MealsHandler) Get(ctx context.Context, params params.Container) (*inter
func (h *MealsHandler) GetParametersForVerb(verb interfaces.Verb) []params.Registration {
return []params.Registration{
{
Name: paramDate,
Name: handler.ParamDate,
ShortHand: "d",
Description: "Menu date",
Description: "Meal date",
DefaultFunc: func() string { return time.Now().Format(time.DateOnly) },
ParseFunc: func(value string) (any, error) { return time.Parse(time.DateOnly, value) },
},
{
Name: paramLocation,
Name: handler.ParamLocation,
ShortHand: "l",
Description: "Define the restaurant",
Description: "Select a restaurant",
DefaultFunc: func() string { return "330" },
ParseFunc: params.ParseString,
},