From 8654e8dade7874a96657910b4db9e7b8eb001634 Mon Sep 17 00:00:00 2001 From: kokoa322 Date: Mon, 18 Jul 2022 14:49:11 +0900 Subject: [PATCH] =?UTF-8?q?#28=20[update]=20=ED=8F=B4=EB=8D=94=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BookmarkController.java | 12 +++++++++-- .../bookmark/dto/FolderResponseDto.java | 7 ++++--- .../bookmark/service/BookmarkService.java | 20 ++++++++++++------- .../bookmark/service/FolderService.java | 2 +- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/mpnp/baechelin/bookmark/controller/BookmarkController.java b/src/main/java/com/mpnp/baechelin/bookmark/controller/BookmarkController.java index d876e72..019dbde 100644 --- a/src/main/java/com/mpnp/baechelin/bookmark/controller/BookmarkController.java +++ b/src/main/java/com/mpnp/baechelin/bookmark/controller/BookmarkController.java @@ -3,6 +3,10 @@ import com.mpnp.baechelin.bookmark.dto.BookmarkRequestDto; import com.mpnp.baechelin.bookmark.service.BookmarkService; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.security.core.userdetails.User; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @@ -14,8 +18,12 @@ public class BookmarkController { /** 북마크 생성 폴더 담기 */ @PostMapping("/bookmark") - public void bookmark(@RequestBody BookmarkRequestDto bookmarkRequestDto){ + public ResponseEntity bookmark(@RequestBody BookmarkRequestDto bookmarkRequestDto, + @AuthenticationPrincipal User user){ - bookmarkService.bookmark(bookmarkRequestDto); + bookmarkService.bookmark(bookmarkRequestDto, user.getUsername()); + if(user==null){ throw new IllegalArgumentException("해당하는 회원 정보가 없습니다."); } + + return new ResponseEntity<>(HttpStatus.OK); } } diff --git a/src/main/java/com/mpnp/baechelin/bookmark/dto/FolderResponseDto.java b/src/main/java/com/mpnp/baechelin/bookmark/dto/FolderResponseDto.java index 988573f..f302026 100644 --- a/src/main/java/com/mpnp/baechelin/bookmark/dto/FolderResponseDto.java +++ b/src/main/java/com/mpnp/baechelin/bookmark/dto/FolderResponseDto.java @@ -17,6 +17,7 @@ public class FolderResponseDto { private int id; private String folderName; + private List> bookmarkList; public FolderResponseDto(Folder folder) { @@ -38,16 +39,16 @@ public static FolderResponseDto FolderDtoRes(Folder folder) { String category = bookmark.getStoreId().getCategory(); // 업장 카테고리 String PhoneNumber = bookmark.getStoreId().getPhoneNumber(); // 업장 전화번호 - List storeImageList = bookmark.getStoreId().getStoreImageList();// 업장 이미지 리스트 - List tempBookmarkList = new ArrayList<>(); // 정보를 담는 리스트 + List tempBookmarkList = new ArrayList<>(); // 정보를 담는 리스트 + List storeImageList = bookmark.getStoreId().getStoreImageList();// 업장 이미지 리스트 tempBookmarkList.add(name); tempBookmarkList.add(pointAvg); tempBookmarkList.add(address); tempBookmarkList.add(category); tempBookmarkList.add(PhoneNumber); - tempBookmarkList.add(storeImageList.get(0).getStoreImageUrl()); + if(!storeImageList.isEmpty()) { tempBookmarkList.add(storeImageList.get(0).getStoreImageUrl()); } bookmarks.add(tempBookmarkList); } 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 1fc8264..af84a60 100644 --- a/src/main/java/com/mpnp/baechelin/bookmark/service/BookmarkService.java +++ b/src/main/java/com/mpnp/baechelin/bookmark/service/BookmarkService.java @@ -7,6 +7,8 @@ import com.mpnp.baechelin.bookmark.repository.FolderRepository; import com.mpnp.baechelin.store.domain.Store; import com.mpnp.baechelin.store.repository.StoreRepository; +import com.mpnp.baechelin.user.domain.User; +import com.mpnp.baechelin.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -15,22 +17,26 @@ public class BookmarkService { private final BookmarkRepository bookmarkRepository; - private final FolderRepository folderRepository; - private final StoreRepository storeRepository; + private final FolderRepository folderRepository; + private final StoreRepository storeRepository; + private final UserRepository userRepository; - public void bookmark(BookmarkRequestDto bookmarkRequestDto) { + public void bookmark(BookmarkRequestDto bookmarkRequestDto, String socialId) { + + + Folder folder = folderRepository.findById(bookmarkRequestDto.getFolderId()).orElseThrow(()-> new IllegalArgumentException("폴더가 존재하지 않습니다")); + Store store = storeRepository.findById(bookmarkRequestDto.getStoreId()).orElseThrow(()-> new IllegalArgumentException("가게가 존재하지 않습니다")); + User user = userRepository.findBySocialId(socialId); if(user == null) { throw new IllegalArgumentException("해당하는 유저가 없습니다."); } - Folder folder = folderRepository.findById(bookmarkRequestDto.getFolderId()) - .orElseThrow(()-> new IllegalArgumentException("폴더가 존재하지 않습니다")); - Store store = storeRepository.findById(bookmarkRequestDto.getStoreId()) - .orElseThrow(()-> new IllegalArgumentException("가게가 존재하지 않습니다")); Bookmark bookmark = Bookmark .builder() .folderId(folder) .storeId(store) + .userId(user) .build(); + storeRepository.save(store.updateBookmarkCount(1)); bookmarkRepository.save(bookmark); } diff --git a/src/main/java/com/mpnp/baechelin/bookmark/service/FolderService.java b/src/main/java/com/mpnp/baechelin/bookmark/service/FolderService.java index eed5baa..268f615 100644 --- a/src/main/java/com/mpnp/baechelin/bookmark/service/FolderService.java +++ b/src/main/java/com/mpnp/baechelin/bookmark/service/FolderService.java @@ -57,7 +57,7 @@ public void folderUpdate(int folderId, String newFolderName) { public List folderList(String socialId) { - User user = userRepository.findBySocialId(socialId); + User user = userRepository.findBySocialId(socialId); if(user == null){ throw new IllegalArgumentException("해당하는 유저를 찾을 수 없습니다."); } List folderResponseDtoList = new ArrayList<>();