ArticleRouter.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package router
  2. import (
  3. "demo/data/dao"
  4. "github.com/gin-gonic/gin"
  5. "github.com/spf13/cast"
  6. )
  7. func ArticleRouter(engine *gin.RouterGroup) {
  8. user := engine.Group("/article")
  9. PushRouter(user, "GET", "/collection", GetArticleCollection)
  10. PushRouter(user, "GET", "/topic", GetArticleTopicList)
  11. }
  12. func GetArticleCollection(c *gin.Context) {
  13. pageNum := c.Query("pageNum")
  14. pageSize := c.Query("pageSize")
  15. list, err := dao.GetArticleList(cast.ToInt(pageNum), cast.ToInt(pageSize))
  16. if err != nil {
  17. c.JSON(200, CreateResultError(500, "数据读取失败"))
  18. return
  19. }
  20. c.JSON(200, CreateResultData(list))
  21. }
  22. func GetArticleTopicList(c *gin.Context) {
  23. topicId := c.Query("topicId")
  24. pageNum := c.Query("pageNum")
  25. pageSize := c.Query("pageSize")
  26. topic, vo, err := dao.GetArticleListByTopicId(cast.ToInt64(topicId), cast.ToInt(pageNum), cast.ToInt(pageSize))
  27. if err != nil {
  28. c.JSON(200, CreateResultError(500, "数据读取失败"))
  29. return
  30. }
  31. m := make(map[string]interface{})
  32. m["topic"] = topic
  33. m["list"] = vo.List
  34. m["total"] = vo.Total
  35. c.JSON(200, CreateResultData(m))
  36. }