From 2909125499adc4489a60a5ae3ed122aa8223d7db Mon Sep 17 00:00:00 2001 From: kokoa322 Date: Sun, 31 Jul 2022 15:24:50 +0900 Subject: [PATCH] #28 [update] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 북마크 생성 트랜잭션처리 --- .../mpnp/baechelin/bookmark/service/BookmarkService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mpnp/baechelin/bookmark/service/BookmarkService.java b/src/main/java/com/mpnp/baechelin/bookmark/service/BookmarkService.java index e6bf03f..b82af0b 100644 --- a/src/main/java/com/mpnp/baechelin/bookmark/service/BookmarkService.java +++ b/src/main/java/com/mpnp/baechelin/bookmark/service/BookmarkService.java @@ -32,11 +32,13 @@ 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() @@ -44,6 +46,7 @@ public void bookmark(BookmarkRequestDto bookmarkRequestDto, String socialId) { .storeId(store) .userId(user) .build(); + storeRepository.save(store.updateBookmarkCount()); bookmarkRepository.save(bookmark); }