Skip to content

Commit

Permalink
Feat: 사용자 존재 여부 체크 (moyeothon#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
kduoh99 committed Nov 3, 2024
1 parent 6f626ce commit f5d5a63
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
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);
}

0 comments on commit f5d5a63

Please sign in to comment.