Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] 기능 명세서 수정사항 반영 - 회원가입/로그인 #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

implementation 'org.springframework.boot:spring-boot-starter-validation' // 유효성 검사 위해
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sopt.univoice.domain.auth.controller;


import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -50,7 +51,7 @@ public ResponseEntity<UserLoginResponse> signIn(@RequestBody MemberSignInRequest
}

@PostMapping("/signup")
public ResponseEntity<SuccessStatusResponse<Void>> signUp(@ModelAttribute MemberCreateRequest memberCreateRequest) {
public ResponseEntity<SuccessStatusResponse<Void>> signUp(@Valid @ModelAttribute MemberCreateRequest memberCreateRequest) {
System.out.println(memberCreateRequest.toString());


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package sopt.univoice.domain.auth.dto;


import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.*;
import org.springframework.web.multipart.MultipartFile;
@Setter
Expand All @@ -10,23 +14,31 @@
@ToString
public class MemberCreateRequest{

@NotNull
private Long admissionNumber;

@NotEmpty
private String name;

@NotEmpty
private String studentNumber;

@NotEmpty
@Size(min = 5, max = 20)
@Pattern(regexp = "^(?=.*[a-z])(?=.*\\d)(?=.*[!@#$%^&*])[A-Za-z\\d!@#$%^&*]{5,20}$", message = "영문 소문자, 숫자, 특수문자 사용 5~20자 여야 합니다.")
private String email;

@NotEmpty
@Size(min = 8, max = 16)
@Pattern(regexp = "^(?=.*[a-z])(?=.*\\d)(?=.*[!@#$%^&*])[A-Za-z\\d!@#$%^&*]{8,16}$", message = "영문 소문자, 숫자, 특수문자 각각 1개 이상 포함 8~16자 여야 합니다.")
private String password;

@NotNull
MultipartFile studentCardImage;

@NotEmpty
private String universityName;

@NotEmpty
private String departmentName;




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package sopt.univoice.infra.common.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
public class ValidationExceptionHandler {

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<Map<String, String>> handleValidationExceptions(MethodArgumentNotValidException ex) {
Map<String, String> errors = new HashMap<>();
ex.getBindingResult().getFieldErrors().forEach(error ->
errors.put(error.getField(), error.getDefaultMessage())
);
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
}
}
Loading