diff --git a/backend/app/http/v1/common.go b/backend/app/http/v1/common.go index 9664a2b..aed95ad 100644 --- a/backend/app/http/v1/common.go +++ b/backend/app/http/v1/common.go @@ -13,8 +13,6 @@ import ( // @provider type Common struct{} -// Upload file -// // @Router /v1/upload [post] // @Summary Upload file // @Description Upload file @@ -22,22 +20,22 @@ type Common struct{} // @Accept multipart/form-data // @Produce json // @Param file formData file true "File" -// @Param type formData string false "Type enum(image, video, audio)" +// @Param form formData dto.UploadForm true "Upload form" // @Success 200 {object} dto.UploadResult // @Bind user local key(__ctx_user) // @Bind file file -// @Bind typeArg body key(type) +// @Bind form body func (c *Common) Upload( ctx fiber.Ctx, user *models.User, file *multipart.FileHeader, - typeArg *string, + form *dto.UploadForm, ) (*dto.UploadResult, error) { val := "" - if typeArg != nil { - val = *typeArg + if form != nil { + val = form.Type } - return services.Common.Upload(ctx, user.ID, file, val) + return services.Common.Upload(ctx.Context(), user.ID, file, val) } // Get options (enums) diff --git a/backend/app/http/v1/dto/common.go b/backend/app/http/v1/dto/common.go index 528eca1..55cc54e 100644 --- a/backend/app/http/v1/dto/common.go +++ b/backend/app/http/v1/dto/common.go @@ -14,3 +14,7 @@ type OptionsResponse struct { ContentStatus []requests.KV `json:"content_status"` ContentGenre []requests.KV `json:"content_genre"` } + +type UploadForm struct { + Type string `form:"type" json:"type"` +} diff --git a/backend/app/http/v1/dto/creator.go b/backend/app/http/v1/dto/creator.go index 6dc8990..b364ca3 100644 --- a/backend/app/http/v1/dto/creator.go +++ b/backend/app/http/v1/dto/creator.go @@ -55,13 +55,14 @@ type ContentEditDTO struct { } type CreatorContentItem struct { - ID string `json:"id"` - Title string `json:"title"` - Genre string `json:"genre"` - Key string `json:"key"` - Views int `json:"views"` - Likes int `json:"likes"` - IsPurchased bool `json:"is_purchased"` + ID string `json:"id"` + Title string `json:"title"` + Genre string `json:"genre"` + Key string `json:"key"` + Price float64 `json:"price"` + Views int `json:"views"` + Likes int `json:"likes"` + IsPurchased bool `json:"is_purchased"` } type AssetDTO struct { diff --git a/backend/app/http/v1/routes.gen.go b/backend/app/http/v1/routes.gen.go index a14157e..d428990 100644 --- a/backend/app/http/v1/routes.gen.go +++ b/backend/app/http/v1/routes.gen.go @@ -59,7 +59,7 @@ func (r *Routes) Register(router fiber.Router) { r.common.Upload, Local[*models.User]("__ctx_user"), File[multipart.FileHeader]("file"), - Body[string]("type"), + Body[dto.UploadForm]("form"), )) // Register routes for controller: Content r.log.Debugf("Registering route: Get /v1/contents -> content.List") diff --git a/backend/app/services/creator.go b/backend/app/services/creator.go index 5e6719c..bc7ae1a 100644 --- a/backend/app/services/creator.go +++ b/backend/app/services/creator.go @@ -122,6 +122,19 @@ func (s *creator) ListContents( return nil, errorx.ErrDatabaseError.WithCause(err) } + // Fetch Prices + ids := make([]int64, len(list)) + for i, item := range list { + ids[i] = item.ID + } + priceMap := make(map[int64]float64) + if len(ids) > 0 { + prices, _ := models.ContentPriceQuery.WithContext(ctx).Where(models.ContentPriceQuery.ContentID.In(ids...)).Find() + for _, p := range prices { + priceMap[p.ContentID] = float64(p.PriceAmount) / 100.0 + } + } + var data []creator_dto.CreatorContentItem for _, item := range list { data = append(data, creator_dto.CreatorContentItem{ @@ -129,6 +142,7 @@ func (s *creator) ListContents( Title: item.Title, Genre: item.Genre, Key: item.Key, + Price: priceMap[item.ID], Views: int(item.Views), Likes: int(item.Likes), IsPurchased: false,