Merge remote-tracking branch 'origin/master'

This commit is contained in:
hoon7566
2022-03-17 15:17:57 +09:00
5 changed files with 23 additions and 21 deletions

View File

@@ -8,6 +8,7 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import static javax.persistence.FetchType.LAZY;
@@ -31,12 +32,11 @@ public class Category extends BaseEntity {
private Store store;
@OneToMany(mappedBy = "category", cascade = CascadeType.ALL)
private List<Item> items;
private List<Item> items = new ArrayList<>();
// == 연관관계 편의 메소드 == //
public void setStore(Store store) {
this.store = store;
store.getCategories().add(this);
}
public void addItem(Item item) {

View File

@@ -54,12 +54,10 @@ public class Item extends BaseEntity {
public void setStore(Store store) {
this.store = store;
store.getItems().add(this);
}
public void setCategory(Category category) {
this.category = category;
category.getItems().add(this);
}
public void setItemNameAndPriceAndCategory(String name , Long price,Category category){

View File

@@ -24,7 +24,7 @@ public class ItemOption extends BaseEntity {
private String name;
@ManyToOne(fetch = LAZY , cascade = CascadeType.ALL)
@ManyToOne(fetch = LAZY )
@JoinColumn(name = "item_id")
private Item item;

View File

@@ -48,13 +48,13 @@ public class Store extends BaseEntity {
//== user-service.user pk ==//
private Long userId;
@OneToMany(mappedBy = "store")
@OneToMany(mappedBy = "store", cascade = CascadeType.ALL)
private List<Category> categories = new ArrayList<>();
@OneToMany(mappedBy = "store")
@OneToMany(mappedBy = "store", cascade = CascadeType.ALL)
private List<Item> items = new ArrayList<>();
@OneToMany(mappedBy = "store")
@OneToMany(mappedBy = "store", cascade = CascadeType.ALL)
private List<FavoriteStore> favoriteStores = new ArrayList<>();
// == 연관관계 편의 메소드 == //

View File

@@ -22,11 +22,10 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
//@Component
@Component
@RequiredArgsConstructor
@Slf4j
public class SqlCommandLineRunner implements CommandLineRunner {
@@ -105,17 +104,14 @@ public class SqlCommandLineRunner implements CommandLineRunner {
Category 디카페인 = categoryRepository.save(Category.of("디카페인", 1, store));
Category = categoryRepository.save(Category.of("", 2, store));
ItemOption ice = ItemOption.of(OptionType.REQUIRED, "ICE");
ItemOption hot = ItemOption.of(OptionType.REQUIRED, "HOT");
Item 아메리카노 = Item.of("아메리카노", 1500L, 카페인, store, List.of(ice, hot));
Item 카페라떼 = Item.of("카페라떼", 2000L, 카페인, store, List.of(ice, hot));
Item 카페모카 = Item.of("카페모카", 3900L, 카페인, store, List.of(ice, hot));
Item 콜드브루 = Item.of("콜드브루", 2500L, 카페인, store, List.of(ice));
Item 녹차라떼 = Item.of("녹차라떼", 3000L, 디카페인, store, List.of(ice, hot));
Item 딸기라떼 = Item.of("딸기라떼", 3000L, 디카페인, store, List.of(ice, hot));
Item 녹차 = Item.of("녹차", 3000L, , store, List.of(hot));
Item 히비스커스 = Item.of("히비스커스 티", 3000L, , store, List.of(hot));
Item 아메리카노 = Item.of("아메리카노", 1500L, 카페인, store, List.of(getIceOption(), getHotOption()));
Item 카페라떼 = Item.of("카페라떼", 2000L, 카페인, store, List.of(getIceOption(), getHotOption()));
Item 카페모카 = Item.of("카페모카", 3900L, 카페인, store, List.of(getIceOption(), getHotOption()));
Item 콜드브루 = Item.of("콜드브루", 2500L, 카페인, store, List.of(getIceOption()));
Item 녹차라떼 = Item.of("녹차라떼", 3000L, 카페인, store, List.of(getIceOption(), getHotOption()));
Item 딸기라떼 = Item.of("딸기라떼", 3000L, 카페인, store, List.of(getIceOption(), getHotOption()));
Item 녹차 = Item.of("녹차", 3000L, , store, List.of(getHotOption()));
Item 히비스커스 = Item.of("히비스커스 티", 3000L, , store, List.of(getIceOption(), getHotOption()));
List<Item> items = List.of(아메리카노, 카페라떼, 카페모카, 콜드브루, 녹차라떼, 딸기라떼, 녹차, 히비스커스);
itemRepository.saveAll(items);
@@ -124,6 +120,14 @@ public class SqlCommandLineRunner implements CommandLineRunner {
});
}
private ItemOption getIceOption() {
return ItemOption.of(OptionType.REQUIRED, "ICE");
}
private ItemOption getHotOption() {
return ItemOption.of(OptionType.REQUIRED, "HOT");
}
void createFavoriteStore(FavoriteStoreRepository favoriteStoreRepository, List<Store> stores) {
List<Long> userList = List.of(1L,2L,3L,4L,5L,6L,7L);
userList.forEach(userId -> stores.forEach(store -> favoriteStoreRepository.save(FavoriteStore.of(userId, store))));