Bläddra i källkod

新增获取帖子详情接口

rdluck 4 år sedan
förälder
incheckning
1d4371bc5f
5 ändrade filer med 72 tillägg och 4 borttagningar
  1. 41 0
      controllers/article.go
  2. 1 1
      controllers/home.go
  3. 22 0
      models/article.go
  4. 3 3
      models/home.go
  5. 5 0
      routers/router.go

+ 41 - 0
controllers/article.go

@@ -1,2 +1,43 @@
 package controllers
 
+import "hongze/hongze_cygx/models"
+
+type ArticleController struct {
+	BaseAuthController
+}
+
+// @Title 获取报告详情
+// @Description 获取报告详情接口
+// @Param   ArticleId   query   int  true       "报告ID"
+// @Success 200 {object} models.ArticleDetail
+// @router /detail [get]
+func (this *ArticleController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	articleId, _ := this.GetInt("ArticleId")
+	if articleId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误"
+		return
+	}
+	detail, err := models.GetArticleDetailById(articleId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败"
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = detail
+}

+ 1 - 1
controllers/home.go

@@ -15,7 +15,7 @@ type HomeController struct {
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Param   ChartPermissionId   query   int  true       "品类id,最新传0"
-// @Success 200 {object} models.HomeList
+// @Success 200 {object} models.HomeListResp
 // @router /list [get]
 func (this *HomeController) ListHome() {
 	br := new(models.BaseResponse).Init()

+ 22 - 0
models/article.go

@@ -1,5 +1,7 @@
 package models
 
+import "rdluck_tools/orm"
+
 type CygxArticle struct {
 	Article_id      int    `description:"文章id"`
 	Title           string `description:"标题"`
@@ -14,6 +16,20 @@ type CygxArticle struct {
 }
 
 type HomeArticle struct {
+	Article_id       int    `description:"文章id"`
+	Title            string `description:"标题"`
+	TitleEn          string `description:"英文标题 "`
+	UpdateFrequency  string `description:"更新周期"`
+	CreateDate       string `description:"创建时间"`
+	PublishDate      string `description:"发布时间"`
+	Body             string `description:"内容"`
+	Abstract         string `description:"摘要"`
+	CategoryName     string `description:"一级分类"`
+	SubCategoryName  string `description:"二级分类"`
+	ExpertBackground string `description:"专家背景"`
+}
+
+type ArticleDetail struct {
 	Article_id      int    `description:"文章id"`
 	Title           string `description:"标题"`
 	TitleEn         string `description:"英文标题 "`
@@ -26,3 +42,9 @@ type HomeArticle struct {
 	SubCategoryName string `description:"二级分类"`
 }
 
+func GetArticleDetailById(articleId int) (item *ArticleDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article WHERE article_id = ? `
+	err = o.Raw(sql, articleId).QueryRow(&item)
+	return
+}

+ 3 - 3
models/home.go

@@ -9,7 +9,7 @@ func GetHomeCount(condition string, pars []interface{}) (count int, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT COUNT(1) AS count
                 FROM cygx_article AS a
-                WHERE a.publish_status=1`
+                WHERE a.publish_status=1 `
 	if condition != "" {
 		sql += condition
 	}
@@ -21,11 +21,11 @@ func GetHomeList(condition string, pars []interface{}, startSize, pageSize int)
 	o := orm.NewOrm()
 	sql := ` SELECT *
                  FROM cygx_article AS a
-                WHERE a.publish_status=1`
+                WHERE a.publish_status=1 `
 	if condition != "" {
 		sql += condition
 	}
-	sql += `ORDER BY publish_date DESC LIMIT ?,? `
+	sql += ` ORDER BY publish_date DESC LIMIT ?,? `
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }

+ 5 - 0
routers/router.go

@@ -43,6 +43,11 @@ func init() {
 				&controllers.ChartPermissionController{},
 			),
 		),
+		beego.NSNamespace("/article",
+			beego.NSInclude(
+				&controllers.ArticleController{},
+			),
+		),
 	)
 	beego.AddNamespace(ns)
 }