53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package medias
|
|
|
|
import (
|
|
"backend/common/errorx"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
. "github.com/spf13/cast"
|
|
)
|
|
|
|
// @provider
|
|
type Controller struct {
|
|
svc *Service
|
|
}
|
|
|
|
// List
|
|
func (c *Controller) List(ctx fiber.Ctx) error {
|
|
filter := ListFilter{}
|
|
if err := ctx.Bind().Body(&filter); err != nil {
|
|
return ctx.Status(fiber.StatusBadRequest).JSON(errorx.RequestParseError)
|
|
}
|
|
|
|
tenantId, userId := ToInt64(ctx.Locals("tenantId")), ToInt64(ctx.Locals("userId"))
|
|
|
|
items, err := c.svc.List(ctx.Context(), tenantId, userId, &filter)
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).JSON(errorx.InternalError)
|
|
}
|
|
|
|
return ctx.JSON(items)
|
|
}
|
|
|
|
// Show
|
|
func (c *Controller) Show(ctx fiber.Ctx) error {
|
|
id := ToInt64(ctx.Params("id"))
|
|
tenantId, userId := ToInt64(ctx.Locals("tenantId")), ToInt64(ctx.Locals("userId"))
|
|
|
|
item, err := c.svc.GetByID(ctx.Context(), tenantId, userId, id)
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).JSON(errorx.InternalError)
|
|
}
|
|
|
|
return ctx.JSON(item)
|
|
}
|
|
|
|
// Audio
|
|
func (c *Controller) Video(ctx fiber.Ctx) error {
|
|
// mediaId := ToInt64(ctx.Params("media"))
|
|
// tenantId := ToInt64(ctx.Locals("tenantId"))
|
|
// userId := ToInt64(ctx.Locals("userId"))
|
|
|
|
return ctx.JSON(nil)
|
|
}
|