org_ad.go 4.68 KB
Newer Older
haoyanbin's avatar
1  
haoyanbin committed
1 2 3
package apis

import (
haoyanbin's avatar
haoyanbin committed
4
	"fmt"
haoyanbin's avatar
1  
haoyanbin committed
5 6 7 8 9 10

	"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/jwtauth/user"
	_ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"

haoyanbin's avatar
1  
haoyanbin committed
11 12 13
	"go-admin/app/operate/models"
	"go-admin/app/operate/service"
	"go-admin/app/operate/service/dto"
haoyanbin's avatar
1  
haoyanbin committed
14 15 16 17 18 19 20
	"go-admin/common/actions"
)

type OrgAd struct {
	api.Api
}

haoyanbin's avatar
haoyanbin committed
21 22 23 24
// GetPage <运营>获取广告列表
// @Summary <运营>获取广告列表
// @Description <运营>获取广告列表
// @Tags <运营>广告
haoyanbin's avatar
1  
haoyanbin committed
25 26
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
haoyanbin's avatar
haoyanbin committed
27
// @Param data body dto.OrgAdGetPageReq true "data"
haoyanbin's avatar
haoyanbin committed
28
// @Success 200 {string} string "{"code": 200, "data": [...]}"
haoyanbin's avatar
1  
haoyanbin committed
29 30 31
// @Router /api/v1/org-ad [get]
// @Security Bearer
func (e OrgAd) GetPage(c *gin.Context) {
haoyanbin's avatar
haoyanbin committed
32 33 34 35 36 37 38 39 40 41 42 43
	req := dto.OrgAdGetPageReq{}
	s := service.OrgAd{}
	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
	}
haoyanbin's avatar
1  
haoyanbin committed
44 45 46 47 48 49 50 51

	p := actions.GetPermissionFromContext(c)
	list := make([]models.OrgAd, 0)
	var count int64

	err = s.GetPage(&req, p, &list, &count)
	if err != nil {
		e.Error(500, err, fmt.Sprintf("获取广告 失败,\r\n失败信息 %s", err.Error()))
haoyanbin's avatar
haoyanbin committed
52
		return
haoyanbin's avatar
1  
haoyanbin committed
53 54 55 56 57
	}

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

haoyanbin's avatar
haoyanbin committed
58 59 60 61
// Get <运营>获取广告
// @Summary <运营>获取广告
// @Description <运营>获取广告
// @Tags <运营>广告
haoyanbin's avatar
1  
haoyanbin committed
62
// @Param id path string false "id"
haoyanbin's avatar
haoyanbin committed
63
// @Success 200 {string} string  {data=models.OrgAd} "{"code": 200, "data": [...]}"
haoyanbin's avatar
1  
haoyanbin committed
64 65 66 67 68
// @Router /api/v1/org-ad/{id} [get]
// @Security Bearer
func (e OrgAd) Get(c *gin.Context) {
	req := dto.OrgAdGetReq{}
	s := service.OrgAd{}
haoyanbin's avatar
haoyanbin committed
69
	err := e.MakeContext(c).
haoyanbin's avatar
1  
haoyanbin committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
		MakeOrm().
		Bind(&req).
		MakeService(&s.Service).
		Errors
	if err != nil {
		e.Logger.Error(err)
		e.Error(500, err, err.Error())
		return
	}
	var object models.OrgAd

	p := actions.GetPermissionFromContext(c)
	err = s.Get(&req, p, &object)
	if err != nil {
		e.Error(500, err, fmt.Sprintf("获取广告失败,\r\n失败信息 %s", err.Error()))
haoyanbin's avatar
haoyanbin committed
85
		return
haoyanbin's avatar
1  
haoyanbin committed
86 87
	}

haoyanbin's avatar
haoyanbin committed
88
	e.OK(object, "查询成功")
haoyanbin's avatar
1  
haoyanbin committed
89 90
}

