From ce95865f92b3c71bb18b8a4b1acdad99fae587ca Mon Sep 17 00:00:00 2001 From: Rogee Date: Thu, 8 Jan 2026 11:30:31 +0800 Subject: [PATCH] feat: enrich content item fields --- backend/app/http/v1/dto/content.go | 39 +++++++++++++++++++----------- backend/app/services/content.go | 7 ++++++ backend/app/services/super.go | 7 ++++++ 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/backend/app/http/v1/dto/content.go b/backend/app/http/v1/dto/content.go index 4b839ad..697f697 100644 --- a/backend/app/http/v1/dto/content.go +++ b/backend/app/http/v1/dto/content.go @@ -13,20 +13,31 @@ type ContentListFilter struct { } type ContentItem struct { - ID int64 `json:"id"` - Title string `json:"title"` - Cover string `json:"cover"` - Genre string `json:"genre"` - Type string `json:"type"` // video, audio, article - Price float64 `json:"price"` - AuthorID int64 `json:"author_id"` - AuthorName string `json:"author_name"` - AuthorAvatar string `json:"author_avatar"` - AuthorIsFollowing bool `json:"author_is_following"` - Views int `json:"views"` - Likes int `json:"likes"` - CreatedAt string `json:"created_at"` - IsPurchased bool `json:"is_purchased"` + ID int64 `json:"id"` + // TenantID 内容所属租户ID。 + TenantID int64 `json:"tenant_id"` + // UserID 内容作者用户ID(与 author_id 同义,便于后台展示)。 + UserID int64 `json:"user_id"` + Title string `json:"title"` + Cover string `json:"cover"` + Genre string `json:"genre"` + Type string `json:"type"` // video, audio, article + // Status 内容状态(如 published/unpublished)。 + Status string `json:"status"` + // Visibility 内容可见性(如 public/tenant_only/private)。 + Visibility string `json:"visibility"` + Price float64 `json:"price"` + AuthorID int64 `json:"author_id"` + AuthorName string `json:"author_name"` + // AuthorAvatar 作者头像URL。 + AuthorAvatar string `json:"author_avatar"` + AuthorIsFollowing bool `json:"author_is_following"` + Views int `json:"views"` + Likes int `json:"likes"` + CreatedAt string `json:"created_at"` + // PublishedAt 发布时间,未发布为空。 + PublishedAt string `json:"published_at"` + IsPurchased bool `json:"is_purchased"` } type ContentDetail struct { diff --git a/backend/app/services/content.go b/backend/app/services/content.go index 3c54987..a02c134 100644 --- a/backend/app/services/content.go +++ b/backend/app/services/content.go @@ -479,8 +479,12 @@ func (s *content) ListTopics(ctx context.Context) ([]content_dto.Topic, error) { func (s *content) toContentItemDTO(item *models.Content, price float64, authorIsFollowing bool) content_dto.ContentItem { dto := content_dto.ContentItem{ ID: item.ID, + TenantID: item.TenantID, + UserID: item.UserID, Title: item.Title, Genre: item.Genre, + Status: string(item.Status), + Visibility: string(item.Visibility), AuthorID: item.UserID, Views: int(item.Views), Likes: int(item.Likes), @@ -488,6 +492,9 @@ func (s *content) toContentItemDTO(item *models.Content, price float64, authorIs Price: price, AuthorIsFollowing: authorIsFollowing, } + if !item.PublishedAt.IsZero() { + dto.PublishedAt = item.PublishedAt.Format("2006-01-02") + } if item.Author != nil { dto.AuthorName = item.Author.Nickname dto.AuthorAvatar = item.Author.Avatar diff --git a/backend/app/services/super.go b/backend/app/services/super.go index c8f5442..346eb33 100644 --- a/backend/app/services/super.go +++ b/backend/app/services/super.go @@ -705,14 +705,21 @@ func (s *super) toSuperContentTenant(tenant *models.Tenant) *super_dto.SuperCont func (s *super) toSuperContentDTO(item *models.Content, price *models.ContentPrice) *v1_dto.ContentItem { dto := &v1_dto.ContentItem{ ID: item.ID, + TenantID: item.TenantID, + UserID: item.UserID, Title: item.Title, Genre: item.Genre, + Status: string(item.Status), + Visibility: string(item.Visibility), AuthorID: item.UserID, Views: int(item.Views), Likes: int(item.Likes), CreatedAt: item.CreatedAt.Format("2006-01-02"), IsPurchased: false, } + if !item.PublishedAt.IsZero() { + dto.PublishedAt = item.PublishedAt.Format("2006-01-02") + } if price != nil { dto.Price = float64(price.PriceAmount) / 100.0 }