Skip to content

Commit

Permalink
Merge pull request #49 from SWM-Flash/feature/FLASH-247-member-delete…
Browse files Browse the repository at this point in the history
…-api

회원 탈퇴 API 추가
  • Loading branch information
ChoiWonYu authored Aug 30, 2024
2 parents eaf0977 + 17f2486 commit f383174
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import com.first.flash.account.member.application.dto.MemberCompleteRegistrationResponse;
import com.first.flash.account.member.application.dto.MemberInfoResponse;
import com.first.flash.account.member.domain.Member;
import com.first.flash.account.member.domain.MemberDeletedEvent;
import com.first.flash.account.member.domain.MemberRepository;
import com.first.flash.account.member.exception.exceptions.MemberNotFoundException;
import com.first.flash.account.member.exception.exceptions.NickNameDuplicatedException;
import com.first.flash.global.event.Events;
import com.first.flash.global.util.AuthUtil;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -51,8 +53,20 @@ public ConfirmNickNameResponse confirmNickName(final ConfirmNickNameRequest requ
}

public MemberInfoResponse getMyInfo() {
UUID id = AuthUtil.getId();
Member member = findById(id);
Member member = findMemberByAuthInfo();
return MemberInfoResponse.toDto(member);
}

@Transactional
public MemberInfoResponse deleteMember() {
Member member = findMemberByAuthInfo();
memberRepository.deleteById(member.getId());
Events.raise(MemberDeletedEvent.of(member.getId()));
return MemberInfoResponse.toDto(member);
}

private Member findMemberByAuthInfo() {
UUID id = AuthUtil.getId();
return findById(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.first.flash.account.member.domain;

import com.first.flash.global.event.Event;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class MemberDeletedEvent extends Event {

private final UUID memberId;

public static MemberDeletedEvent of(final UUID memberId) {
return new MemberDeletedEvent(memberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
public interface MemberRepository {

Member save(final Member member);

Optional<Member> findById(final UUID id);

Optional<Member> findBySocialId(final String socialId);

boolean existsByNickName(final String nickName);

void deleteById(final UUID id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface MemberJpaRepository extends JpaRepository<Member, UUID> {
Optional<Member> findMemberBySocialId(final String email);

boolean existsByNickName(final String nickName);

void deleteById(final UUID id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ public Optional<Member> findBySocialId(final String socialId) {
public boolean existsByNickName(final String nickName) {
return jpaRepository.existsByNickName(nickName);
}

@Override
public void deleteById(final UUID id) {
jpaRepository.deleteById(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -92,6 +93,16 @@ public ResponseEntity<ConfirmNickNameResponse> confirmNickName(
return ResponseEntity.ok(memberService.confirmNickName(request));
}

@Operation(summary = "회원 탈퇴", description = "회원 탈퇴")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "회원 탈퇴 성공",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = MemberInfoResponse.class)))
})
@DeleteMapping
public ResponseEntity<MemberInfoResponse> deleteMember() {
return ResponseEntity.ok(memberService.deleteMember());
}

@Operation(summary = "유저 차단", description = "특정 유저 차단")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "차단 성공",
Expand Down

0 comments on commit f383174

Please sign in to comment.