Skip to content

Commit

Permalink
Merge pull request #197 from MoneyMakersClub/develop
Browse files Browse the repository at this point in the history
[Feat] 회원 탈퇴시 폴더&커스텀도서 삭제 로직 추가
  • Loading branch information
hyejin2234 authored Nov 30, 2024
2 parents 6a1c848 + a81a2f0 commit 246d677
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public interface BookInfoRepository extends JpaRepository<BookInfo, Long> {
"ORDER BY COUNT(b) DESC")
List<BookInfo> findRelatedBooksByBookInfoId(@Param("bookInfoId") Long bookInfoId);

@Query("SELECT b FROM BookInfo b WHERE b.createdUserId = :userId")
List<BookInfo> findCustomBookByCreatedUserId(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.mmc.bookduck.domain.book.entity.UserBook;
import com.mmc.bookduck.domain.book.repository.BookInfoRepository;
import com.mmc.bookduck.domain.book.repository.UserBookRepository;
import com.mmc.bookduck.domain.friend.service.FriendService;
import com.mmc.bookduck.domain.friend.repository.FriendRepository;
import com.mmc.bookduck.domain.oneline.dto.response.OneLineRatingListResponseDto;
import com.mmc.bookduck.domain.oneline.dto.response.OneLineRatingUnitDto;
import com.mmc.bookduck.domain.oneline.entity.OneLine;
Expand Down Expand Up @@ -77,7 +77,7 @@ public class BookInfoService {
private final UserService userService;
private final OneLineRepository oneLineRepository;
private final S3Service s3Service;
private final FriendService friendService;
private final FriendRepository friendRepository;

// api 도서 목록 조회
public BookListResponseDto<BookUnitResponseDto> searchBookList(String keyword, Long page, Long size) {
Expand Down Expand Up @@ -342,7 +342,7 @@ public CustomBookResponseDto getCustomBookBasic(Long bookInfoId) {
if(bookInfo.getCreatedUserId().equals(user.getUserId())){ // 내 customBook
MyRatingOneLineReadStatusDto myRatingOneLine = getMyRatingOneLineReadStatus(bookInfo, user);
return new CustomBookResponseDto(userBook, myRatingOneLine.myRating(),myRatingOneLine.oneLineId(), myRatingOneLine.myOneLine(), true);
}else if(friendService.isFriendWithCurrentUserOrNull(bookInfoCreaterUser)){ //친구 customBook
}else if(isFriend(user,bookInfoCreaterUser)){ //친구 customBook
return new CustomBookResponseDto(userBook, false);
}else{
throw new CustomException(ErrorCode.UNAUTHORIZED_REQUEST); //내것도 아니고 친구것도 아닌 경우
Expand Down Expand Up @@ -492,8 +492,9 @@ public BookListResponseDto<BookCoverImageUnitDto> getMostReadBooks() {
@Transactional(readOnly = true)
public UserArchiveResponseDto getAllUserBookArchive(Long bookInfoId, Long userId, Pageable pageable) {
User bookUser = userService.getActiveUserByUserId(userId);
User currentUser = userService.getCurrentUser();

if(!friendService.isFriendWithCurrentUserOrNull(bookUser)){
if(!isFriend(currentUser,bookUser)){
throw new CustomException(ErrorCode.FRIENDSHIP_REQUIRED);
}
BookInfo bookInfo = getBookInfoById(bookInfoId);
Expand All @@ -515,6 +516,11 @@ public UserArchiveResponseDto getAllUserBookArchive(Long bookInfoId, Long userId
return UserArchiveResponseDto.fromWithoutTitleAuthor(dtoPage);
}

@Transactional(readOnly = true)
public boolean isFriend(User currentUser, User otherUser){
return friendRepository.findFriendBetweenUsers(currentUser.getUserId(), otherUser.getUserId()).isPresent();
}

@Transactional(readOnly = true)
public UserArchiveResponseDto getAllMyBookArchive(Long bookInfoId, Pageable pageable) {
User user = userService.getCurrentUser();
Expand Down Expand Up @@ -600,4 +606,15 @@ public BookListResponseDto<BookCoverImageUnitDto> getRelatedBooks(Long bookInfoI
return new BookListResponseDto<>(topSixBooks);
}

// 사용자 customBook 삭제
public void deleteUserCustomBook(User user) {
List<BookInfo> customBookList = bookInfoRepository.findCustomBookByCreatedUserId(user.getUserId());
for(BookInfo customBook : customBookList){
Optional<UserBook> customUserBook = userBookRepository.findByUserAndBookInfo(user, customBook);
if(customUserBook.isPresent()){
userBookRepository.delete(customUserBook.get());
}
bookInfoRepository.delete(customBook);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface FolderRepository extends JpaRepository<Folder, Long> {
List<Folder> findAllByUserOrderByFolderIdDesc(User user);

boolean existsByFolderNameAndUser(String folderName, User user);

List<Folder> findAllByUser(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,12 @@ public boolean checkIsCustom(UserBook userBook){
return true;
}
}

// 사용자 폴더 삭제
public void deleteUserFolder(User user) {
List<Folder> folders = folderRepository.findAllByUser(user);
for (Folder folder : folders) {
deleteFolder(folder.getFolderId());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mmc.bookduck.domain.user.service;

import com.mmc.bookduck.domain.book.service.BookInfoService;
import com.mmc.bookduck.domain.folder.service.FolderService;
import com.mmc.bookduck.domain.user.dto.request.UserNicknameRequestDto;
import com.mmc.bookduck.domain.user.dto.request.UserSettingUpdateRequestDto;
import com.mmc.bookduck.domain.user.dto.response.UserNicknameResponseDto;
Expand Down Expand Up @@ -30,6 +32,8 @@ public class UserSettingService {
private final UserSettingRepository userSettingRepository;
private final RedisService redisService;
private final CookieUtil cookieUtil;
private final FolderService folderService;
private final BookInfoService bookInfoService;

@Transactional(readOnly = true)
public UserSettingInfoResponseDto getUserSettingInfo() {
Expand Down Expand Up @@ -85,6 +89,10 @@ private <T> void updateSetting(T value, Consumer<T> updateFunction) {
public void deactivate(HttpServletResponse response) {
User user = userService.getCurrentUser();

// 폴더 & 커스텀책 삭제
folderService.deleteUserFolder(user);
bookInfoService.deleteUserCustomBook(user);

String nickname = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 8);
user.updateNickname(nickname);
user.updateStatus(UserStatus.DELETED);
Expand Down

0 comments on commit 246d677

Please sign in to comment.