Skip to content

Commit

Permalink
Merge pull request #31 from HongDam-org/feat/member-duplicate
Browse files Browse the repository at this point in the history
[FEAT] member duplicate
  • Loading branch information
jinjoo-lab authored Oct 6, 2023
2 parents 305e9c1 + 3c8b2cd commit 2109878
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
6 changes: 6 additions & 0 deletions backend/src/docs/member.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:doctype: book
:icons: font
:source-highlighter: highlightjs
:toc: left
:toclevels: 4

Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,4 +17,9 @@ public class MemberController {
public MemberController(MemberService memberService) {
this.memberService = memberService;
}

@GetMapping("/duplicate/{name}")
public ResponseEntity<DuplicateNicknameDto> duplicateNickname(@PathVariable String name) {
return ResponseEntity.ok(memberService.duplicateNickname(name));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
public interface MemberRepository extends JpaRepository<Member, UUID> {
Optional<Member> findById(UUID uuid);

Optional<Member> findByNickname(String nickName);

@Query(
"SELECT m FROM Member m WHERE m.oAuth2Info.clientId = :oAuthId AND"
+ " m.oAuth2Info.authType = :authType")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
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;

public MemberService(MemberRepository memberRepository) {
this.memberRepository = memberRepository;
}

public DuplicateNicknameDto duplicateNickname(String nickName) {
Optional<Member> 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;
}
}

0 comments on commit 2109878

Please sign in to comment.