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>
32 lines
742 B
Go
32 lines
742 B
Go
package universities
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces"
|
|
"git.bissendorf.co/bissendorf/unifood/m/v2/model/external/stwbremen"
|
|
"git.bissendorf.co/bissendorf/unifood/m/v2/util"
|
|
)
|
|
|
|
func getRestaurantList(ctx context.Context, client interfaces.QueryClient[stwbremen.RestaurantList]) ([]string, error) {
|
|
list, err := client.Get(ctx,
|
|
`page('essen-und-trinken')`,
|
|
`{"items": "page.children.children"}`,
|
|
false,
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to load university list: %w", err)
|
|
}
|
|
|
|
return util.Transform(list.Items, func(i *string) string {
|
|
parts := strings.SplitN(*i, "/", 2)
|
|
if len(parts) < 2 {
|
|
return parts[0]
|
|
}
|
|
|
|
return parts[1]
|
|
}), nil
|
|
}
|