From 2f08a20d812c0f73bc2ee4d90b410da02f5a43bc Mon Sep 17 00:00:00 2001 From: liyusang1 Date: Fri, 5 Jan 2024 20:23:15 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20check-duplicated-email=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit check-duplicated-email 추가 --- .../domain/member/controller/MemberController.java | 11 +++++++++++ .../domain/member/service/MemberService.java | 10 ++++++++-- .../global/springsecurity/SpringSecurityConfig.java | 1 + src/test/http/member/signup.http | 8 ++++++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/haejwo/tripcometrue/domain/member/controller/MemberController.java b/src/main/java/com/haejwo/tripcometrue/domain/member/controller/MemberController.java index 9a44eae6..d524b67d 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/member/controller/MemberController.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/member/controller/MemberController.java @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -46,4 +47,14 @@ public ResponseEntity> test( .status(response.getCode()) .body(response); } + + @GetMapping("/check-duplicated-email") + public ResponseEntity> checkDuplicateEmail( + @RequestParam String email) { + memberService.checkDuplicateEmail(email); + ResponseDTO response = ResponseDTO.ok(); + return ResponseEntity + .status(response.getCode()) + .body(response); + } } \ No newline at end of file diff --git a/src/main/java/com/haejwo/tripcometrue/domain/member/service/MemberService.java b/src/main/java/com/haejwo/tripcometrue/domain/member/service/MemberService.java index b73510a7..d26399a4 100644 --- a/src/main/java/com/haejwo/tripcometrue/domain/member/service/MemberService.java +++ b/src/main/java/com/haejwo/tripcometrue/domain/member/service/MemberService.java @@ -1,10 +1,10 @@ package com.haejwo.tripcometrue.domain.member.service; +import com.haejwo.tripcometrue.domain.member.dto.request.SignUpRequestDto; +import com.haejwo.tripcometrue.domain.member.dto.response.SignUpResponseDto; import com.haejwo.tripcometrue.domain.member.entity.Member; import com.haejwo.tripcometrue.domain.member.exception.EmailDuplicateException; import com.haejwo.tripcometrue.domain.member.repository.MemberRepository; -import com.haejwo.tripcometrue.domain.member.dto.request.SignUpRequestDto; -import com.haejwo.tripcometrue.domain.member.dto.response.SignUpResponseDto; import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; @@ -30,4 +30,10 @@ public SignUpResponseDto signup(SignUpRequestDto signUpRequestDto) { memberRepository.save(newMember); return SignUpResponseDto.fromEntity(newMember); } + + public void checkDuplicateEmail(String email) { + memberRepository.findByMemberBaseEmail(email).ifPresent(user -> { + throw new EmailDuplicateException(); + }); + } } \ No newline at end of file diff --git a/src/main/java/com/haejwo/tripcometrue/global/springsecurity/SpringSecurityConfig.java b/src/main/java/com/haejwo/tripcometrue/global/springsecurity/SpringSecurityConfig.java index 466dacd8..c97d87bd 100644 --- a/src/main/java/com/haejwo/tripcometrue/global/springsecurity/SpringSecurityConfig.java +++ b/src/main/java/com/haejwo/tripcometrue/global/springsecurity/SpringSecurityConfig.java @@ -67,6 +67,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, .requestMatchers(new AntPathRequestMatcher("/login/**")).permitAll() .requestMatchers(new AntPathRequestMatcher("/v1/member/signup")).permitAll() .requestMatchers(new AntPathRequestMatcher("/v1/member/test/jwt")).permitAll() + .requestMatchers(new AntPathRequestMatcher("/v1/member/check-duplicated-email")).permitAll() .requestMatchers(new AntPathRequestMatcher("/v1/places/**")).permitAll() .anyRequest().authenticated()); diff --git a/src/test/http/member/signup.http b/src/test/http/member/signup.http index 6ed0b546..a246c257 100644 --- a/src/test/http/member/signup.http +++ b/src/test/http/member/signup.http @@ -3,7 +3,11 @@ POST http://localhost:8080/v1/member/signup Content-Type: application/json { - "email": "test11@naver.com", + "email": "test1@naver.com", "password": "123456", "nickname": "testusername" -} \ No newline at end of file +} + +### 이메일 중복 체크 +GET http://localhost:8080/v1/member/check-duplicated-email?email=test1@naver.com +Content-Type: application/json \ No newline at end of file