123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package menu
- import (
- "net/http"
- "github.com/xinliangnote/go-gin-api/internal/code"
- "github.com/xinliangnote/go-gin-api/internal/pkg/core"
- )
- type updateUsedRequest struct {
- Id string `form:"id"` // 主键ID
- Used int32 `form:"used"` // 是否启用 1:是 -1:否
- }
- type updateUsedResponse struct {
- Id int32 `json:"id"` // 主键ID
- }
- // UpdateUsed 更新菜单为启用/禁用
- // @Summary 更新菜单为启用/禁用
- // @Description 更新菜单为启用/禁用
- // @Tags API.menu
- // @Accept application/x-www-form-urlencoded
- // @Produce json
- // @Param id formData string true "hashId"
- // @Param used formData int true "是否启用 1:是 -1:否"
- // @Success 200 {object} updateUsedResponse
- // @Failure 400 {object} code.Failure
- // @Router /api/menu/used [patch]
- // @Security LoginToken
- func (h *handler) UpdateUsed() core.HandlerFunc {
- return func(c core.Context) {
- req := new(updateUsedRequest)
- res := new(updateUsedResponse)
- if err := c.ShouldBindForm(req); err != nil {
- c.AbortWithError(core.Error(
- http.StatusBadRequest,
- code.ParamBindError,
- code.Text(code.ParamBindError)).WithError(err),
- )
- return
- }
- ids, err := h.hashids.HashidsDecode(req.Id)
- if err != nil {
- c.AbortWithError(core.Error(
- http.StatusBadRequest,
- code.HashIdsDecodeError,
- code.Text(code.HashIdsDecodeError)).WithError(err),
- )
- return
- }
- id := int32(ids[0])
- err = h.menuService.UpdateUsed(c, id, req.Used)
- if err != nil {
- c.AbortWithError(core.Error(
- http.StatusBadRequest,
- code.MenuUpdateError,
- code.Text(code.MenuUpdateError)).WithError(err),
- )
- return
- }
- res.Id = id
- c.Payload(res)
- }
- }
|