|
|
|
@ -1,8 +1,13 @@ |
|
|
|
package com.shopify.cart.controller; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
import org.springframework.web.bind.annotation.PutMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
@ -27,4 +32,22 @@ public class CartController { |
|
|
|
cart.setProduct(productRepository.getById(pid)); |
|
|
|
return cartRepository.save(cart); |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping("/cart/{uid}") |
|
|
|
public List<Cart> getCartByUser(@PathVariable("uid") Long uid) { |
|
|
|
return cartRepository.getCartByUserId(uid); |
|
|
|
} |
|
|
|
|
|
|
|
@PutMapping("/cart/{cid}") |
|
|
|
public Cart editCartItem(@RequestBody Cart cart, @PathVariable("cid") Long cid) { |
|
|
|
Cart cartDB = cartRepository.getById(cid); |
|
|
|
cartDB.setQuantity(cart.getQuantity()); |
|
|
|
cartDB.setPrice(cart.getPrice()); |
|
|
|
return cartRepository.save(cartDB); |
|
|
|
} |
|
|
|
|
|
|
|
@DeleteMapping("/cart/{cid}") |
|
|
|
public void deleteCartItem(@PathVariable("cid") Long cid) { |
|
|
|
cartRepository.deleteById(cid); |
|
|
|
} |
|
|
|
} |