diff --git a/backend/src/docs/member.adoc b/backend/src/docs/member.adoc new file mode 100644 index 00000000..bad4a425 --- /dev/null +++ b/backend/src/docs/member.adoc @@ -0,0 +1,6 @@ +:doctype: book +:icons: font +:source-highlighter: highlightjs +:toc: left +:toclevels: 4 + diff --git a/backend/src/main/java/com/twtw/backend/domain/member/controller/MemberController.java b/backend/src/main/java/com/twtw/backend/domain/member/controller/MemberController.java index bd908d49..d6a73b62 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/controller/MemberController.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/controller/MemberController.java @@ -1,7 +1,11 @@ package com.twtw.backend.domain.member.controller; +import com.twtw.backend.domain.member.dto.response.DuplicateNicknameDto; import com.twtw.backend.domain.member.service.MemberService; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -13,4 +17,9 @@ public class MemberController { public MemberController(MemberService memberService) { this.memberService = memberService; } + + @GetMapping("/duplicate/{name}") + public ResponseEntity duplicateNickname(@PathVariable String name) { + return ResponseEntity.ok(memberService.duplicateNickname(name)); + } } diff --git a/backend/src/main/java/com/twtw/backend/domain/member/dto/response/DuplicateNicknameDto.java b/backend/src/main/java/com/twtw/backend/domain/member/dto/response/DuplicateNicknameDto.java new file mode 100644 index 00000000..3ab97e27 --- /dev/null +++ b/backend/src/main/java/com/twtw/backend/domain/member/dto/response/DuplicateNicknameDto.java @@ -0,0 +1,12 @@ +package com.twtw.backend.domain.member.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class DuplicateNicknameDto { + private Boolean isPresent; +} diff --git a/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java b/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java index 7ad4a864..cf99b679 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/repository/MemberRepository.java @@ -12,6 +12,8 @@ public interface MemberRepository extends JpaRepository { Optional findById(UUID uuid); + Optional findByNickname(String nickName); + @Query( "SELECT m FROM Member m WHERE m.oAuth2Info.clientId = :oAuthId AND" + " m.oAuth2Info.authType = :authType") diff --git a/backend/src/main/java/com/twtw/backend/domain/member/service/MemberService.java b/backend/src/main/java/com/twtw/backend/domain/member/service/MemberService.java index 535d48cc..c4f5ccfb 100644 --- a/backend/src/main/java/com/twtw/backend/domain/member/service/MemberService.java +++ b/backend/src/main/java/com/twtw/backend/domain/member/service/MemberService.java @@ -1,9 +1,15 @@ package com.twtw.backend.domain.member.service; +import com.twtw.backend.domain.member.dto.response.DuplicateNicknameDto; +import com.twtw.backend.domain.member.entity.Member; import com.twtw.backend.domain.member.repository.MemberRepository; +import com.twtw.backend.global.exception.EntityNotFoundException; import org.springframework.stereotype.Service; +import java.util.Optional; +import java.util.UUID; + @Service public class MemberService { private final MemberRepository memberRepository; @@ -11,4 +17,20 @@ public class MemberService { public MemberService(MemberRepository memberRepository) { this.memberRepository = memberRepository; } + + public DuplicateNicknameDto duplicateNickname(String nickName) { + Optional member = memberRepository.findByNickname(nickName); + + if (member.isPresent()) { + return new DuplicateNicknameDto(true); + } + + return new DuplicateNicknameDto(false); + } + + public Member getMemberById(UUID id) { + Member member = memberRepository.findById(id).orElseThrow(EntityNotFoundException::new); + + return member; + } }