feat: 添加点赞和收藏功能,优化内容详情视图和评论交互
This commit is contained in:
@@ -88,7 +88,7 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
|
||||
// Convert to DTO
|
||||
data := make([]content_dto.ContentItem, len(list))
|
||||
for i, item := range list {
|
||||
data[i] = s.toContentItemDTO(item, priceMap[item.ID])
|
||||
data[i] = s.toContentItemDTO(item, priceMap[item.ID], false)
|
||||
}
|
||||
|
||||
return &requests.Pager{
|
||||
@@ -179,8 +179,18 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt
|
||||
}
|
||||
}
|
||||
|
||||
// Check if author is followed
|
||||
authorIsFollowing := false
|
||||
if userID > 0 {
|
||||
exists, _ := models.TenantUserQuery.WithContext(ctx).
|
||||
Where(models.TenantUserQuery.TenantID.Eq(item.TenantID),
|
||||
models.TenantUserQuery.Role.Contains(string(consts.TenantUserRoleMember))).
|
||||
Exists()
|
||||
authorIsFollowing = exists
|
||||
}
|
||||
|
||||
detail := &content_dto.ContentDetail{
|
||||
ContentItem: s.toContentItemDTO(&item, price),
|
||||
ContentItem: s.toContentItemDTO(&item, price, authorIsFollowing),
|
||||
Description: item.Description,
|
||||
Body: item.Body,
|
||||
MediaUrls: s.toMediaURLs(accessibleAssets),
|
||||
@@ -356,7 +366,7 @@ func (s *content) GetLibrary(ctx context.Context, userID int64) ([]user_dto.Cont
|
||||
|
||||
var data []user_dto.ContentItem
|
||||
for _, item := range list {
|
||||
dto := s.toContentItemDTO(item, 0)
|
||||
dto := s.toContentItemDTO(item, 0, false)
|
||||
dto.IsPurchased = true
|
||||
data = append(data, dto)
|
||||
}
|
||||
@@ -441,16 +451,17 @@ func (s *content) ListTopics(ctx context.Context) ([]content_dto.Topic, error) {
|
||||
|
||||
// Helpers
|
||||
|
||||
func (s *content) toContentItemDTO(item *models.Content, price float64) content_dto.ContentItem {
|
||||
func (s *content) toContentItemDTO(item *models.Content, price float64, authorIsFollowing bool) content_dto.ContentItem {
|
||||
dto := content_dto.ContentItem{
|
||||
ID: cast.ToString(item.ID),
|
||||
Title: item.Title,
|
||||
Genre: item.Genre,
|
||||
AuthorID: cast.ToString(item.UserID),
|
||||
Views: int(item.Views),
|
||||
Likes: int(item.Likes),
|
||||
CreatedAt: item.CreatedAt.Format("2006-01-02"),
|
||||
Price: price,
|
||||
ID: cast.ToString(item.ID),
|
||||
Title: item.Title,
|
||||
Genre: item.Genre,
|
||||
AuthorID: cast.ToString(item.UserID),
|
||||
Views: int(item.Views),
|
||||
Likes: int(item.Likes),
|
||||
CreatedAt: item.CreatedAt.Format("2006-01-02"),
|
||||
Price: price,
|
||||
AuthorIsFollowing: authorIsFollowing,
|
||||
}
|
||||
if item.Author != nil {
|
||||
dto.AuthorName = item.Author.Nickname
|
||||
@@ -623,7 +634,7 @@ func (s *content) getInteractList(ctx context.Context, userID int64, typ string)
|
||||
|
||||
var data []user_dto.ContentItem
|
||||
for _, item := range list {
|
||||
data = append(data, s.toContentItemDTO(item, 0))
|
||||
data = append(data, s.toContentItemDTO(item, 0, false))
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user