31 lines
657 B
Go
31 lines
657 B
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)
|
|
}
|