Skip to content

Commit

Permalink
Merge pull request #63 from UniBond-jijijin/feature/41-delete-member
Browse files Browse the repository at this point in the history
[feature/41-delete-member] 회원 탈퇴
  • Loading branch information
5jisoo authored Jan 8, 2024
2 parents d08309e + ea4bda4 commit d5685f9
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 29 deletions.
20 changes: 19 additions & 1 deletion unibond/BOOT-INF/classes/static/docs/experience-community.html
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,24 @@ <h3 id="_request"><a class="link" href="#_request">Request</a></h3>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Authorization</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Basic auth credentials</p></td>
</tr>
</tbody>
</table>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Parameter</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
Expand Down Expand Up @@ -835,7 +853,7 @@ <h3 id="_response_2"><a class="link" href="#_response_2">Response</a></h3>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2024-01-01 07:25:25 +0900
Last updated 2024-01-08 20:48:26 +0900
</div>
</div>
</body>
Expand Down
4 changes: 2 additions & 2 deletions unibond/BOOT-INF/classes/static/docs/member.html
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
"isSuccess" : true,
"code" : 1000,
"message" : "요청에 성공하였습니다.",
"result" : 64
"result" : 65
}</code></pre>
</div>
</div>
Expand Down Expand Up @@ -1436,7 +1436,7 @@ <h3 id="_response_5"><a class="link" href="#_response_5">Response</a></h3>
"code" : 1000,
"message" : "요청에 성공하였습니다.",
"result" : {
"profileImage" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/f35652bb-10a5-4de7-b560-707157e9a916test_profile_img.jpg",
"profileImage" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/dc45f826-fb80-46d9-9121-ae0a0816a9e4test_profile_img.jpg",
"nickname" : "병원장",
"gender" : "MALE",
"diseaseName" : "1번 염색체 장완 21.3 부분의 미세결손 증후군",
Expand Down
20 changes: 19 additions & 1 deletion unibond/BOOT-INF/classes/static/docs/question-community.html
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,24 @@ <h3 id="_request"><a class="link" href="#_request">Request</a></h3>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Authorization</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Basic auth credentials</p></td>
</tr>
</tbody>
</table>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Parameter</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
Expand Down Expand Up @@ -668,7 +686,7 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2024-01-01 07:25:08 +0900
Last updated 2024-01-08 20:49:25 +0900
</div>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -45,4 +46,9 @@ Page<Comment> findParentCommentsByPostFetchOwner(@Param("post") Post post,
"where c.post = :post and c.status = 'ACTIVE' and mb.id IS NULL ")
Integer getCommentCountByPost(@Param("post") Post post,
@Param("loginId") Long loginId);

@Modifying
@Query("update Comment c set c.status = 'DELETED' " +
"where c.member.id = :memberId ")
void bulkDeleteByMember(@Param("memberId") Long memberId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.unibond.unibond.disease.repository;

import com.unibond.unibond.common.BaseEntityStatus;
import com.unibond.unibond.disease.domain.Disease;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -10,6 +11,6 @@

@Repository
public interface DiseaseRepository extends JpaRepository<Disease, Long> {
Page<Disease> findFirst5ByDiseaseNameKorContains(String query, Pageable pageable);
Page<Disease> findFirst5ByDiseaseNameEngContains(String query, Pageable pageable);
Page<Disease> findFirst5ByDiseaseNameKorContainsAndStatus(String query, BaseEntityStatus status, Pageable pageable);
Page<Disease> findFirst5ByDiseaseNameEngContainsAndStatus(String query, BaseEntityStatus status, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.unibond.unibond.disease.service;

import com.unibond.unibond.common.BaseException;
import com.unibond.unibond.common.BaseResponseStatus;
import com.unibond.unibond.disease.domain.Disease;
import com.unibond.unibond.disease.dto.SearchDiseaseResDto;
import com.unibond.unibond.disease.repository.DiseaseRepository;
Expand All @@ -10,9 +9,9 @@
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.unibond.unibond.common.BaseResponseStatus.*;
import static com.unibond.unibond.common.BaseEntityStatus.ACTIVE;
import static com.unibond.unibond.common.BaseResponseStatus.DATABASE_ERROR;
import static com.unibond.unibond.common.BaseResponseStatus.NULL_SEARCH_LAN;

@RequiredArgsConstructor
@Service
Expand All @@ -25,9 +24,9 @@ public SearchDiseaseResDto searchDisease(String language, String searchWord, Pag
Page<Disease> searchedDiseaseList;

if (language.equals("kor")) {
searchedDiseaseList = diseaseRepository.findFirst5ByDiseaseNameKorContains(searchWord, pageable);
searchedDiseaseList = diseaseRepository.findFirst5ByDiseaseNameKorContainsAndStatus(searchWord, ACTIVE, pageable);
} else if (language.equals("eng")) {
searchedDiseaseList = diseaseRepository.findFirst5ByDiseaseNameEngContains(searchWord, pageable);
searchedDiseaseList = diseaseRepository.findFirst5ByDiseaseNameEngContainsAndStatus(searchWord, ACTIVE, pageable);
} else {
throw new BaseException(NULL_SEARCH_LAN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ Boolean hasSentLetterToSamePersonWithinHour(@Param("sender") Long senderId, @Par
@Query("update Letter l set l.letterStatus = 'ARRIVED' " +
"where l.createdDate <= :currentTimeMinusOneHour and l.letterStatus = 'SENDING'")
void bulkSendLetter(@Param("currentTimeMinusOneHour") LocalDateTime currentTime);

@Modifying
@Query("update Letter l set l.status = 'DELETED' " +
"where l.sender.id = :memberId or l.receiver.id = :memberId ")
void bulkDeleteByMember(@Param("memberId") Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
Expand All @@ -23,11 +24,8 @@ public interface LetterRoomRepository extends JpaRepository<LetterRoom, Long> {
Optional<LetterRoom> findLetterRoomBy2Member(@Param("member1") Member member1,
@Param("member2") Member member2);

@Query("select l from LetterRoom l " +
"join fetch l.member1 " +
"join fetch l.member1.disease " +
"join fetch l.member2 " +
"join fetch l.member2.disease " +
"where l.id = :letterRoomId ")
Optional<LetterRoom> findByIdFetch2Member(@Param("letterRoomId") Long letterRoomId);
@Modifying
@Query("update LetterRoom lr set lr.status = 'DELETED' " +
"where lr.member1.id = :memberId or lr.member2.id = :memberId ")
void bulkDeleteByMember(@Param("memberId") Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public BaseResponse<?> getMemberDetail(@PathVariable("memberId") Long memberId,
}
}

@DeleteMapping("/api/v1/members")
public BaseResponse<?> deleteMember(@RequestHeader("Authorization") Long loginId) {
try {
return new BaseResponse<>(memberService.deleteMember());
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}

@PatchMapping("/api/v1/members/{memberId}")
public BaseResponse<?> modifyMemberInfo(@PathVariable("memberId") Long memberId,
@RequestBody(required = false) MemberModifyReqDto request,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.unibond.unibond.member.service;

import com.unibond.unibond.block.repository.MemberBlockRepository;
import com.unibond.unibond.comment.repository.CommentRepository;
import com.unibond.unibond.common.BaseException;
import com.unibond.unibond.common.BaseResponseStatus;
import com.unibond.unibond.common.service.LoginInfoService;
import com.unibond.unibond.common.service.S3Uploader;
import com.unibond.unibond.disease.domain.Disease;
import com.unibond.unibond.disease.repository.DiseaseRepository;
import com.unibond.unibond.letter.repository.LetterRepository;
import com.unibond.unibond.letter_room.repository.LetterRoomRepository;
import com.unibond.unibond.member.domain.Member;
import com.unibond.unibond.member.dto.MemberDetailResDto;
import com.unibond.unibond.member.dto.MemberModifyReqDto;
Expand All @@ -21,6 +24,7 @@
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import static com.unibond.unibond.common.BaseEntityStatus.DELETED;
import static com.unibond.unibond.common.BaseResponseStatus.*;

@Service
Expand All @@ -32,6 +36,9 @@ public class MemberService {
private final MemberBlockRepository memberBlockRepository;
private final DiseaseRepository diseaseRepository;
private final PostRepository postRepository;
private final CommentRepository commentRepository;
private final LetterRepository letterRepository;
private final LetterRoomRepository letterRoomRepository;

@Transactional
public Long signupWithNoProfileImg(MemberRegisterReqDto registerReqDto) throws BaseException {
Expand Down Expand Up @@ -156,6 +163,24 @@ public MemberDetailResDto getMemberInfo(Long memberId, Pageable pageable) throws
}
}

@Transactional
public BaseResponseStatus deleteMember() throws BaseException {
try {
Member loginMember = loginInfoService.getLoginMember();
loginMember.setStatus(DELETED);
Long loginId = loginMember.getId();
commentRepository.bulkDeleteByMember(loginId);
letterRepository.bulkDeleteByMember(loginId);
letterRoomRepository.bulkDeleteByMember(loginId);
postRepository.bulkDeleteByMember(loginId);
return SUCCESS;
} catch (BaseException e) {
throw e;
} catch (Exception e) {
throw new BaseException(DATABASE_ERROR);
}
}

private MemberDetailResDto getMyProfileInfo(Long memberId) throws BaseException {
Member member = memberRepository.findMemberByIdFetchJoinDisease(memberId)
.orElseThrow(() -> new BaseException(INVALID_MEMBER_ID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.Optional;

@Repository
Expand Down Expand Up @@ -40,4 +42,9 @@ Page<Post> findPostsByBoardType(@Param("boardType") BoardType boardType,
Page<Post> findPostsByMember(@Param("member") Member member,
@Param("loginId") Long loginId,
Pageable pageable);

@Modifying
@Query("update Post p set p.status = 'DELETED' " +
"where p.owner.id = :memberId ")
void bulkDeleteByMember(@Param("memberId") Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ <h3 id="_response_2"><a class="link" href="#_response_2">Response</a></h3>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2024-01-08 20:48:26 +0900
Last updated 2024-01-08 21:14:50 +0900
</div>
</div>
</body>
Expand Down
12 changes: 9 additions & 3 deletions unibond/src/main/resources/static/docs/letter-rooms.html
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,20 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 1248
Content-Length: 1599

{
"isSuccess" : true,
"code" : 1000,
"message" : "요청에 성공하였습니다.",
"result" : {
"letterRoomList" : [ {
"senderProfileImg" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/025cc515-c832-4c29-9fe0-9e77f0afea7d6808929_emoji_emoticon_emotion_expression_face_icon.png",
"senderNick" : "서울의가을",
"senderId" : 28,
"recentLetterSentDate" : "2024-01-08T19:33:37.078678",
"letterRoomId" : 12
}, {
"senderProfileImg" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/3b6fc68f-808c-4e22-97e8-9447d6916bc5cat-2068462_640.jpg",
"senderNick" : "눈송이네 베이킹",
"senderId" : 30,
Expand All @@ -538,10 +544,10 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
"letterRoomId" : 18
} ],
"pageInfo" : {
"numberOfElements" : 3,
"numberOfElements" : 4,
"lastPage" : true,
"totalPages" : 1,
"totalElements" : 3,
"totalElements" : 4,
"size" : 30
}
}
Expand Down
4 changes: 2 additions & 2 deletions unibond/src/main/resources/static/docs/member.html
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
"isSuccess" : true,
"code" : 1000,
"message" : "요청에 성공하였습니다.",
"result" : 65
"result" : 68
}</code></pre>
</div>
</div>
Expand Down Expand Up @@ -1436,7 +1436,7 @@ <h3 id="_response_5"><a class="link" href="#_response_5">Response</a></h3>
"code" : 1000,
"message" : "요청에 성공하였습니다.",
"result" : {
"profileImage" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/dc45f826-fb80-46d9-9121-ae0a0816a9e4test_profile_img.jpg",
"profileImage" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/00f348b2-0669-4007-a6ff-6e4129b71023test_profile_img.jpg",
"nickname" : "병원장",
"gender" : "MALE",
"diseaseName" : "1번 염색체 장완 21.3 부분의 미세결손 증후군",
Expand Down
19 changes: 15 additions & 4 deletions unibond/src/main/resources/static/docs/question-community.html
Original file line number Diff line number Diff line change
Expand Up @@ -517,18 +517,18 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 1437
Content-Length: 2067

{
"isSuccess" : true,
"code" : 1000,
"message" : "요청에 성공하였습니다.",
"result" : {
"pageInfo" : {
"numberOfElements" : 2,
"numberOfElements" : 3,
"lastPage" : true,
"totalPages" : 1,
"totalElements" : 2,
"totalElements" : 3,
"size" : 30
},
"postPreviewList" : [ {
Expand All @@ -542,6 +542,17 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
"contentPreview" : "급하게 친구들끼리 여행을 가게 될 일이 생겼어요. 사실 이동하는 게 많이 어려워서",
"boardType" : "QNA",
"isEnd" : false
}, {
"createdDate" : "2023-11-12T00:57:12.641472",
"ownerId" : 28,
"ownerProfileImg" : "https://unibond-img-bucket.s3.ap-northeast-2.amazonaws.com/user/025cc515-c832-4c29-9fe0-9e77f0afea7d6808929_emoji_emoticon_emotion_expression_face_icon.png",
"ownerNick" : "서울의가을",
"disease" : "10번 염색체 장완 말단부의 단일염색체증",
"postId" : 62,
"postImg" : null,
"contentPreview" : "학교에 다니면서 친구들한테 어떻게 이 병에 대해 솔직하게 털어놨는지 다들 계기가 ",
"boardType" : "QNA",
"isEnd" : false
}, {
"createdDate" : "2023-10-03T00:41:51.650698",
"ownerId" : 30,
Expand Down Expand Up @@ -686,7 +697,7 @@ <h3 id="_response"><a class="link" href="#_response">Response</a></h3>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2024-01-08 20:49:25 +0900
Last updated 2024-01-08 21:14:50 +0900
</div>
</div>
</body>
Expand Down

0 comments on commit d5685f9

Please sign in to comment.