Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 21 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,36 @@
### 요구사항
—사용자

-[ ] 쇼핑 검색을 통해 최저가 상품 검색을 할 수 있다.

-[ ] 유저는 회원 가입 후 로그인을 해야 구매가 가능하다.

-[ ] 회원가입 시 이메일, 이름, 주소, 휴대폰번호, 비밀번호를 가진다.

-[ ] 사용자는 검색한 상품을 장바구니에 넣어 둘 수 있다.

-[ ] 사용자는 장바구니에 넣어둔 상품 조회가 가능하다.

-[ ] 사용자는 상품을 결제한 내역을 조회 할 수 있다.
- [ ] 쇼핑 검색을 통해 최저가 상품 검색을 할 수 있다.
- [ ] 유저는 회원 가입 후 로그인을 해야 구매가 가능하다.
- [ ] 회원가입 시 이메일, 이름, 주소, 휴대폰번호, 비밀번호를 가진다.
- [ ] 사용자는 검색한 상품을 장바구니에 넣어 둘 수 있다.
- [ ] 사용자는 장바구니에 넣어둔 상품 조회가 가능하다.
- [ ] 사용자는 상품을 결제한 내역을 조회 할 수 있다.

— 상품

-[ ] 상품은 상품 ID, 상품명, 사진, 최소가격, 최고가격, 날짜, 상품사진, 최저가 쇼핑몰 주소 으로 이루어져있다.

-[ ] 상품은 사용자의 장바구니에 등록이 될 수 있다.
- [ ] 상품은 상품 ID, 상품명, 사진, 최소가격, 최고가격, 날짜, 상품사진, 최저가 쇼핑몰 주소 으로 이루어져있다.
- [ ] 상품은 사용자의 장바구니에 등록이 될 수 있다.

— 장바구니

-[ ] 장바구니는 사용자가 결제를 위해 담아둔 목록을 가지고 있다.

- [ ] 장바구니는 사용자마다 1개의 장바구니를 가진다.
- [ ] 장바구니는 사용자가 결제를 위해 담아둔 목록을 가지고 있다.
- 상품 목록에는 담아 둔상품들의 상품아이디, 상품 이름, 최저가격, 쇼핑몰, 배송비를 가지고있다.

-[ ] 장바구니에서 상품을 취소 할 수 있다.

-[ ] 장바구니에 담아 둔 상품의 전체 합을 보여주며, 상품을 함께 주문 할 수 있다.

-[ ] 장바구니는 중복된 상품을 가지고 있지 않다.

- [ ] 장바구니에서 상품을 취소 할 수 있다.
- [ ] 장바구니에 담아 둔 상품의 전체 합을 보여주며, 상품을 함께 주문 할 수 있다.
- [ ] 장바구니는 중복된 상품을 가지고 있지 않다.
- 중복이 될 경우 갯수가 추가된다.

-[ ] 장바구니 목록에서 두 개 이상의 상품의 쇼핑몰이 같다면, 배송비는 무료로 배송된다.

-[ ] 장바구니의 상품들의 쇼핑몰 이름 중복이 없다면, 상품 개별 2500원이 추가 결제 된다.
- [ ] 장바구니 목록에서 두 개 이상의 상품의 쇼핑몰이 같다면, 배송비는 무료로 배송된다.
- [ ] 장바구니의 상품들의 쇼핑몰 이름 중복이 없다면, 상품 개별 2500원이 추가 결제 된다.

- 주문
-[ ] 장바구니에서 선택한 상품의 리스트, 총액을 가진다.
-[ ] 배송받는 주소,연락처 변경이 가능하다.
-[ ] 배송받는 주소는 기본적으로 유저의 주소를 사용한다.

— 추천

-[ ] 특정 상품 키워드 검색시, 타 사용자가 이미 구매한 키워드의 제품이라면, 타 사용자가 구매한 제품들을 추천목록으로 나타낸다.

-[ ] 타 사용자가 구매한 제품들의 목록이 많다면, 구매 수가 많은 상품 순으로 추천한다.
- [ ] 장바구니에서 선택한 상품의 리스트, 총액을 가진다.
- [ ] 배송받는 주소,연락처 변경이 가능하다.
- [ ] 배송받는 주소는 기본적으로 유저의 주소를 사용한다.
- [ ] 주문의 상품목록을 상품id를 가지고 있다.

