feat: 更新上传接口,使用新的上传表单结构并添加价格字段

This commit is contained in:
2025-12-31 16:41:19 +08:00
parent b82a69689d
commit 5a364a995a
5 changed files with 33 additions and 16 deletions

View File

@@ -13,8 +13,6 @@ import (
// @provider // @provider
type Common struct{} type Common struct{}
// Upload file
//
// @Router /v1/upload [post] // @Router /v1/upload [post]
// @Summary Upload file // @Summary Upload file
// @Description Upload file // @Description Upload file
@@ -22,22 +20,22 @@ type Common struct{}
// @Accept multipart/form-data // @Accept multipart/form-data
// @Produce json // @Produce json
// @Param file formData file true "File" // @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 // @Success 200 {object} dto.UploadResult
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind file file // @Bind file file
// @Bind typeArg body key(type) // @Bind form body
func (c *Common) Upload( func (c *Common) Upload(
ctx fiber.Ctx, ctx fiber.Ctx,
user *models.User, user *models.User,
file *multipart.FileHeader, file *multipart.FileHeader,
typeArg *string, form *dto.UploadForm,
) (*dto.UploadResult, error) { ) (*dto.UploadResult, error) {
val := "" val := ""
if typeArg != nil { if form != nil {
val = *typeArg 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) // Get options (enums)

View File

@@ -14,3 +14,7 @@ type OptionsResponse struct {
ContentStatus []requests.KV `json:"content_status"` ContentStatus []requests.KV `json:"content_status"`
ContentGenre []requests.KV `json:"content_genre"` ContentGenre []requests.KV `json:"content_genre"`
} }
type UploadForm struct {
Type string `form:"type" json:"type"`
}

View File

@@ -59,6 +59,7 @@ type CreatorContentItem struct {
Title string `json:"title"` Title string `json:"title"`
Genre string `json:"genre"` Genre string `json:"genre"`
Key string `json:"key"` Key string `json:"key"`
Price float64 `json:"price"`
Views int `json:"views"` Views int `json:"views"`
Likes int `json:"likes"` Likes int `json:"likes"`
IsPurchased bool `json:"is_purchased"` IsPurchased bool `json:"is_purchased"`

View File

@@ -59,7 +59,7 @@ func (r *Routes) Register(router fiber.Router) {
r.common.Upload, r.common.Upload,
Local[*models.User]("__ctx_user"), Local[*models.User]("__ctx_user"),
File[multipart.FileHeader]("file"), File[multipart.FileHeader]("file"),
Body[string]("type"), Body[dto.UploadForm]("form"),
)) ))
// Register routes for controller: Content // Register routes for controller: Content
r.log.Debugf("Registering route: Get /v1/contents -> content.List") r.log.Debugf("Registering route: Get /v1/contents -> content.List")

View File

@@ -122,6 +122,19 @@ func (s *creator) ListContents(
return nil, errorx.ErrDatabaseError.WithCause(err) 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 var data []creator_dto.CreatorContentItem
for _, item := range list { for _, item := range list {
data = append(data, creator_dto.CreatorContentItem{ data = append(data, creator_dto.CreatorContentItem{
@@ -129,6 +142,7 @@ func (s *creator) ListContents(
Title: item.Title, Title: item.Title,
Genre: item.Genre, Genre: item.Genre,
Key: item.Key, Key: item.Key,
Price: priceMap[item.ID],
Views: int(item.Views), Views: int(item.Views),
Likes: int(item.Likes), Likes: int(item.Likes),
IsPurchased: false, IsPurchased: false,