Skip to content

Commit ebdf344

Browse files
authored
[SSD-147] refactor: 요청 DTO validation 및 응답 공통화 (#86)
1 parent ab88480 commit ebdf344

File tree

16 files changed

+60
-54
lines changed

16 files changed

+60
-54
lines changed

backend/src/main/java/com/timepaper/backend/domain/postit/dto/PostitCreateRequestDto.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
public class PostitCreateRequestDto {
1414

1515
@NotEmpty
16-
@Length(max = 20)
16+
@Length(max = 20, message = "작성자 이름은 최대 20자까지 입력할 수 있습니다.")
1717
private String authorName;
1818

1919
@NotEmpty
20-
@Length(max = 155)
20+
@Length(max = 155, message = "내용은 최대 155자까지 입력할 수 있습니다.")
2121
private String content;
2222

2323
private String imageUrl;

backend/src/main/java/com/timepaper/backend/domain/timepaper/controller/TimePaperController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.timepaper.backend.domain.timepaper.service.TimePaperService;
88
import com.timepaper.backend.domain.user.entity.User;
99
import com.timepaper.backend.global.dto.ApiResponse;
10+
import jakarta.validation.Valid;
1011
import java.util.UUID;
1112
import lombok.RequiredArgsConstructor;
1213
import lombok.extern.slf4j.Slf4j;
@@ -33,7 +34,7 @@ public class TimePaperController {
3334

3435
@PostMapping
3536
public ResponseEntity<ApiResponse<TimePaperResponseDto>> createTimePaper(
36-
@RequestBody TimePaperCreateRequestDto timePaperCreateRequestDto,
37+
@Valid @RequestBody TimePaperCreateRequestDto timePaperCreateRequestDto,
3738
Authentication authentication) {
3839

3940
TimePaperResponseDto responseDto =
@@ -72,7 +73,7 @@ public ResponseEntity<ApiResponse<Void>> deleteTimePaper(@PathVariable UUID time
7273
@PatchMapping("/{timePaperId}/lock")
7374
public ResponseEntity<ApiResponse<TimePaperLockResponseDto>> lockTimePaper(
7475
@PathVariable UUID timePaperId,
75-
@RequestBody TimePaperLockRequestDto timePaperLockRequestDto,
76+
@RequestBody @Valid TimePaperLockRequestDto timePaperLockRequestDto,
7677
@AuthenticationPrincipal User requester
7778
) {
7879

backend/src/main/java/com/timepaper/backend/domain/timepaper/dto/request/TimePaperLockRequestDto.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ public class TimePaperLockRequestDto {
2222
private LocalDateTime releaseDate;
2323

2424

25-
2625
}

backend/src/main/java/com/timepaper/backend/domain/user/dto/request/LoginRequestDto.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.timepaper.backend.domain.user.dto.request;
22

3+
import jakarta.validation.constraints.NotBlank;
34
import lombok.Getter;
45
import lombok.NoArgsConstructor;
56
import lombok.Setter;
@@ -9,7 +10,9 @@
910
@NoArgsConstructor
1011
public class LoginRequestDto {
1112

13+
@NotBlank(message = "이메일 입력은 필수입니다.")
1214
private String email;
15+
@NotBlank(message = "비밀번호 입력은 필수입니다.")
1316
private String password;
1417

1518
}

backend/src/main/java/com/timepaper/backend/domain/user/dto/request/SignUpRequestDto.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

backend/src/main/java/com/timepaper/backend/global/auth/controller/AuthController.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import com.timepaper.backend.global.auth.dto.CertificationNumberRequestDto;
44
import com.timepaper.backend.global.auth.dto.EmailCertificationRequestDto;
5-
import com.timepaper.backend.global.auth.dto.SignupDto;
5+
import com.timepaper.backend.global.auth.dto.SignupRequestDto;
66
import com.timepaper.backend.global.auth.service.AuthService;
77
import com.timepaper.backend.global.dto.ApiResponse;
88
import jakarta.servlet.http.HttpServletResponse;
9+
import jakarta.validation.Valid;
910
import lombok.RequiredArgsConstructor;
1011
import lombok.extern.slf4j.Slf4j;
1112
import org.springframework.http.HttpStatus;
1213
import org.springframework.http.ResponseEntity;
1314
import org.springframework.security.core.Authentication;
14-
import org.springframework.validation.annotation.Validated;
1515
import org.springframework.web.bind.annotation.CookieValue;
1616
import org.springframework.web.bind.annotation.PostMapping;
1717
import org.springframework.web.bind.annotation.RequestBody;
@@ -30,21 +30,20 @@ public class AuthController {
3030
public void reissueToken(HttpServletResponse response,
3131
@CookieValue(value = "refresh_token", required = true) String refreshToken) {
3232

33-
log.info("refreshToken : {}", refreshToken);
3433
authService.reissueToken(response, refreshToken);
3534
}
3635

3736
@PostMapping("/auth/logout")
3837
public void logout(HttpServletResponse response,
3938
@CookieValue(value = "refresh_token", required = false) String refreshToken,
4039
Authentication authentication) {
41-
log.info("refreshToken : {}", refreshToken);
40+
4241
authService.logout(response, refreshToken, authentication);
4342
}
4443

4544
@PostMapping("/auth/email-verification-codes")
4645
public ResponseEntity<ApiResponse<Void>> requestEmailVerificationCode(
47-
@RequestBody @Validated EmailCertificationRequestDto dto
46+
@RequestBody @Valid EmailCertificationRequestDto dto
4847
) {
4948
authService.requestEmailVerificationCode(dto);
5049

@@ -54,7 +53,7 @@ public ResponseEntity<ApiResponse<Void>> requestEmailVerificationCode(
5453

5554
@PostMapping("/auth/email-verification-codes/validate")
5655
public ResponseEntity<ApiResponse<Boolean>> checkEmailVerificationCode(
57-
@RequestBody CertificationNumberRequestDto dto
56+
@RequestBody @Valid CertificationNumberRequestDto dto
5857
) {
5958
authService.checkEmailVerificationCode(dto);
6059

@@ -63,7 +62,7 @@ public ResponseEntity<ApiResponse<Boolean>> checkEmailVerificationCode(
6362
}
6463

6564
@PostMapping("/auth/signup")
66-
public ResponseEntity<ApiResponse<Boolean>> signUp(@RequestBody @Validated SignupDto dto) {
65+
public ResponseEntity<ApiResponse<Boolean>> signUp(@RequestBody @Valid SignupRequestDto dto) {
6766
authService.signUp(dto);
6867

6968
return ResponseEntity.status(HttpStatus.NO_CONTENT)

backend/src/main/java/com/timepaper/backend/global/auth/dto/CertificationNumberRequestDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CertificationNumberRequestDto {
1111
@NotBlank
1212
private String email;
1313

14-
@NotBlank
14+
@NotBlank(message = "인증 코드는 필수입니다.")
1515
private String authenticationCode;
1616

1717
}

backend/src/main/java/com/timepaper/backend/global/auth/dto/EmailCertificationRequestDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@Getter
88
public class EmailCertificationRequestDto {
99

10-
@NotBlank
10+
@NotBlank(message = "이메일은 필수 입력입니다.")
1111
@Email
1212
private String email;
1313
}

backend/src/main/java/com/timepaper/backend/global/auth/dto/SignupDto.java renamed to backend/src/main/java/com/timepaper/backend/global/auth/dto/SignupRequestDto.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import lombok.Getter;
99

1010
@Getter
11-
public class SignupDto {
11+
public class SignupRequestDto {
1212

13-
@Email
13+
@Email(message = "이메일 형식이 틀렸습니다.")
1414
private String email;
1515

1616
@Pattern(regexp = "^(?=.*[!@#$%^&*]).{8,}$")

backend/src/main/java/com/timepaper/backend/global/auth/filter/LoginFilter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public Authentication attemptAuthentication(HttpServletRequest request,
5151
try {
5252
requestDto = objectMapper.readValue(request.getInputStream(),
5353
LoginRequestDto.class);
54-
5554
} catch (IOException e) {
56-
//여기 예외처리 어떻게 하징
5755
throw new GlobalException(ErrorCode.SERVER_ERROR);
5856
}
5957

@@ -85,7 +83,7 @@ protected void unsuccessfulAuthentication(HttpServletRequest request,
8583
throws IOException, ServletException {
8684

8785
log.info("로그인 검증 실패");
88-
log.info("failed: {}", failed);
86+
log.info("failed : {}", failed);
8987
log.info(failed.getMessage());
9088

9189
ApiResponse<Object> apiResponse = null;

0 commit comments

Comments
 (0)