Skip to content

Commit

Permalink
#28 [Fix] 북마크 원복 + 수정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Aug 4, 2022
1 parent 24afde3 commit d029024
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@
public class BookmarkService {

private final BookmarkRepository bookmarkRepository;
private final FolderRepository folderRepository;
private final StoreRepository storeRepository;
private final UserRepository userRepository;
private final FolderRepository folderRepository;
private final StoreRepository storeRepository;
private final UserRepository userRepository;
private final StoreService storeService;

@Transactional
public void bookmark(BookmarkRequestDto bookmarkRequestDto, String socialId) {
// 북마크 폴더 생성하는 Flow를 따르므로 bookmarkRequestDto의 folderId는 존재
Folder folder = folderRepository.findById(bookmarkRequestDto.getFolderId()).orElseThrow(()-> new CustomException(ErrorCode.NO_FOLDER_FOUND));
Store store = storeRepository.findById((long) bookmarkRequestDto.getStoreId()).orElseThrow(()-> new CustomException(ErrorCode.NO_BOOKMARK_FOUND));
User user = userRepository.findBySocialId(socialId); if(user == null) {throw new CustomException(ErrorCode.NO_USER_FOUND); }
Folder folder = folderRepository.findById(bookmarkRequestDto.getFolderId()).orElseThrow(() -> new CustomException(ErrorCode.NO_FOLDER_FOUND));
Store store = storeRepository.findById((long) bookmarkRequestDto.getStoreId()).orElseThrow(() -> new CustomException(ErrorCode.NO_BOOKMARK_FOUND));
User user = userRepository.findBySocialId(socialId);
if (user == null) {
throw new CustomException(ErrorCode.NO_USER_FOUND);
}

Bookmark bookmark = Bookmark
.builder()
Expand All @@ -53,17 +56,21 @@ public void bookmark(BookmarkRequestDto bookmarkRequestDto, String socialId) {

if (!bookmarkRepository.existsByStoreIdAndUserId(store, user)) {
bookmarkRepository.save(bookmark);
storeService.updateBookmarkCnt(store,socialId);
storeService.updateBookmarkCnt(store, socialId);
}
}

@Transactional
public void bookmarkDelete(Long storeId, String socialId) {
User user = userRepository.findBySocialId(socialId); if(user == null) { throw new CustomException(ErrorCode.NO_USER_FOUND); }
Store store = storeRepository.findById(storeId).orElseThrow(()-> new CustomException(ErrorCode.NO_STORE_FOUND));
User user = userRepository.findBySocialId(socialId);
if (user == null) {
throw new CustomException(ErrorCode.NO_USER_FOUND);
}
Store store = storeRepository.findById(storeId).orElseThrow(() -> new CustomException(ErrorCode.NO_STORE_FOUND));
Bookmark bookmark = bookmarkRepository.findByStoreIdAndUserId(store, user).orElseThrow(() -> new CustomException(ErrorCode.NO_BOOKMARK_FOUND));
store.removeBookmark(bookmark);
bookmarkRepository.delete(bookmark);
storeService.updateBookmarkCnt(store,socialId);
storeService.updateBookmarkCnt(store, socialId);
}


Expand All @@ -74,7 +81,7 @@ public List<BookmarkInfoDto> bookmarkTop(String socialId, Pageable pageable) {
Page<Bookmark> bookmarkPage = bookmarkRepository.findAllByUserId(user, pageable);

List<BookmarkInfoDto> bookmarkList = new ArrayList<>();
for(Bookmark bookmark: bookmarkPage){
for (Bookmark bookmark : bookmarkPage) {
BookmarkInfoDto bookmarkInfoDto = new BookmarkInfoDto(bookmark);
bookmarkList.add(bookmarkInfoDto);
}
Expand All @@ -87,7 +94,7 @@ public BookmarkPagedResponseDto bookmarkList(String socialId, int folderId, Page
if (user == null) {
throw new CustomException(ErrorCode.NO_USER_FOUND);
}
Folder folder = folderRepository.findById(folderId).orElseThrow(()-> new CustomException(ErrorCode.NO_FOLDER_FOUND));
Folder folder = folderRepository.findById(folderId).orElseThrow(() -> new CustomException(ErrorCode.NO_FOLDER_FOUND));
Page<Bookmark> pagedBookmark = bookmarkRepository.findAllByFolderId(folder, pageable);
return new BookmarkPagedResponseDto(pagedBookmark);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,24 @@ public List<FolderResponseDto> folderList(String socialId) {
List<FolderResponseDto> folderResponseDtoList = new ArrayList<>();
for (Folder obj : user.getFolderList()) {
FolderResponseDto folderResponseDto = FolderResponseDto.FolderDtoRes(obj);
List<Integer> latestFolder = bookmarkRepository.findLatestFolder(obj.getId());
// List<Integer> latestFolder = bookmarkRepository.findLatestFolder(obj.getId());
// folderResponseDto.setThumbNail();
// folderResponseDtoList.add();

folderResponseDtoList.add(folderResponseDto);
}
return folderResponseDtoList;
}
@Transactional(readOnly = true)
public List<FolderResponseDto> folderListV2(String socialId) {
User user = userRepository.findBySocialId(socialId);
if (user == null) {
throw new CustomException(ErrorCode.NO_USER_FOUND);
}
List<FolderResponseDto> folderResponseDtoList = new ArrayList<>();
for (Folder obj : user.getFolderList()) {
FolderResponseDto folderResponseDto = FolderResponseDto.FolderDtoRes(obj);
List<Integer> latestFolder = bookmarkRepository.findLatestFolder(obj.getId());
//TODO ThumbNail
folderResponseDtoList.add(folderResponseDto);
}
return folderResponseDtoList;
}
Expand Down

0 comments on commit d029024

Please sign in to comment.