Skip to content

Commit

Permalink
#25, #18 [Add, Refactor] 북마크 리팩터링 및 엔티티 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 12, 2022
1 parent ca921d3 commit 2d9a85a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ public class BookmarkService {

public void bookmark(BookmarkReqDTO bookmarkReqDTO) {

Optional<Folder> folder = folderRepository.findById(bookmarkReqDTO.getFolderId());
Optional<Store> store = storeRepository.findById(bookmarkReqDTO.getStoreId());
Folder folder = folderRepository.findById(bookmarkReqDTO.getFolderId())
.orElseThrow(()-> new IllegalArgumentException("폴더가 존재하지 않습니다"));
Store store = storeRepository.findById(bookmarkReqDTO.getStoreId())
.orElseThrow(()-> new IllegalArgumentException("가게가 존재하지 않습니다"));

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

storeRepository.save(store.updateBookmarkCount(1));
bookmarkRepository.save(bookmark);
}
}
10 changes: 9 additions & 1 deletion src/main/java/com/mpnp/baechelin/store/domain/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class Store {
// @Column(nullable = false)
private String phoneNumber;

@Column(nullable = false)
private int bookMarkCount = 0;

@Column(nullable = false)
private String heightDifferent;

Expand Down Expand Up @@ -80,11 +83,16 @@ public Store(PublicApiResponseDto.Row row) {
this.category = row.getCategory();
}

public Store updateBookmarkCount(int upOrDown){
this.bookMarkCount += upOrDown;
return this;
}

@OneToMany(mappedBy = "storeId", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Review> reviewList = new ArrayList<>();

@OneToMany(mappedBy = "storeId", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Bookmark> BookmarkList = new ArrayList<>();
private List<Bookmark> bookmarkList = new ArrayList<>();


}
7 changes: 1 addition & 6 deletions src/main/java/com/mpnp/baechelin/user/entity/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class User extends TimeStamped {
private List<Folder> folderList;

@OneToMany(mappedBy = "userId", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Review> reviewsList;
private List<Review> reviewList;

@Builder
public User(String socialId,
Expand All @@ -80,9 +80,4 @@ public User(String socialId,
this.roleType = roleType;
}

@OneToMany(mappedBy = "userId", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Review> reviewList;

@OneToMany(mappedBy = "userId", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Folder> folderList = new ArrayList<>();
}

0 comments on commit 2d9a85a

Please sign in to comment.