package admin_role import ( "github.com/gin-gonic/gin" "net/http" "sghgogs.com/micro/auth-client/model/base" "sghgogs.com/micro/auth-client/response" "sghgogs.com/micro/auth-client/utils" pb "sghgogs.com/micro/auth-service/proto" "sghgogs.com/micro/common" "strconv" ) type ToggleRequest struct { Status base.Status `json:"status" binding:"required"` // "enabled"|"disabled" } // ToggleAdminRole // @summary 启用/禁用 // @Tags Role 角色管理 // @Accept json // @Produce json // @Param Authorization header string true "Bearer 用户令牌" // @Param body body ToggleRequest true "请求body" // @Success 200 {object} response.ApiResponse "成功" // @Failure 400 {object} response.ApiResponse "请求错误" // @Failure 500 {object} response.ApiResponse "内部错误" // @Router /v1/api/admin/role/{roleID}/toggle [put] func (svc *ApiAdminRole) ToggleAdminRole(c *gin.Context) { var req ToggleRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, err.Error())) return } RoleID, err := strconv.ParseInt(c.Param("roleID"), 10, 64) if err != nil || RoleID <= 0 { c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, common.ErrorMessage[common.InvalidRoleID])) return } enum, err := base.MapStatusToEnum(req.Status) if err != nil { c.JSON(http.StatusBadRequest, response.ErrorResponse(http.StatusBadRequest, common.ErrorMessage[common.StatusIsNotValid])) return } ctx, _ := utils.CreateContextWithToken(c, "authorizationservice", "AdminRoleService.ToggleAdminRole") _, err = svc.Service.ToggleAdminRole(ctx, &pb.ToggleAdminRoleRequest{ RoleId: RoleID, Status: enum, }) if err != nil { code, mgs := response.MicroErrorRequest(err) c.JSON(code, response.ErrorResponse(code, mgs)) return } c.JSON(http.StatusOK, response.SuccessResponse(nil)) }