diff --git a/pkg/internal/server/api/index.go b/pkg/internal/server/api/index.go index e25481e..aeedd11 100644 --- a/pkg/internal/server/api/index.go +++ b/pkg/internal/server/api/index.go @@ -11,6 +11,8 @@ func MapAPIs(app *fiber.App, baseURL string) { api.Get("/users/:account", getOthersInfo) api.Get("/users/:account/pin", listOthersPinnedPost) + api.Get("/publishers/:name", getPublisher) + recommendations := api.Group("/recommendations").Name("Recommendations API") { recommendations.Get("/", listRecommendationNews) diff --git a/pkg/internal/server/api/publishers_api.go b/pkg/internal/server/api/publishers_api.go new file mode 100644 index 0000000..f0ccf78 --- /dev/null +++ b/pkg/internal/server/api/publishers_api.go @@ -0,0 +1,15 @@ +package api + +import ( + "git.solsynth.dev/hydrogen/interactive/pkg/internal/services" + "github.com/gofiber/fiber/v2" +) + +func getPublisher(c *fiber.Ctx) error { + alias := c.Params("name") + if out, err := services.GetPublisher(alias); err != nil { + return fiber.NewError(fiber.StatusNotFound, err.Error()) + } else { + return c.JSON(out) + } +} diff --git a/pkg/internal/services/publishers.go b/pkg/internal/services/publishers.go new file mode 100644 index 0000000..00aa3f4 --- /dev/null +++ b/pkg/internal/services/publishers.go @@ -0,0 +1,26 @@ +package services + +import ( + "git.solsynth.dev/hydrogen/interactive/pkg/internal/database" + "git.solsynth.dev/hydrogen/interactive/pkg/internal/models" + "github.com/gofiber/fiber/v2" +) + +func GetPublisher(alias string) (any, error) { + realm, err := GetRealmWithAlias(alias) + if err == nil { + return fiber.Map{ + "type": "realm", + "data": realm, + }, nil + } + + var account models.Account + if err = database.C.Where("name = ?", alias).First(&account).Error; err != nil { + return nil, err + } + return fiber.Map{ + "type": "account", + "data": account, + }, nil +}