Skip to content

Commit

Permalink
#28 [update]
Browse files Browse the repository at this point in the history
폴더 서비스 리팩토링
  • Loading branch information
kokoa322 committed Jul 18, 2022
1 parent 647e8e0 commit 8654e8d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class FolderResponseDto {
private int id;
private String folderName;

private List<List<String>> bookmarkList;

public FolderResponseDto(Folder folder) {
Expand All @@ -38,16 +39,16 @@ public static FolderResponseDto FolderDtoRes(Folder folder) {
String category = bookmark.getStoreId().getCategory(); // 업장 카테고리
String PhoneNumber = bookmark.getStoreId().getPhoneNumber(); // 업장 전화번호

List<StoreImage> storeImageList = bookmark.getStoreId().getStoreImageList();// 업장 이미지 리스트
List<String> tempBookmarkList = new ArrayList<>(); // 정보를 담는 리스트
List<String> tempBookmarkList = new ArrayList<>(); // 정보를 담는 리스트
List<StoreImage> 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);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void folderUpdate(int folderId, String newFolderName) {
public List<FolderResponseDto> folderList(String socialId) {


User user = userRepository.findBySocialId(socialId);
User user = userRepository.findBySocialId(socialId); if(user == null){ throw new IllegalArgumentException("해당하는 유저를 찾을 수 없습니다."); }
List<FolderResponseDto> folderResponseDtoList = new ArrayList<>();


Expand Down

0 comments on commit 8654e8d

Please sign in to comment.