|
|
@@ -26,7 +26,8 @@ func (s *Server) MaterialList(c *gin.Context) {
|
|
|
ctx := s.FromContext(c)
|
|
|
db := s.DB()
|
|
|
|
|
|
- categoryId := ctx.QueryInt64("categoryId", 0)
|
|
|
+ groupId := ctx.QueryInt64("groupId", 0)
|
|
|
+ materialType := ctx.QueryString("type", "")
|
|
|
|
|
|
paging := &services.Pagination{
|
|
|
Current: ctx.QueryInt64("current", 1),
|
|
|
@@ -35,28 +36,28 @@ func (s *Server) MaterialList(c *gin.Context) {
|
|
|
|
|
|
query := db.Model(&entity.DtMaterial{}).Where("status = ?", 1)
|
|
|
|
|
|
- if categoryId > 0 {
|
|
|
- query = query.Where("category_id = ?", categoryId)
|
|
|
+ if groupId > 0 {
|
|
|
+ query = query.Where("group_id = ?", groupId)
|
|
|
+ }
|
|
|
+
|
|
|
+ if materialType != "" {
|
|
|
+ query = query.Where("type = ?", materialType)
|
|
|
}
|
|
|
|
|
|
query.Count(&paging.Total)
|
|
|
paging.Computer()
|
|
|
|
|
|
type MaterialInfo struct {
|
|
|
- Id int64 `json:"id"`
|
|
|
- Title string `json:"title"`
|
|
|
- TitleVi string `json:"titleVi"`
|
|
|
- Type string `json:"type"`
|
|
|
- Icon string `json:"icon"`
|
|
|
- Images string `json:"images"`
|
|
|
- Videos string `json:"videos"`
|
|
|
- TextContent string `json:"textContent"`
|
|
|
- ViewCount int `json:"viewCount"`
|
|
|
- CreatedAt int64 `json:"createdAt"`
|
|
|
+ Id int64 `json:"id"`
|
|
|
+ Name string `json:"name"`
|
|
|
+ Url string `json:"url"`
|
|
|
+ Content string `json:"content"`
|
|
|
+ Type string `json:"type"`
|
|
|
+ CreatedAt int64 `json:"createdAt"`
|
|
|
}
|
|
|
|
|
|
materials := make([]*MaterialInfo, 0)
|
|
|
- query.Select("id, title, title_vi, type, icon, images, videos, text_content, view_count, created_at").
|
|
|
+ query.Select("id, name, url, content, type, created_at").
|
|
|
Order("sort ASC, id DESC").
|
|
|
Offset(int(paging.Start)).
|
|
|
Limit(int(paging.Size)).
|
|
|
@@ -88,25 +89,17 @@ func (s *Server) MaterialDetail(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 更新浏览次数
|
|
|
- db.Model(&entity.DtMaterial{}).Where("id = ?", req.Id).
|
|
|
- Update("view_count", material.ViewCount+1)
|
|
|
-
|
|
|
ctx.OK(gin.H{
|
|
|
- "id": material.Id,
|
|
|
- "title": material.Title,
|
|
|
- "titleVi": material.TitleVi,
|
|
|
- "type": material.Type,
|
|
|
- "icon": material.Icon,
|
|
|
- "images": material.Images,
|
|
|
- "videos": material.Videos,
|
|
|
- "textContent": material.TextContent,
|
|
|
- "viewCount": material.ViewCount + 1,
|
|
|
- "createdAt": material.CreatedAt,
|
|
|
+ "id": material.Id,
|
|
|
+ "name": material.Name,
|
|
|
+ "url": material.Url,
|
|
|
+ "content": material.Content,
|
|
|
+ "type": material.Type,
|
|
|
+ "createdAt": material.CreatedAt,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-// MaterialLike 素材点赞 - 由于实体没有likeCount字段,改为增加浏览次数
|
|
|
+// MaterialLike 素材点赞
|
|
|
func (s *Server) MaterialLike(c *gin.Context) {
|
|
|
ctx := s.FromContext(c)
|
|
|
db := s.DB()
|
|
|
@@ -126,11 +119,7 @@ func (s *Server) MaterialLike(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 更新浏览次数(用作点赞计数)
|
|
|
- db.Model(&entity.DtMaterial{}).Where("id = ?", req.Id).
|
|
|
- Update("view_count", material.ViewCount+1)
|
|
|
-
|
|
|
ctx.OK(gin.H{
|
|
|
- "viewCount": material.ViewCount + 1,
|
|
|
+ "success": true,
|
|
|
})
|
|
|
}
|