Skip to content

Commit

Permalink
#28 [update]
Browse files Browse the repository at this point in the history
북마크 생성 트랜잭션처리
  • Loading branch information
kokoa322 committed Jul 31, 2022
1 parent f78d4a5 commit 2909125
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ public class BookmarkService {
private final UserRepository userRepository;
private final StoreImgRepository storeImgRepository;
// private final StoreImageRepository storeImageRepository;

@Transactional
public void bookmark(BookmarkRequestDto bookmarkRequestDto, String socialId) {

Folder folder = folderRepository.findById(bookmarkRequestDto.getFolderId()).orElseThrow(()-> new IllegalArgumentException("폴더가 존재하지 않습니다"));
Store store = storeRepository.findById((long) bookmarkRequestDto.getStoreId()).orElseThrow(()-> new IllegalArgumentException("가게가 존재하지 않습니다"));
User user = userRepository.findBySocialId(socialId); if(user == null) { throw new IllegalArgumentException("해당하는 유저가 없습니다."); }
Store store = storeRepository.findById((long) bookmarkRequestDto.getStoreId()).orElseThrow(()-> new IllegalArgumentException("가게가 존재하지 않습니다"));
User user = userRepository.findBySocialId(socialId); if(user == null) { throw new IllegalArgumentException("해당하는 유저가 없습니다."); }

Bookmark bookmark = Bookmark
.builder()
.folderId(folder)
.storeId(store)
.userId(user)
.build();

storeRepository.save(store.updateBookmarkCount());
bookmarkRepository.save(bookmark);
}
Expand Down

0 comments on commit 2909125

Please sign in to comment.