feat: enrich content item fields
This commit is contained in:
@@ -13,20 +13,31 @@ type ContentListFilter struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ContentItem struct {
|
type ContentItem struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Title string `json:"title"`
|
// TenantID 内容所属租户ID。
|
||||||
Cover string `json:"cover"`
|
TenantID int64 `json:"tenant_id"`
|
||||||
Genre string `json:"genre"`
|
// UserID 内容作者用户ID(与 author_id 同义,便于后台展示)。
|
||||||
Type string `json:"type"` // video, audio, article
|
UserID int64 `json:"user_id"`
|
||||||
Price float64 `json:"price"`
|
Title string `json:"title"`
|
||||||
AuthorID int64 `json:"author_id"`
|
Cover string `json:"cover"`
|
||||||
AuthorName string `json:"author_name"`
|
Genre string `json:"genre"`
|
||||||
AuthorAvatar string `json:"author_avatar"`
|
Type string `json:"type"` // video, audio, article
|
||||||
AuthorIsFollowing bool `json:"author_is_following"`
|
// Status 内容状态(如 published/unpublished)。
|
||||||
Views int `json:"views"`
|
Status string `json:"status"`
|
||||||
Likes int `json:"likes"`
|
// Visibility 内容可见性(如 public/tenant_only/private)。
|
||||||
CreatedAt string `json:"created_at"`
|
Visibility string `json:"visibility"`
|
||||||
IsPurchased bool `json:"is_purchased"`
|
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 {
|
type ContentDetail struct {
|
||||||
|
|||||||
@@ -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 {
|
func (s *content) toContentItemDTO(item *models.Content, price float64, authorIsFollowing bool) content_dto.ContentItem {
|
||||||
dto := content_dto.ContentItem{
|
dto := content_dto.ContentItem{
|
||||||
ID: item.ID,
|
ID: item.ID,
|
||||||
|
TenantID: item.TenantID,
|
||||||
|
UserID: item.UserID,
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
Genre: item.Genre,
|
Genre: item.Genre,
|
||||||
|
Status: string(item.Status),
|
||||||
|
Visibility: string(item.Visibility),
|
||||||
AuthorID: item.UserID,
|
AuthorID: item.UserID,
|
||||||
Views: int(item.Views),
|
Views: int(item.Views),
|
||||||
Likes: int(item.Likes),
|
Likes: int(item.Likes),
|
||||||
@@ -488,6 +492,9 @@ func (s *content) toContentItemDTO(item *models.Content, price float64, authorIs
|
|||||||
Price: price,
|
Price: price,
|
||||||
AuthorIsFollowing: authorIsFollowing,
|
AuthorIsFollowing: authorIsFollowing,
|
||||||
}
|
}
|
||||||
|
if !item.PublishedAt.IsZero() {
|
||||||
|
dto.PublishedAt = item.PublishedAt.Format("2006-01-02")
|
||||||
|
}
|
||||||
if item.Author != nil {
|
if item.Author != nil {
|
||||||
dto.AuthorName = item.Author.Nickname
|
dto.AuthorName = item.Author.Nickname
|
||||||
dto.AuthorAvatar = item.Author.Avatar
|
dto.AuthorAvatar = item.Author.Avatar
|
||||||
|
|||||||
@@ -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 {
|
func (s *super) toSuperContentDTO(item *models.Content, price *models.ContentPrice) *v1_dto.ContentItem {
|
||||||
dto := &v1_dto.ContentItem{
|
dto := &v1_dto.ContentItem{
|
||||||
ID: item.ID,
|
ID: item.ID,
|
||||||
|
TenantID: item.TenantID,
|
||||||
|
UserID: item.UserID,
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
Genre: item.Genre,
|
Genre: item.Genre,
|
||||||
|
Status: string(item.Status),
|
||||||
|
Visibility: string(item.Visibility),
|
||||||
AuthorID: item.UserID,
|
AuthorID: item.UserID,
|
||||||
Views: int(item.Views),
|
Views: int(item.Views),
|
||||||
Likes: int(item.Likes),
|
Likes: int(item.Likes),
|
||||||
CreatedAt: item.CreatedAt.Format("2006-01-02"),
|
CreatedAt: item.CreatedAt.Format("2006-01-02"),
|
||||||
IsPurchased: false,
|
IsPurchased: false,
|
||||||
}
|
}
|
||||||
|
if !item.PublishedAt.IsZero() {
|
||||||
|
dto.PublishedAt = item.PublishedAt.Format("2006-01-02")
|
||||||
|
}
|
||||||
if price != nil {
|
if price != nil {
|
||||||
dto.Price = float64(price.PriceAmount) / 100.0
|
dto.Price = float64(price.PriceAmount) / 100.0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user