feat: add list profile

This commit is contained in:
Rogee
2024-12-09 20:33:35 +08:00
parent af8a8e9469
commit 0c9cb498d5
12 changed files with 125 additions and 40 deletions

View File

@@ -6,7 +6,7 @@ import (
"backend/providers/jwt"
"github.com/gofiber/fiber/v3"
. "github.com/spf13/cast"
log "github.com/sirupsen/logrus"
)
// @provider
@@ -18,6 +18,7 @@ type Controller struct {
func (c *Controller) List(ctx fiber.Ctx) error {
filter := ListFilter{}
if err := ctx.Bind().Body(&filter); err != nil {
log.WithError(err).Error("parse body failed")
return ctx.Status(fiber.StatusBadRequest).JSON(errorx.RequestParseError)
}
claim := ctx.Locals(consts.CtxKeyClaim).(*jwt.Claims)
@@ -32,15 +33,24 @@ func (c *Controller) List(ctx fiber.Ctx) error {
// Show
func (c *Controller) Show(ctx fiber.Ctx) error {
id := ToInt64(ctx.Params("id"))
tenantId, userId := ToInt64(ctx.Locals("tenantId")), ToInt64(ctx.Locals("userId"))
hash := ctx.Params("hash")
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
log.Debug(claim)
item, err := c.svc.GetByID(ctx.Context(), tenantId, userId, id)
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
if err != nil {
log.WithField("action", "medias.Show").WithError(err).Error("GetMediaByHash")
return ctx.Status(fiber.StatusInternalServerError).JSON(errorx.InternalError)
}
return ctx.JSON(item)
resource := c.svc.ModelToListItem(ctx.Context(), model)
resource.Bought, err = c.svc.HasUserBought(ctx.Context(), claim.TenantID, claim.UserID, model.ID)
if err != nil {
log.WithField("action", "medias.Show").WithError(err).Error("HasUserBought")
return ctx.Status(fiber.StatusInternalServerError).JSON(errorx.InternalError)
}
return ctx.JSON(resource)
}
// Audio