Skip to content

Commit

Permalink
[feat] check-duplicated-email 추가
Browse files Browse the repository at this point in the history
check-duplicated-email 추가
  • Loading branch information
liyusang1 committed Jan 5, 2024
1 parent 071816b commit 2f08a20
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -46,4 +47,14 @@ public ResponseEntity<ResponseDTO<TestUserResponseDto>> test(
.status(response.getCode())
.body(response);
}

@GetMapping("/check-duplicated-email")
public ResponseEntity<ResponseDTO<Void>> checkDuplicateEmail(
@RequestParam String email) {
memberService.checkDuplicateEmail(email);
ResponseDTO<Void> response = ResponseDTO.ok();
return ResponseEntity
.status(response.getCode())
.body(response);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 6 additions & 2 deletions src/test/http/member/signup.http
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

### 이메일 중복 체크
GET http://localhost:8080/v1/member/check-duplicated-email?email=test1@naver.com
Content-Type: application/json

0 comments on commit 2f08a20

Please sign in to comment.