mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-10-06 06:46:10 +00:00
192 lines
4.6 KiB
Go
192 lines
4.6 KiB
Go
package apis
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"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"
|
|
|
|
"go-admin/app/admin/models"
|
|
"go-admin/app/admin/service"
|
|
"go-admin/app/admin/service/dto"
|
|
)
|
|
|
|
type SysPost struct {
|
|
api.Api
|
|
}
|
|
|
|
// GetSysPostList
|
|
// @Summary 岗位列表数据
|
|
// @Description 获取JSON
|
|
// @Tags 岗位
|
|
// @Param postName query string false "postName"
|
|
// @Param postCode query string false "postCode"
|
|
// @Param postId query string false "postId"
|
|
// @Param status query string false "status"
|
|
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
|
|
// @Router /api/v1/post [get]
|
|
// @Security Bearer
|
|
func (e SysPost) GetSysPostList(c *gin.Context) {
|
|
s := new(service.SysPost)
|
|
req := new(dto.SysPostSearch)
|
|
err := e.MakeContext(c).
|
|
MakeOrm().
|
|
Bind(req).
|
|
MakeService(&s.Service).
|
|
Errors
|
|
if err != nil {
|
|
e.Error(http.StatusInternalServerError, err, err.Error())
|
|
e.Logger.Error(err)
|
|
return
|
|
}
|
|
|
|
list := make([]models.SysPost, 0)
|
|
var count int64
|
|
|
|
err = s.GetSysPostPage(req, &list, &count)
|
|
if err != nil {
|
|
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
|
}
|
|
|
|
// GetSysPost
|
|
// @Summary 获取岗位信息
|
|
// @Description 获取JSON
|
|
// @Tags 岗位
|
|
// @Param postId path int true "postId"
|
|
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
|
|
// @Router /api/v1/post/{postId} [get]
|
|
// @Security Bearer
|
|
func (e SysPost) GetSysPost(c *gin.Context) {
|
|
s := new(service.SysPost)
|
|
req := new(dto.SysPostById)
|
|
err := e.MakeContext(c).
|
|
MakeOrm().
|
|
Bind(req).
|
|
MakeService(&s.Service).
|
|
Errors
|
|
if err != nil {
|
|
e.Error(http.StatusInternalServerError, err, err.Error())
|
|
e.Logger.Error(err)
|
|
return
|
|
}
|
|
var object models.SysPost
|
|
|
|
err = s.GetSysPost(req, &object)
|
|
if err != nil {
|
|
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
|
|
return
|
|
}
|
|
|
|
e.OK(object, "查看成功")
|
|
}
|
|
|
|
// InsertSysPost
|
|
// @Summary 添加岗位
|
|
// @Description 获取JSON
|
|
// @Tags 岗位
|
|
// @Accept application/json
|
|
// @Product application/json
|
|
// @Param data body dto.SysPostControl true "data"
|
|
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
|
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
|
// @Router /api/v1/post [post]
|
|
// @Security Bearer
|
|
func (e SysPost) InsertSysPost(c *gin.Context) {
|
|
s := new(service.SysPost)
|
|
req := new(dto.SysPostControl)
|
|
err := e.MakeContext(c).
|
|
MakeOrm().
|
|
Bind(req).
|
|
MakeService(&s.Service).
|
|
Errors
|
|
if err != nil {
|
|
e.Error(http.StatusInternalServerError, err, err.Error())
|
|
e.Logger.Error(err)
|
|
return
|
|
}
|
|
|
|
// 设置创建人
|
|
req.SetCreateBy(user.GetUserId(c))
|
|
|
|
err = s.InsertSysPost(req)
|
|
if err != nil {
|
|
e.Logger.Error(err)
|
|
e.Error(http.StatusInternalServerError, err, "创建失败")
|
|
return
|
|
}
|
|
|
|
e.OK(req.GetId(), "创建成功")
|
|
}
|
|
|
|
// UpdateSysPost
|
|
// @Summary 修改岗位
|
|
// @Description 获取JSON
|
|
// @Tags 岗位
|
|
// @Accept application/json
|
|
// @Product application/json
|
|
// @Param data body dto.SysPostControl true "body"
|
|
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
|
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
|
// @Router /api/v1/post/ [put]
|
|
// @Security Bearer
|
|
func (e SysPost) UpdateSysPost(c *gin.Context) {
|
|
s := new(service.SysPost)
|
|
req := new(dto.SysPostControl)
|
|
err := e.MakeContext(c).
|
|
MakeOrm().
|
|
Bind(req).
|
|
MakeService(&s.Service).
|
|
Errors
|
|
if err != nil {
|
|
e.Error(http.StatusInternalServerError, err, err.Error())
|
|
e.Logger.Error(err)
|
|
return
|
|
}
|
|
|
|
req.SetUpdateBy(user.GetUserId(c))
|
|
|
|
err = s.UpdateSysPost(req)
|
|
if err != nil {
|
|
e.Logger.Error(err)
|
|
return
|
|
}
|
|
e.OK(req.GetId(), "更新成功")
|
|
}
|
|
|
|
// DeleteSysPost
|
|
// @Summary 删除岗位
|
|
// @Description 删除数据
|
|
// @Tags 岗位
|
|
// @Param id path int true "id"
|
|
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
|
// @Success 500 {string} string "{"code": 500, "message": "删除失败"}"
|
|
// @Router /api/v1/post/{postId} [delete]
|
|
func (e SysPost) DeleteSysPost(c *gin.Context) {
|
|
s := new(service.SysPost)
|
|
req := new(dto.SysPostById)
|
|
err := e.MakeContext(c).
|
|
MakeOrm().
|
|
Bind(req).
|
|
MakeService(&s.Service).
|
|
Errors
|
|
if err != nil {
|
|
e.Error(http.StatusInternalServerError, err, err.Error())
|
|
e.Logger.Error(err)
|
|
return
|
|
}
|
|
req.SetUpdateBy(user.GetUserId(c))
|
|
|
|
err = s.RemoveSysPost(req)
|
|
if err != nil {
|
|
e.Logger.Error(err)
|
|
return
|
|
}
|
|
e.OK(req.GetId(), "删除成功")
|
|
}
|