### 용어사전

Expand All @@ -59,6 +43,8 @@
| 주문 | Order |유저 장바구니 목록에 있는 것을 종합하여 주문한다.|
| 상품 | Product |상품은 아이디, 상품이름, 최저가,최고가,쇼핑몰의 정보를 가지고 있으며, 장바구니담길수 있다.
| 배송비 | shipping fee |장바구니 목록에서, 같은 쇼핑몰인지 아닌지에 따라서,배송비가 무료 또는 2500원이 붙는다.
| 주문주소 | destination| 주문에서 주소는 도착지의 정보를 나타낸다.|


###모델링
유저 엔
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
Expand All @@ -31,7 +32,6 @@ public class CartService {
* @param product Cart에 추가 될 제품
*/
public void addProductToCart(Long userId, Product product) {

}

/**
Expand All @@ -46,25 +46,25 @@ public void removeProductFromCart(Long userId, Product product) {
}

/**
* Cart 에 담긴 제품 목록을 찾는다.
* Cart 에 담긴 제품 ID 목록을 찾는다.
*
* @param userId 유저 ID
* @return Cart 에 담긴 제품 목록
* @return Cart 에 담긴 제품 ID 목록
*/
public List<Product> findProductsToCart(Long userId) {
return cartRepository.selectProductsToCart(userId);
public List<Long> findProductIdsFromCart(Long userId) {
return cartRepository.findCartByUserId(userId).getProductIds();
}

/**
* Cart 에 담긴 제품 ID 목록을 찾는다.
*
* Cart 에 담긴 제품 목록을 찾는다.
* @param userId 유저 ID
* @return Cart 에 담긴 제품 ID 목록
* @return Cart 에 담긴 제품 목록
*/
public List<Long> findProductIdsToCart(Long userId) {
return cartRepository.selectProductsToCart(userId).stream()
.map(product -> product.getId())
public List<Product> findProductsFromCart(Long userId) {
return cartRepository.findCartByUserId(userId).getProductIds().stream().map(productId ->
productService.findProductById(productId))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
}

}
46 changes: 10 additions & 36 deletions src/main/java/io/github/wotjd243/shoppinggogo/cart/domain/Cart.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package io.github.wotjd243.shoppinggogo.cart.domain;

import io.github.wotjd243.shoppinggogo.product.domain.Product;
import io.github.wotjd243.shoppinggogo.user.domain.User;
import lombok.Data;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class Cart {
@Getter
private Long id; //카트 키
private Long userId; //유저 키
private List<Product> products; //제품 목록
private List<Long> checkedProductIds; //체크되어진 제품 ID 목록
private List<Long> productIds; //제품 목록

public Cart(Long id, Long userId, List<Product> products, List<Long> checkedProductIds) {
public Cart(Long id, Long userId, List<Long> productIds) {
this.id = id;
this.userId = userId;
this.products = products;
this.checkedProductIds = checkedProductIds;
this.productIds = new ArrayList<>(productIds);
}

public boolean removeProductFromCart(Long productId) {
return productIds.remove(productId);
}

/**
Expand All @@ -32,30 +29,7 @@ public void filterByDepricatedProduct(Product depricatedProduct) {

}


/**
* 카트에 담긴 제품 목록과 체크되어진 제품 목록을 매칭시킨다.
* @param checkedProductIds 체크되어진 제품 ID 목록
*/
public List<Product> matchByCheckedProductIds(List<Long> checkedProductIds) {
return products.stream().filter(product ->
checkedProductIds.contains(product.getId()))
.collect(Collectors.toList());
}

/**
* 카트에 담긴 제품 최저 가격의 총 합을 얻는다.
*/
public int getProductLowestPriceSumBySelectedProducts() {
return matchByCheckedProductIds(checkedProductIds)
.stream().mapToInt(p -> p.findLowestPrice().getLowestPrice()).sum();
}

public Long getId() {
return id;
}

public List<Product> getProducts() {
return products;
public List<Long> getProductIds() {
return productIds;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package io.github.wotjd243.shoppinggogo.cart.infra;


import io.github.wotjd243.shoppinggogo.product.domain.Product;

import io.github.wotjd243.shoppinggogo.cart.domain.Cart;

import java.util.List;
import java.util.Optional;

public interface CartRepository {

/**
* Cart 에 담긴 제품 목록을 조회한다.
* @param userId 유저 ID
* @return Cart 에 담긴 제품 목록
* 유저 ID에 의해, 카드를 찾는다.
* @param userId 유저
* @return Cart 정보
*/
public List<Product> selectProductsToCart(Long userId);

public Cart findCartByUserId(Long userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,37 @@ public class DummyCartData {
private static final Map<Long, Cart> carts = new HashMap<>();

static {
//상품 목록
List<Product> product1s = new ArrayList<>();
List<PriceRecord> price1s = new ArrayList<>();
price1s.add(new PriceRecord(1L, 10, 30, 20,
new Date(), new Date()));
price1s.add(new PriceRecord(2L,11, 31, 21, new Date(), new Date()));
price1s.add(new PriceRecord(3L, 12, 32, 22, new Date(), new Date()));
List<Product> product2s = new ArrayList<>();

product1s.add(new Product( 1L, "DDD 프로젝트", new Category("강의", "프로그래밍"),
//상품가격 및 상품
PriceRecord price1 = new PriceRecord(11,31,21, new Date(), new Date());
Product product01 = new Product(1L,"DDD 프로젝트", new Category("강의", "프로그래밍"),
new ProductImage(1000L, 1L, "/ddd/project/link", "file.jpg", new Date()),
price1s,
new Date(), new Date()));
carts.put(1L, new Cart(1L, 1L, product1s, Arrays.asList(1L)));
price1,
new Date(), new Date());

List<Product> product2s = new ArrayList<>();
List<PriceRecord> price2s = new ArrayList<>();
price2s.add(new PriceRecord(1L, 100, 300, 200,
new Date(), new Date()));
product2s.add(new Product( 2L, "포켓몬스터", new Category("강의", "프로그래밍"),
PriceRecord price2 = new PriceRecord(100, 300, 200, new Date(), new Date());
Product product02 = new Product(2L, "포켓몬스터", new Category("강의", "프로그래밍"),
new ProductImage(2000L, 2L, "/pocket", "monster.jpg", new Date()),
price2s,
new Date(), new Date()));
carts.put(2L, new Cart(2L, 2L, product2s, Arrays.asList(2L)));
price2,
new Date(), new Date());


product1s.add(product01);
product2s.add(product01);
product2s.add(product02);

put(1L, 1L, Arrays.asList(1L));
put(2L, 2L, Arrays.asList(1L, 2L));
}

public static Cart getByUserId(final long userId) {
return carts.get(userId);
}

public static Cart put(final Long id, final long userId, final List<Product> products,
final List<Long> checkedProducts) {
return carts.put(userId, new Cart(id, userId, products, checkedProducts));
public static Cart put(final Long id, final long userId, final List<Long> productIds){
return carts.put(userId, new Cart(id, userId, productIds));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.wotjd243.shoppinggogo.cart.infra;

import io.github.wotjd243.shoppinggogo.product.domain.Product;
import io.github.wotjd243.shoppinggogo.cart.domain.Cart;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand All @@ -9,9 +9,7 @@
public class DummyCartRepository implements CartRepository {

@Override
public List<Product> selectProductsToCart(Long userId) {

return DummyCartData.getByUserId(userId)
.getProducts();
public Cart findCartByUserId(Long userId) {
return DummyCartData.getByUserId(userId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.wotjd243.shoppinggogo.cart.ui;


import io.github.wotjd243.shoppinggogo.cart.application.CartService;
import io.github.wotjd243.shoppinggogo.product.domain.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CartController {

@Autowired
private CartService cartService;

@GetMapping("/cart/product/list")
public List<Product> findProducts(@RequestParam Long userId) {
return cartService.findProductsFromCart(userId);
}
}
Loading