diff --git a/src/main/java/com/javajober/exception/ApplicationExceptionHandler.java b/src/main/java/com/javajober/exception/ApplicationExceptionHandler.java index a79ddd2b..13d0b13f 100644 --- a/src/main/java/com/javajober/exception/ApplicationExceptionHandler.java +++ b/src/main/java/com/javajober/exception/ApplicationExceptionHandler.java @@ -1,6 +1,7 @@ package com.javajober.exception; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MissingPathVariableException; import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -42,4 +43,9 @@ public ResponseEntity handleMethodArgumentTypeMisma log.error(e.getMessage()); return ApiResponse.invalidResponse(ApiStatus.OBJECT_EMPTY, e.getMessage()); } + + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity handleMethodArgumentNotValidException(MethodArgumentNotValidException e) { + return ApiResponse.invalidResponse(ApiStatus.INVALID_DATA, e.getMessage()); + } } \ No newline at end of file diff --git a/src/main/java/com/javajober/member/controller/MemberController.java b/src/main/java/com/javajober/member/controller/MemberController.java index 1aeaddcd..b6b89918 100644 --- a/src/main/java/com/javajober/member/controller/MemberController.java +++ b/src/main/java/com/javajober/member/controller/MemberController.java @@ -3,7 +3,6 @@ import javax.validation.Valid; import org.springframework.http.ResponseEntity; -import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -24,7 +23,7 @@ @RestController @Validated -@RequestMapping("/members") +@RequestMapping("api/members") public class MemberController { private final MemberService memberService; private final RefreshTokenService refreshTokenService; @@ -36,19 +35,18 @@ public MemberController(MemberService memberService, } @PostMapping("/signup") - public ResponseEntity> signup(@RequestBody @Valid MemberSignupRequest memberSignupRequest, - BindingResult bindingResult) { + public ResponseEntity> signup(@RequestBody @Valid MemberSignupRequest memberSignupRequest) { - MemberSignupResponse data = memberService.signup(memberSignupRequest, bindingResult); + MemberSignupResponse data = memberService.signup(memberSignupRequest); return ApiResponse.response(ApiStatus.OK, "회원가입에 성공했습니다.", data); } @PostMapping("/login") - public ResponseEntity> login(@RequestBody @Valid MemberLoginRequest loginDto, BindingResult bindingResult) { + public ResponseEntity> login(@RequestBody @Valid MemberLoginRequest loginDto) { try { - MemberLoginResponse data = memberService.login(loginDto,bindingResult); + MemberLoginResponse data = memberService.login(loginDto); return ApiResponse.response(ApiStatus.OK, "로그인에 성공했습니다.", data); } catch (IllegalArgumentException e) { diff --git a/src/main/java/com/javajober/member/service/MemberService.java b/src/main/java/com/javajober/member/service/MemberService.java index 8f7508a6..0d7e65e2 100644 --- a/src/main/java/com/javajober/member/service/MemberService.java +++ b/src/main/java/com/javajober/member/service/MemberService.java @@ -5,7 +5,6 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; -import org.springframework.validation.BindingResult; import com.javajober.exception.ApiStatus; import com.javajober.exception.ApplicationException; @@ -35,11 +34,7 @@ public MemberService(MemberRepository memberRepository, PasswordEncoder password } @Transactional - public MemberSignupResponse signup(MemberSignupRequest memberSignupRequest, BindingResult bindingResult) { - if (bindingResult.hasErrors()) { - throw new ApplicationException(ApiStatus.INVALID_DATA, "잘못된 요청입니다."); - } - + public MemberSignupResponse signup(MemberSignupRequest memberSignupRequest) { Member member = memberSignupRequest.toEntity(memberSignupRequest); member.setPassword(passwordEncoder.encode(memberSignupRequest.getPassword())); Member saveMember = memberRepository.save(member); @@ -48,10 +43,7 @@ public MemberSignupResponse signup(MemberSignupRequest memberSignupRequest, Bind } @Transactional - public MemberLoginResponse login(MemberLoginRequest loginDto, BindingResult bindingResult) { - if (bindingResult.hasErrors()) { - throw new ApplicationException(ApiStatus.INVALID_DATA, "잘못된 요청입니다."); - } + public MemberLoginResponse login(MemberLoginRequest loginDto) { Member member = memberRepository.findMember(loginDto.getEmail()); if (!passwordEncoder.matches(loginDto.getPassword(), member.getPassword())) { @@ -66,4 +58,4 @@ public MemberLoginResponse login(MemberLoginRequest loginDto, BindingResult bind return new MemberLoginResponse(member,accessToken,refreshToken); } -} +} \ No newline at end of file diff --git a/src/main/java/com/javajober/security/SecurityConfig.java b/src/main/java/com/javajober/security/SecurityConfig.java index b3a438ab..535ad3c7 100644 --- a/src/main/java/com/javajober/security/SecurityConfig.java +++ b/src/main/java/com/javajober/security/SecurityConfig.java @@ -39,6 +39,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .authorizeRequests() .antMatchers("/members/login").permitAll() .antMatchers("/members/signup").permitAll() + .antMatchers("/healthCheck").permitAll() .anyRequest().authenticated() .and() .exceptionHandling() diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 618b2baa..6e5f7d73 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,3 +1,3 @@ spring: profiles: - active: dev,secret,jwt \ No newline at end of file + active: prod,secret,jwt \ No newline at end of file