✨ Able to list destinations
This commit is contained in:
parent
ebc3a6f09c
commit
8888f7661a
@ -7,6 +7,8 @@ const (
|
|||||||
|
|
||||||
type BaseDestination struct {
|
type BaseDestination struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
Label string `json:"label"`
|
||||||
|
LabelRegion string `json:"label_region"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LocalDestination struct {
|
type LocalDestination struct {
|
||||||
|
19
pkg/internal/server/api/destinations.go
Normal file
19
pkg/internal/server/api/destinations.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
func listDestination(c *fiber.Ctx) error {
|
||||||
|
var destinations []models.LocalDestination
|
||||||
|
for _, value := range viper.GetStringSlice("destinations") {
|
||||||
|
var parsed models.LocalDestination
|
||||||
|
raw, _ := jsoniter.Marshal(value)
|
||||||
|
_ = jsoniter.Unmarshal(raw, &parsed)
|
||||||
|
destinations = append(destinations, parsed)
|
||||||
|
}
|
||||||
|
return c.JSON(destinations)
|
||||||
|
}
|
@ -6,10 +6,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func MapAPIs(app *fiber.App, baseURL string) {
|
func MapAPIs(app *fiber.App, baseURL string) {
|
||||||
app.Get("/.well-known/destinations", getDestinations)
|
|
||||||
|
|
||||||
api := app.Group(baseURL).Name("API")
|
api := app.Group(baseURL).Name("API")
|
||||||
{
|
{
|
||||||
|
api.Get("/destinations", listDestination)
|
||||||
|
|
||||||
boost := api.Group("/boosts").Name("Boosts API")
|
boost := api.Group("/boosts").Name("Boosts API")
|
||||||
{
|
{
|
||||||
boost.Get("/", listBoostByUser)
|
boost.Get("/", listBoostByUser)
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getDestinations(c *fiber.Ctx) error {
|
|
||||||
var data []string
|
|
||||||
for key := range viper.GetStringMap("destinations") {
|
|
||||||
data = append(data, key)
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.JSON(fiber.Map{
|
|
||||||
"data": data,
|
|
||||||
"preferred": viper.GetString("preferred_destination"),
|
|
||||||
})
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user