|
|
@@ -45,18 +45,19 @@ func (s *Server) MaterialList(c *gin.Context) {
|
|
|
type MaterialInfo struct {
|
|
|
Id int64 `json:"id"`
|
|
|
Title string `json:"title"`
|
|
|
- Cover string `json:"cover"`
|
|
|
+ TitleVi string `json:"titleVi"`
|
|
|
Type string `json:"type"`
|
|
|
- Url string `json:"url"`
|
|
|
- Description string `json:"description"`
|
|
|
+ Icon string `json:"icon"`
|
|
|
+ Images string `json:"images"`
|
|
|
+ Videos string `json:"videos"`
|
|
|
+ TextContent string `json:"textContent"`
|
|
|
ViewCount int `json:"viewCount"`
|
|
|
- LikeCount int `json:"likeCount"`
|
|
|
CreatedAt int64 `json:"createdAt"`
|
|
|
}
|
|
|
|
|
|
materials := make([]*MaterialInfo, 0)
|
|
|
- query.Select("id, title, cover, type, url, description, view_count, like_count, created_at").
|
|
|
- Order("id DESC").
|
|
|
+ query.Select("id, title, title_vi, type, icon, images, videos, text_content, view_count, created_at").
|
|
|
+ Order("sort ASC, id DESC").
|
|
|
Offset(int(paging.Start)).
|
|
|
Limit(int(paging.Size)).
|
|
|
Scan(&materials)
|
|
|
@@ -94,18 +95,18 @@ func (s *Server) MaterialDetail(c *gin.Context) {
|
|
|
ctx.OK(gin.H{
|
|
|
"id": material.Id,
|
|
|
"title": material.Title,
|
|
|
- "cover": material.Cover,
|
|
|
+ "titleVi": material.TitleVi,
|
|
|
"type": material.Type,
|
|
|
- "url": material.Url,
|
|
|
- "description": material.Description,
|
|
|
- "content": material.Content,
|
|
|
+ "icon": material.Icon,
|
|
|
+ "images": material.Images,
|
|
|
+ "videos": material.Videos,
|
|
|
+ "textContent": material.TextContent,
|
|
|
"viewCount": material.ViewCount + 1,
|
|
|
- "likeCount": material.LikeCount,
|
|
|
"createdAt": material.CreatedAt,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-// MaterialLike 素材点赞
|
|
|
+// MaterialLike 素材点赞 - 由于实体没有likeCount字段,改为增加浏览次数
|
|
|
func (s *Server) MaterialLike(c *gin.Context) {
|
|
|
ctx := s.FromContext(c)
|
|
|
db := s.DB()
|
|
|
@@ -125,11 +126,11 @@ func (s *Server) MaterialLike(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 更新点赞次数
|
|
|
+ // 更新浏览次数(用作点赞计数)
|
|
|
db.Model(&entity.DtMaterial{}).Where("id = ?", req.Id).
|
|
|
- Update("like_count", material.LikeCount+1)
|
|
|
+ Update("view_count", material.ViewCount+1)
|
|
|
|
|
|
ctx.OK(gin.H{
|
|
|
- "likeCount": material.LikeCount + 1,
|
|
|
+ "viewCount": material.ViewCount + 1,
|
|
|
})
|
|
|
}
|