feat: 更新上传接口,使用新的上传表单结构并添加价格字段
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user