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

Feat: 사용자 존재 여부 체크 #22

Merged
merged 1 commit into from
Nov 3, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -78,4 +79,19 @@ public RspTemplate<ProfileResDto> updateProfile(
ProfileResDto updatedProfile = memberService.updateProfile(principal, reqDto);
return new RspTemplate<>(HttpStatus.OK, "프로필 수정 성공", updatedProfile);
}

@PostMapping("/check-duplicate")
@Operation(
summary = "이메일 중복 검사",
description = "해당 사용자가 존재하는지 여부를 검사합니다.",
responses = {
@ApiResponse(responseCode = "200", description = "중복 검사 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청"),
@ApiResponse(responseCode = "500", description = "서버 오류")
}
)
public RspTemplate<String> checkDuplicateRequest(Principal principal) {
boolean isDuplicate = memberService.checkDuplicate(principal);
return new RspTemplate<>(HttpStatus.OK, String.valueOf(isDuplicate));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public ProfileResDto updateProfile(Principal principal, UpdateProfileReqDto reqD
return ProfileResDto.from(member);
}

public boolean checkDuplicate(Principal principal) {
Member member = getMemberByPrincipal(principal);
return memberRepository.existsById(member.getId());
}

private Member getMemberByPrincipal(Principal principal) {
Long memberId = Long.parseLong(principal.getName());
return memberRepository.findById(memberId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
@Repository
public interface MemberRepository extends JpaRepository<Member, Long> {


Optional<Member> findByEmail(String email);
}