增加@getter和@setter注解,去除原有的getter和setter
This commit is contained in:
@ -22,7 +22,7 @@ public class ApiResponse<T> {
|
|||||||
return new ApiResponse<>(true, ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
|
return new ApiResponse<>(true, ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> ApiResponse<T> success() { // 通常也会有一个不带数据的成功响应
|
public static <T> ApiResponse<T> success() {
|
||||||
return new ApiResponse<>(true, ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), null);
|
return new ApiResponse<>(true, ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
|||||||
jwt = authHeader.substring(7);
|
jwt = authHeader.substring(7);
|
||||||
username = jwtService.extractUsername(jwt);
|
username = jwtService.extractUsername(jwt);
|
||||||
|
|
||||||
//如果username为空且认证为空
|
//如果username不为空且认证为空
|
||||||
if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
|
if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
|
||||||
UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
|
UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
|
||||||
if (jwtService.isTokenValid(jwt, userDetails)) {
|
if (jwtService.isTokenValid(jwt, userDetails)) {
|
||||||
|
@ -4,6 +4,11 @@ import jakarta.validation.constraints.Email;
|
|||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
public class LoginDto {
|
public class LoginDto {
|
||||||
|
|
||||||
@NotBlank(message = "邮箱不能为空")
|
@NotBlank(message = "邮箱不能为空")
|
||||||
@ -13,20 +18,4 @@ public class LoginDto {
|
|||||||
@NotBlank(message = "密码不能为空")
|
@NotBlank(message = "密码不能为空")
|
||||||
@Size(min = 6, max = 30, message = "密码长度必须在6到30位之间")
|
@Size(min = 6, max = 30, message = "密码长度必须在6到30位之间")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,11 @@ import jakarta.validation.constraints.NotBlank;
|
|||||||
import jakarta.validation.constraints.Pattern;
|
import jakarta.validation.constraints.Pattern;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
public class RegistrationDto {
|
public class RegistrationDto {
|
||||||
|
|
||||||
//注:username可以为空
|
//注:username可以为空
|
||||||
@ -22,28 +27,4 @@ public class RegistrationDto {
|
|||||||
@NotBlank(message = "密码不能为空")
|
@NotBlank(message = "密码不能为空")
|
||||||
@Size(min = 6, max = 30, message = "密码长度必须在6到30位之间")
|
@Size(min = 6, max = 30, message = "密码长度必须在6到30位之间")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,13 @@
|
|||||||
package co.jp.springp0421.dogdemo.dto;
|
package co.jp.springp0421.dogdemo.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
public class UserDto {
|
public class UserDto {
|
||||||
|
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package co.jp.springp0421.dogdemo.exception;
|
package co.jp.springp0421.dogdemo.exception;
|
||||||
|
|
||||||
import co.jp.springp0421.dogdemo.common.ResultCode;
|
import co.jp.springp0421.dogdemo.common.ResultCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class BusinessException extends RuntimeException {
|
public class BusinessException extends RuntimeException {
|
||||||
|
|
||||||
private final ResultCode resultCode;
|
private final ResultCode resultCode;
|
||||||
@ -26,13 +28,4 @@ public class BusinessException extends RuntimeException {
|
|||||||
this.resultCode = resultCode;
|
this.resultCode = resultCode;
|
||||||
this.detailMessage = null;
|
this.detailMessage = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultCode getResultCode() {
|
|
||||||
return resultCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDetailMessage() {
|
|
||||||
return detailMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -92,33 +92,21 @@ public class GlobalExceptionHandler {
|
|||||||
private HttpStatus determineHttpStatusFromResultCode(ResultCode resultCode) {
|
private HttpStatus determineHttpStatusFromResultCode(ResultCode resultCode) {
|
||||||
if (resultCode == null) return HttpStatus.INTERNAL_SERVER_ERROR;
|
if (resultCode == null) return HttpStatus.INTERNAL_SERVER_ERROR;
|
||||||
|
|
||||||
switch (resultCode) {
|
return switch (resultCode) {
|
||||||
case SUCCESS:
|
case SUCCESS -> HttpStatus.OK;
|
||||||
return HttpStatus.OK;
|
case UNAUTHORIZED, USER_INVALID_CREDENTIALS, USER_TOKEN_INVALID, USER_TOKEN_EXPIRED ->
|
||||||
case UNAUTHORIZED:
|
HttpStatus.UNAUTHORIZED;
|
||||||
case USER_INVALID_CREDENTIALS:
|
case FORBIDDEN -> HttpStatus.FORBIDDEN;
|
||||||
case USER_TOKEN_INVALID:
|
case NOT_FOUND, USER_ACCOUNT_NOT_FOUND, USER_PROFILE_NOT_FOUND -> HttpStatus.NOT_FOUND;
|
||||||
case USER_TOKEN_EXPIRED:
|
case CONFLICT, USER_EMAIL_ALREADY_EXISTS -> HttpStatus.CONFLICT;
|
||||||
return HttpStatus.UNAUTHORIZED;
|
case BAD_REQUEST, VALIDATION_ERROR, USER_PASSWORD_TOO_SHORT -> HttpStatus.BAD_REQUEST;
|
||||||
case FORBIDDEN:
|
default -> {
|
||||||
return HttpStatus.FORBIDDEN;
|
|
||||||
case NOT_FOUND:
|
|
||||||
case USER_ACCOUNT_NOT_FOUND:
|
|
||||||
case USER_PROFILE_NOT_FOUND:
|
|
||||||
return HttpStatus.NOT_FOUND;
|
|
||||||
case CONFLICT:
|
|
||||||
case USER_EMAIL_ALREADY_EXISTS:
|
|
||||||
return HttpStatus.CONFLICT;
|
|
||||||
case BAD_REQUEST:
|
|
||||||
case VALIDATION_ERROR:
|
|
||||||
case USER_PASSWORD_TOO_SHORT:
|
|
||||||
return HttpStatus.BAD_REQUEST;
|
|
||||||
default:
|
|
||||||
if (resultCode.getCode() >= 2000 && resultCode.getCode() < 3000) {
|
if (resultCode.getCode() >= 2000 && resultCode.getCode() < 3000) {
|
||||||
return HttpStatus.INTERNAL_SERVER_ERROR;
|
yield HttpStatus.INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return HttpStatus.BAD_REQUEST;
|
yield HttpStatus.BAD_REQUEST;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user