enhance(response):调整基础响应构建功能。
This commit is contained in:
parent
a09629ee2b
commit
b9b9a9c738
|
@ -96,7 +96,7 @@ func (_UserController) InvalidUserPassword(c *gin.Context) {
|
|||
result.Error(500, err.Error())
|
||||
return
|
||||
}
|
||||
result.QuickJson(http.StatusOK, http.StatusAccepted, "用户密码已经失效", gin.H{"verify": verifyCode})
|
||||
result.Json(http.StatusOK, http.StatusAccepted, "用户密码已经失效", gin.H{"verify": verifyCode})
|
||||
}
|
||||
|
||||
type ResetPasswordFormData struct {
|
||||
|
@ -110,14 +110,18 @@ func (_UserController) ResetUserPassword(c *gin.Context) {
|
|||
resetForm := new(ResetPasswordFormData)
|
||||
c.BindJSON(resetForm)
|
||||
verified, err := service.UserService.VerifyUserPassword(resetForm.Username, resetForm.VerifyCode)
|
||||
if !verified {
|
||||
result.Error(http.StatusUnauthorized, "验证码不正确。")
|
||||
if errors.Is(err, &exceptions.NotFoundError{}) {
|
||||
result.NotFound("指定的用户不存在。")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
result.Error(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
if !verified {
|
||||
result.Error(http.StatusUnauthorized, "验证码不正确。")
|
||||
return
|
||||
}
|
||||
completed, err := service.UserService.ResetUserPassword(resetForm.Username, resetForm.NewPassword)
|
||||
if err != nil {
|
||||
result.Error(http.StatusInternalServerError, err.Error())
|
||||
|
@ -127,5 +131,5 @@ func (_UserController) ResetUserPassword(c *gin.Context) {
|
|||
result.Success("用户凭据已更新。")
|
||||
return
|
||||
}
|
||||
result.Error(http.StatusNotAcceptable, "用户凭据未能成功更新。")
|
||||
result.NotAccept("用户凭据未能成功更新。")
|
||||
}
|
||||
|
|
|
@ -15,6 +15,12 @@ type BaseResponse struct {
|
|||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type PagedResponse struct {
|
||||
Page int `json:"page"`
|
||||
Size int `json:"pageSize"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
func NewResult(ctx *gin.Context) *Result {
|
||||
return &Result{Ctx: ctx}
|
||||
}
|
||||
|
@ -77,7 +83,7 @@ func (r *Result) NotFound(msg string) {
|
|||
|
||||
// 快速自由JSON格式响应
|
||||
// ! 注意,给定的map中,同名的键会被覆盖。
|
||||
func (r *Result) QuickJson(status, code int, msg string, payloads ...map[string]interface{}) {
|
||||
func (r *Result) Json(status, code int, msg string, payloads ...map[string]interface{}) {
|
||||
var finalPayload = make(map[string]interface{}, 0)
|
||||
finalPayload["code"] = code
|
||||
finalPayload["message"] = &msg
|
||||
|
|
Loading…
Reference in New Issue
Block a user