feat: register logic refactor

This commit is contained in:
merlin
2025-11-17 18:02:58 +08:00
parent 575041905b
commit 23cb31d4fe
45 changed files with 768 additions and 70 deletions

View File

@@ -10,23 +10,23 @@ import java.time.LocalDateTime;
@NoArgsConstructor
@AllArgsConstructor
public class Response<T> {
private int code;
private String code;
private String message;
private T data;
// 请求成功
public static <T> Response<T> success(ResultCode code , T data){
System.out.println( LocalDateTime.now()+" success : \n"+code);
System.out.println( LocalDateTime.now()+" success : "+code);
return new Response<T>(code.getCode(), code.getMessage(), data);
}
public static <T> Response<T> success(ResultCode code){
System.out.println( LocalDateTime.now()+" success : \n"+code);
System.out.println( LocalDateTime.now()+" success : "+code);
return new Response<T>(code.getCode(), code.getMessage(),null);
}
// 请求失败
public static <T> Response<T> fail(ResultCode code){
System.out.println( LocalDateTime.now()+" fail : \n"+code);
System.out.println( LocalDateTime.now()+" fail : "+code);
return new Response<T>(code.getCode(),code.getMessage(), null);
}

View File

@@ -8,29 +8,42 @@ import lombok.Getter;
@Getter
public enum ResultCode {
SUCCESS(200, "成功"),
BAD_REQUEST(400, "请求参数错误"),
UNAUTHORIZED(401, "未认证或登录已过期"),
FORBIDDEN(403, "无权限访问"),
NOT_FOUND(404, "资源不存在"),
SERVER_ERROR(500, "服务器内部错误"),
SUCCESS("200", "成功"),
BAD_REQUEST("400", "请求参数错误"),
UNAUTHORIZED("401", "未认证或登录已过期"),
FORBIDDEN("403", "无权限访问"),
NOT_FOUND("404", "资源不存在"),
SERVER_ERROR("500", "服务器内部错误"),
// 自定义业务错误码
USER_BANNED(1000,"用户被封禁"),
USER_NOT_FOUND(1001, "用户不存在"),
USER_EXIST(1003,"户已存在"),
USER_PASSWORD_ERROR(1004,"用户密码错误"),
USER_VERIFICATION_ERROR(1005,"验证码不存在或错误"),
USER_SEND_TOO_FAST(1006,"用户请求过快"),
USER_SEND_TOO_OFTEN(1007,"请求次数过多,已被限制"),
ORDER_NOT_FOUND(2000, "订单不存在");
//账户相关
ACCOUNT_EXIST("2001","户已存在"),
//用户相关
USER_BANNED("4000","用户被封禁"),
USER_NOT_FOUND("4001", "用户不存在"),
USER_EXIST("4003","用户已存在"),
USER_PASSWORD_ERROR("4004","用户密码错误"),
USER_VERIFICATION_ERROR("4005","验证码不存在或错误"),
USER_SEND_TOO_FAST("4006","用户请求过快"),
USER_SEND_TOO_OFTEN("4007","请求次数过多,已被限制"),
ORDER_NOT_FOUND("4000", "订单不存在"),
//邮箱相关
MAIL_ACCOUNT_NOT_PROVIDED("4101","未提供验证码接受账户"),
MAIL_REQUEST_TOO_FAST("4102","验证码请求过于频繁"),
MAIL_INFO_LOST("4103","验证信息丢失"),
MAIL_VERIFY_FAIL_TOO_MANY("4104","验证码错误过多,请重新申请验证码"),
MAIL_VERIFY_NOT_EXIST("4105","验证码元素丢失,请重新申请验证码"),
MAIL_VERIFY_CODE_ERROR("4106","验证码错误,请重新输入");
private final int code;
private final String code;
private final String message;
ResultCode(int code, String message) {
ResultCode(String code, String message) {
this.code = code;
this.message = message;
}