-
Notifications
You must be signed in to change notification settings - Fork 0
/
func_createadminmenu.go
executable file
·72 lines (63 loc) · 1.85 KB
/
func_createadminmenu.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
62
63
64
65
66
67
68
69
70
71
72
package admin_handler
import (
"net/http"
"github.com/skyzhouzj/xhframwork/internal/api/service/admin_service"
"github.com/skyzhouzj/xhframwork/internal/pkg/code"
"github.com/skyzhouzj/xhframwork/internal/pkg/core"
"github.com/skyzhouzj/xhframwork/pkg/errno"
)
type createAdminMenuRequest struct {
Id string `form:"id"` // HashID
Actions string `form:"actions"` // 功能权限ID,多个用,分割
}
type createAdminMenuResponse struct {
Id int32 `json:"id"` // 主键ID
}
// CreateAdminMenu 提交菜单授权
// @Summary 提交菜单授权
// @Description 提交菜单授权
// @Tags API.admin
// @Accept multipart/form-data
// @Produce json
// @Param id formData string true "Hashid"
// @Param actions formData string true "功能权限ID,多个用,分割"
// @Success 200 {object} createResponse
// @Failure 400 {object} code.Failure
// @Router /api/admin/menu [post]
func (h *handler) CreateAdminMenu() core.HandlerFunc {
return func(c core.Context) {
req := new(createAdminMenuRequest)
res := new(createAdminMenuResponse)
if err := c.ShouldBindForm(req); err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.ParamBindError,
code.Text(code.ParamBindError)).WithErr(err),
)
return
}
ids, err := h.hashids.HashidsDecode(req.Id)
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.HashIdsDecodeError,
code.Text(code.HashIdsDecodeError)).WithErr(err),
)
return
}
createData := new(admin_service.CreateMenuData)
createData.AdminId = int32(ids[0])
createData.Actions = req.Actions
err = h.adminService.CreateMenu(c, createData)
if err != nil {
c.AbortWithError(errno.NewError(
http.StatusBadRequest,
code.AdminMenuCreateError,
code.Text(code.AdminMenuCreateError)).WithErr(err),
)
return
}
res.Id = int32(ids[0])
c.Payload(res)
}
}