diff --git a/pkg/server/channels_api.go b/pkg/server/channels_api.go index e909ea2..9d14eb3 100644 --- a/pkg/server/channels_api.go +++ b/pkg/server/channels_api.go @@ -25,6 +25,24 @@ func getChannel(c *fiber.Ctx) error { return c.JSON(channel) } +func getChannelAvailability(c *fiber.Ctx) error { + user := c.Locals("principal").(models.Account) + alias := c.Params("channel") + + var err error + var channel models.Channel + if val, ok := c.Locals("realm").(models.Realm); ok { + channel, _, err = services.GetAvailableChannelWithAlias(alias, user, val.ID) + } else { + channel, _, err = services.GetAvailableChannelWithAlias(alias, user) + } + if err != nil { + return fiber.NewError(fiber.StatusForbidden, err.Error()) + } + + return c.JSON(channel) +} + func listChannel(c *fiber.Ctx) error { var err error var channels []models.Channel diff --git a/pkg/server/startup.go b/pkg/server/startup.go index 6b17b7c..c56be90 100644 --- a/pkg/server/startup.go +++ b/pkg/server/startup.go @@ -79,6 +79,7 @@ func NewServer() { { channels.Get("/", listChannel) channels.Get("/:channel", getChannel) + channels.Get("/:channel/available", authMiddleware, getChannelAvailability) channels.Get("/me", authMiddleware, listOwnedChannel) channels.Get("/me/available", authMiddleware, listAvailableChannel)