org_news.go 2.54 KB
Newer Older
haoyanbin's avatar
haoyanbin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
package apis

import (
	oDto "go-admin/app/operate/service/dto"

	"github.com/gin-gonic/gin"
	"github.com/go-admin-team/go-admin-core/sdk/api"
	_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"

	"go-admin/app/mobile/service"
	"go-admin/app/mobile/service/dto"
	"go-admin/app/operate/models"
	oService "go-admin/app/operate/service"
	"go-admin/common/actions"
)

type OrgNews struct {
	api.Api
}

haoyanbin's avatar
haoyanbin committed
21 22 23 24
// GetPage <手机端>首页
// @Summary <手机端>首页
// @Description <手机端>首页
// @Tags <手机端>首页
haoyanbin's avatar
haoyanbin committed
25 26 27 28
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
// @Param data body dto.OrgNewsGetPageReq true "data"
// @Success 200 {string} string "{"code": 200, "data": [...]}"
haoyanbin's avatar
1  
haoyanbin committed
29
// @Router /mobile/v1/org-news [post]
haoyanbin's avatar
haoyanbin committed
30 31 32 33
// @Security Bearer
func (e OrgNews) GetPage(c *gin.Context) {
	req := dto.OrgNewsGetPageReq{}
	s := service.OrgNews{}
haoyanbin's avatar
1  
haoyanbin committed
34 35 36

	err := c.Bind(&req)
	err = e.MakeContext(c).
haoyanbin's avatar
haoyanbin committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
		MakeOrm().
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}

	p := actions.GetPermissionFromContext(c)

	reqOrgAd := oDto.OrgAdGetPageReq{}
	sOrgAd := oService.OrgAd{}
	e.MakeContext(c).MakeOrm().MakeService(&sOrgAd.Service)
	reqOrgAd.Status = "1"
	listOrgAd := make([]models.OrgAd, 0)
	var countOrgAd int64

	err = sOrgAd.GetPage(&reqOrgAd, p, &listOrgAd, &countOrgAd)
	if err != nil {
haoyanbin's avatar
haoyanbin committed
57
		e.Logger.Error(err)
haoyanbin's avatar
haoyanbin committed
58
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
haoyanbin committed
59 60 61 62 63 64 65 66
		return
	}

	list := make([]dto.OrgNews, 0)
	var count int64

	err = s.GetPage(&req, p, &list, &count)
	if err != nil {
haoyanbin's avatar
haoyanbin committed
67
		e.Logger.Error(err)
haoyanbin's avatar
haoyanbin committed
68
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
haoyanbin committed
69 70 71 72 73 74 75 76 77
		return
	}
	var reply dto.OrgNewsGetPageReply
	reply.OrgAd = listOrgAd
	reply.OrgNews = list

	e.PageOK(reply, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
}

haoyanbin's avatar
haoyanbin committed
78 79 80 81
// Get 获取新闻详情
// @Summary 获取新闻详情
// @Description 获取新闻详情
// @Tags <手机端>首页
haoyanbin's avatar
haoyanbin committed
82 83
// @Param id path string false "id"
// @Success 200 {string} string  "{"code": 200, "data": [...]}"
haoyanbin's avatar
haoyanbin committed
84
// @Router /mobile/v1/org-news/{id} [get]
haoyanbin's avatar
haoyanbin committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
// @Security Bearer
func (e OrgNews) Get(c *gin.Context) {
	req := dto.OrgNewsGetReq{}
	s := service.OrgNews{}
	err := e.MakeContext(c).
		MakeOrm().
		Bind(&req).
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}
	var object models.OrgNews

	p := actions.GetPermissionFromContext(c)
	err = s.Get(&req, p, &object)
	if err != nil {
haoyanbin's avatar
haoyanbin committed
104
		e.Logger.Error(err)
haoyanbin's avatar
haoyanbin committed
105
		e.Error(109, err, "未获取到数据")
haoyanbin's avatar
haoyanbin committed
106 107 108 109 110
		return
	}

	e.OK(object, "查询成功")
}