haoyanbin's avatar
haoyanbin committed
91 92 93 94
// Insert <运营>创建广告
// @Summary <运营>创建广告
// @Description <运营>创建广告
// @Tags <运营>广告
haoyanbin's avatar
1  
haoyanbin committed
95 96 97
// @Accept application/json
// @Product application/json
// @Param data body dto.OrgAdInsertReq true "data"
haoyanbin's avatar
haoyanbin committed
98
// @Success 200 {string} string  	"{"code": 200, "message": "添加成功"}"
haoyanbin's avatar
1  
haoyanbin committed
99 100 101
// @Router /api/v1/org-ad [post]
// @Security Bearer
func (e OrgAd) Insert(c *gin.Context) {
haoyanbin's avatar
haoyanbin committed
102 103 104 105 106 107 108 109 110 111 112 113
	req := dto.OrgAdInsertReq{}
	s := service.OrgAd{}
	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
	}
haoyanbin's avatar
1  
haoyanbin committed
114 115 116 117 118 119
	// 设置创建人
	req.SetCreateBy(user.GetUserId(c))

	err = s.Insert(&req)
	if err != nil {
		e.Error(500, err, fmt.Sprintf("创建广告  失败,\r\n失败信息 %s", err.Error()))
haoyanbin's avatar
haoyanbin committed
120
		return
haoyanbin's avatar
1  
haoyanbin committed
121 122 123 124 125
	}

	e.OK(req.GetId(), "创建成功")
}

haoyanbin's avatar
haoyanbin committed
126 127 128 129
// Update <运营>修改广告
// @Summary <运营>修改广告
// @Description <运营>修改广告
// @Tags <运营>广告
haoyanbin's avatar
1  
haoyanbin committed
130 131 132
// @Accept application/json
// @Product application/json
// @Param data body dto.OrgAdUpdateReq true "body"
haoyanbin's avatar
haoyanbin committed
133
// @Success 200 {string} string  	"{"code": 200, "message": "修改成功"}"
haoyanbin's avatar
1  
haoyanbin committed
134 135 136
// @Router /api/v1/org-ad/{id} [put]
// @Security Bearer
func (e OrgAd) Update(c *gin.Context) {
haoyanbin's avatar
haoyanbin committed
137 138 139 140 141 142 143 144 145 146 147 148
	req := dto.OrgAdUpdateReq{}
	s := service.OrgAd{}
	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
	}
haoyanbin's avatar
1  
haoyanbin committed
149 150 151 152 153 154
	req.SetUpdateBy(user.GetUserId(c))
	p := actions.GetPermissionFromContext(c)

	err = s.Update(&req, p)
	if err != nil {
		e.Error(500, err, fmt.Sprintf("修改广告 失败,\r\n失败信息 %s", err.Error()))
haoyanbin's avatar
haoyanbin committed
155
		return
haoyanbin's avatar
1  
haoyanbin committed
156
	}
haoyanbin's avatar
haoyanbin committed
157
	e.OK(req.GetId(), "修改成功")
haoyanbin's avatar
1  
haoyanbin committed
158 159
}

haoyanbin's avatar
haoyanbin committed
160 161 162 163
// Delete <运营>删除广告
// @Summary <运营>删除广告
// @Description <运营>删除广告
// @Tags <运营>广告
haoyanbin's avatar
1  
haoyanbin committed
164
// @Param ids body []int false "ids"
haoyanbin's avatar
haoyanbin committed
165
// @Success 200 {string} string  	"{"code": 200, "message": "删除成功"}"
haoyanbin's avatar
1  
haoyanbin committed
166 167 168
// @Router /api/v1/org-ad [delete]
// @Security Bearer
func (e OrgAd) Delete(c *gin.Context) {
haoyanbin's avatar
haoyanbin committed
169 170 171 172 173 174 175 176 177 178 179 180
	s := service.OrgAd{}
	req := dto.OrgAdDeleteReq{}
	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
	}
haoyanbin's avatar
1  
haoyanbin committed
181 182 183 184 185 186 187

	// req.SetUpdateBy(user.GetUserId(c))
	p := actions.GetPermissionFromContext(c)

	err = s.Remove(&req, p)
	if err != nil {
		e.Error(500, err, fmt.Sprintf("删除广告失败,\r\n失败信息 %s", err.Error()))
haoyanbin's avatar
haoyanbin committed
188
		return
haoyanbin's avatar
1  
haoyanbin committed
189
	}
haoyanbin's avatar
haoyanbin committed
190 191
	e.OK(req.GetId(), "删除成功")
}