org_player_user.go 5.21 KB
Newer Older
haoyanbin's avatar
1  
haoyanbin committed
1 2 3 4 5 6 7 8 9 10
package apis

import (
    "fmt"

	"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 21 22 23 24 25 26
	"go-admin/common/actions"
)

type OrgPlayerUser struct {
	api.Api
}

// GetPage 获取球员账户信息列表
// @Summary 获取球员账户信息列表
// @Description 获取球员账户信息列表
// @Tags 球员账户信息
// @Param pageSize query int false "页条数"
// @Param pageIndex query int false "页码"
haoyanbin's avatar
haoyanbin committed
27
// @Success 200 {string} string {"code": 200, "data": [...]}
haoyanbin's avatar
1  
haoyanbin committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
// @Router /api/v1/org-player-user [get]
// @Security Bearer
func (e OrgPlayerUser) GetPage(c *gin.Context) {
    req := dto.OrgPlayerUserGetPageReq{}
    s := service.OrgPlayerUser{}
    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
   	}

	p := actions.GetPermissionFromContext(c)
	list := make([]models.OrgPlayerUser, 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()))
        return
	}

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

// Get 获取球员账户信息
// @Summary 获取球员账户信息
// @Description 获取球员账户信息
// @Tags 球员账户信息
// @Param id path string false "id"
haoyanbin's avatar
haoyanbin committed
62
// @Success 200 {string} string "{"code": 200,"msg":"更新成功","data":{}}"
haoyanbin's avatar
1  
haoyanbin committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
// @Router /api/v1/org-player-user/{id} [get]
// @Security Bearer
func (e OrgPlayerUser) Get(c *gin.Context) {
	req := dto.OrgPlayerUserGetReq{}
	s := service.OrgPlayerUser{}
    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.OrgPlayerUser

	p := actions.GetPermissionFromContext(c)
	err = s.Get(&req, p, &object)
	if err != nil {
		e.Error(500, err, fmt.Sprintf("获取球员账户信息失败,\r\n失败信息 %s", err.Error()))
        return
	}

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

// Insert 创建球员账户信息
// @Summary 创建球员账户信息
// @Description 创建球员账户信息
// @Tags 球员账户信息
// @Accept application/json
// @Product application/json
// @Param data body dto.OrgPlayerUserInsertReq true "data"
haoyanbin's avatar
haoyanbin committed
97
// @Success 200 {string} string  	"{"code": 200, "message": "添加成功"}"
haoyanbin's avatar
1  
haoyanbin committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
// @Router /api/v1/org-player-user [post]
// @Security Bearer
func (e OrgPlayerUser) Insert(c *gin.Context) {
    req := dto.OrgPlayerUserInsertReq{}
    s := service.OrgPlayerUser{}
    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
    }
	// 设置创建人
	req.SetCreateBy(user.GetUserId(c))

	err = s.Insert(&req)
	if err != nil {
		e.Error(500, err, fmt.Sprintf("创建球员账户信息  失败,\r\n失败信息 %s", err.Error()))
        return
	}

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

// Update 修改球员账户信息
// @Summary 修改球员账户信息
// @Description 修改球员账户信息
// @Tags 球员账户信息
// @Accept application/json
// @Product application/json
// @Param data body dto.OrgPlayerUserUpdateReq true "body"
haoyanbin's avatar
haoyanbin committed
132
// @Success 200 {string} string  	"{"code": 200, "message": "修改成功"}"
haoyanbin's avatar
1  
haoyanbin committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
// @Router /api/v1/org-player-user/{id} [put]
// @Security Bearer
func (e OrgPlayerUser) Update(c *gin.Context) {
    req := dto.OrgPlayerUserUpdateReq{}
    s := service.OrgPlayerUser{}
    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
    }
	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()))
        return
	}
	e.OK( req.GetId(), "修改成功")
}

// Delete 删除球员账户信息
// @Summary 删除球员账户信息
// @Description 删除球员账户信息
// @Tags 球员账户信息
// @Param ids body []int false "ids"
haoyanbin's avatar
haoyanbin committed
164
// @Success 200 {string} string	"{"code": 200, "message": "删除成功"}"
haoyanbin's avatar
1  
haoyanbin committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
// @Router /api/v1/org-player-user [delete]
// @Security Bearer
func (e OrgPlayerUser) Delete(c *gin.Context) {
    s := service.OrgPlayerUser{}
    req := dto.OrgPlayerUserDeleteReq{}
    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
    }

	// 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()))
        return
	}
	e.OK( req.GetId(), "删除成功")
}