修复go的验证库把int的0当作无值的情况
This commit is contained in:
@@ -219,7 +219,7 @@ func (h *RoleHandler) UpdateStatus(c *fiber.Ctx) error {
|
||||
return errors.New(errors.CodeInvalidParam)
|
||||
}
|
||||
|
||||
if err := h.service.UpdateStatus(c.UserContext(), uint(id), req.Status); err != nil {
|
||||
if err := h.service.UpdateStatus(c.UserContext(), uint(id), *req.Status); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ type RemovePermissionParams struct {
|
||||
|
||||
// UpdateRoleStatusRequest 更新角色状态请求
|
||||
type UpdateRoleStatusRequest struct {
|
||||
Status int `json:"status" validate:"required,min=0,max=1" required:"true" minimum:"0" maximum:"1" description:"状态 (0:禁用, 1:启用)"`
|
||||
Status *int `json:"status" validate:"required,min=0,max=1" description:"状态 (0:禁用, 1:启用)"`
|
||||
}
|
||||
|
||||
// UpdateRoleStatusParams 更新角色状态参数聚合
|
||||
|
||||
@@ -225,7 +225,7 @@ func TestRoleAPI_UpdateStatus(t *testing.T) {
|
||||
|
||||
t.Run("成功禁用角色", func(t *testing.T) {
|
||||
reqBody := dto.UpdateRoleStatusRequest{
|
||||
Status: constants.StatusDisabled,
|
||||
Status: intPtr(constants.StatusDisabled),
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
@@ -245,7 +245,7 @@ func TestRoleAPI_UpdateStatus(t *testing.T) {
|
||||
|
||||
t.Run("成功启用角色", func(t *testing.T) {
|
||||
reqBody := dto.UpdateRoleStatusRequest{
|
||||
Status: constants.StatusEnabled,
|
||||
Status: intPtr(constants.StatusEnabled),
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
@@ -265,7 +265,7 @@ func TestRoleAPI_UpdateStatus(t *testing.T) {
|
||||
|
||||
t.Run("角色不存在返回错误", func(t *testing.T) {
|
||||
reqBody := dto.UpdateRoleStatusRequest{
|
||||
Status: constants.StatusEnabled,
|
||||
Status: intPtr(constants.StatusEnabled),
|
||||
}
|
||||
|
||||
jsonBody, _ := json.Marshal(reqBody)
|
||||
@@ -278,3 +278,8 @@ func TestRoleAPI_UpdateStatus(t *testing.T) {
|
||||
assert.Equal(t, errors.CodeRoleNotFound, result.Code)
|
||||
})
|
||||
}
|
||||
|
||||
// intPtr 返回 int 的指针
|
||||
func intPtr(v int) *int {
|
||||
return &v
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user