diff --git a/backend/app/http/v1/dto/creator.go b/backend/app/http/v1/dto/creator.go index 226170f..bc474c3 100644 --- a/backend/app/http/v1/dto/creator.go +++ b/backend/app/http/v1/dto/creator.go @@ -38,7 +38,8 @@ type ContentUpdateForm struct { Title string `json:"title"` Genre string `json:"genre"` Key string `json:"key"` - Price float64 `json:"price"` + Price *float64 `json:"price"` + Status string `json:"status"` CoverIDs []string `json:"cover_ids"` MediaIDs []string `json:"media_ids"` } @@ -64,6 +65,11 @@ type CreatorContentItem struct { Price float64 `json:"price"` Views int `json:"views"` Likes int `json:"likes"` + Cover string `json:"cover"` + ImageCount int `json:"image_count"` + VideoCount int `json:"video_count"` + AudioCount int `json:"audio_count"` + Status string `json:"status"` IsPurchased bool `json:"is_purchased"` } diff --git a/backend/app/services/creator.go b/backend/app/services/creator.go index bc494f4..27d0351 100644 --- a/backend/app/services/creator.go +++ b/backend/app/services/creator.go @@ -117,7 +117,12 @@ func (s *creator) ListContents( q = q.Where(tbl.Title.Like("%" + *filter.Keyword + "%")) } - list, err := q.Order(tbl.CreatedAt.Desc()).Find() + var list []*models.Content + err = q.Order(tbl.CreatedAt.Desc()). + UnderlyingDB(). + Preload("ContentAssets"). + Preload("ContentAssets.Asset"). + Find(&list).Error if err != nil { return nil, errorx.ErrDatabaseError.WithCause(err) } @@ -137,6 +142,38 @@ func (s *creator) ListContents( var data []creator_dto.CreatorContentItem for _, item := range list { + var imageCount, videoCount, audioCount int + var cover string + var firstImage string + + for _, ca := range item.ContentAssets { + if ca.Asset == nil { + continue + } + + // Count logic + switch ca.Asset.Type { + case consts.MediaAssetTypeImage: + imageCount++ + if firstImage == "" { + firstImage = Common.GetAssetURL(ca.Asset.ObjectKey) + } + case consts.MediaAssetTypeVideo: + videoCount++ + case consts.MediaAssetTypeAudio: + audioCount++ + } + + // Cover logic + if ca.Role == consts.ContentAssetRoleCover && cover == "" { + cover = Common.GetAssetURL(ca.Asset.ObjectKey) + } + } + + if cover == "" { + cover = firstImage + } + data = append(data, creator_dto.CreatorContentItem{ ID: cast.ToString(item.ID), Title: item.Title, @@ -145,6 +182,11 @@ func (s *creator) ListContents( Price: priceMap[item.ID], Views: int(item.Views), Likes: int(item.Likes), + Cover: cover, + ImageCount: imageCount, + VideoCount: videoCount, + AudioCount: audioCount, + Status: string(item.Status), IsPurchased: false, }) } @@ -239,34 +281,40 @@ func (s *creator) UpdateContent( } // 2. Update Content - _, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).Updates(&models.Content{ + contentUpdates := &models.Content{ Title: form.Title, Genre: form.Genre, Key: form.Key, - }) + } + if form.Status != "" { + contentUpdates.Status = consts.ContentStatus(form.Status) + } + _, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).Updates(contentUpdates) if err != nil { return err } // 3. Update Price // Check if price exists - count, _ := tx.ContentPrice.WithContext(ctx).Where(tx.ContentPrice.ContentID.Eq(cid)).Count() - newPrice := int64(form.Price * 100) - if count > 0 { - _, err = tx.ContentPrice.WithContext(ctx). - Where(tx.ContentPrice.ContentID.Eq(cid)). - UpdateSimple(tx.ContentPrice.PriceAmount.Value(newPrice)) - } else { - err = tx.ContentPrice.WithContext(ctx).Create(&models.ContentPrice{ - TenantID: tid, - UserID: c.UserID, - ContentID: cid, - PriceAmount: newPrice, - Currency: consts.CurrencyCNY, - }) - } - if err != nil { - return err + if form.Price != nil { + count, _ := tx.ContentPrice.WithContext(ctx).Where(tx.ContentPrice.ContentID.Eq(cid)).Count() + newPrice := int64(*form.Price * 100) + if count > 0 { + _, err = tx.ContentPrice.WithContext(ctx). + Where(tx.ContentPrice.ContentID.Eq(cid)). + UpdateSimple(tx.ContentPrice.PriceAmount.Value(newPrice)) + } else { + err = tx.ContentPrice.WithContext(ctx).Create(&models.ContentPrice{ + TenantID: tid, + UserID: c.UserID, + ContentID: cid, + PriceAmount: newPrice, + Currency: consts.CurrencyCNY, + }) + } + if err != nil { + return err + } } // 4. Update Assets (Full replacement strategy) diff --git a/frontend/portal/src/views/creator/ContentsView.vue b/frontend/portal/src/views/creator/ContentsView.vue index 71e03c8..804999d 100644 --- a/frontend/portal/src/views/creator/ContentsView.vue +++ b/frontend/portal/src/views/creator/ContentsView.vue @@ -77,10 +77,21 @@