|
|
@ -6,12 +6,14 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
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.RequestBody; |
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
import com.shopify.cart.model.Order; |
|
|
import com.shopify.cart.model.Order; |
|
|
import com.shopify.cart.repository.OrderRepository; |
|
|
import com.shopify.cart.repository.OrderRepository; |
|
|
|
|
|
import com.shopify.cart.repository.ProductRepository; |
|
|
import com.shopify.cart.repository.UserRepository; |
|
|
import com.shopify.cart.repository.UserRepository; |
|
|
|
|
|
|
|
|
@RestController |
|
|
@RestController |
|
|
@ -20,11 +22,13 @@ public class OrderController { |
|
|
private OrderRepository orderRepository; |
|
|
private OrderRepository orderRepository; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private UserRepository userRepository; |
|
|
private UserRepository userRepository; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private ProductRepository productRepository; |
|
|
|
|
|
|
|
|
@PostMapping("/order/{uid}") |
|
|
|
|
|
private Order postOrder(@RequestBody Order order, @PathVariable("uid")Long uid) { |
|
|
|
|
|
|
|
|
@PostMapping("/order/{uid}/{pid}") |
|
|
|
|
|
private Order postOrder(@RequestBody Order order, @PathVariable("uid")Long uid, @PathVariable("pid") Long pid) { |
|
|
order.setUser(userRepository.getById(uid)); |
|
|
order.setUser(userRepository.getById(uid)); |
|
|
|
|
|
order.setProduct(productRepository.getById(pid)); |
|
|
return orderRepository.save(order); |
|
|
return orderRepository.save(order); |
|
|
} |
|
|
} |
|
|
@GetMapping("/order/all") |
|
|
@GetMapping("/order/all") |
|
|
@ -33,9 +37,21 @@ public class OrderController { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// @GetMapping("/order") |
|
|
|
|
|
// private List<Order> getOrderByProduct(@RequestParam("uid") Long uid){ |
|
|
|
|
|
// return orderRepository.findAllByUserUserId(uid); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
@GetMapping("/order/{uid}") |
|
|
|
|
|
private List<Order> getOrderByProduct(@PathVariable("uid") Long uid){ |
|
|
|
|
|
return orderRepository.findAllByUserId(uid); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PutMapping("/order/{id}/{uid}/{pid}") |
|
|
|
|
|
private Order editOrder(@RequestBody Order newOrder, @PathVariable("id") Long id, @PathVariable("uid") Long uid, @PathVariable("pid") Long pid) { |
|
|
|
|
|
Order order=orderRepository.getById(id); |
|
|
|
|
|
order.setPrice(newOrder.getPrice()); |
|
|
|
|
|
order.setQuantity(newOrder.getQuantity()); |
|
|
|
|
|
order.setStatus(newOrder.getStatus()); |
|
|
|
|
|
order.setUser(userRepository.getById(uid)); |
|
|
|
|
|
order.setProduct(productRepository.getById(pid)); |
|
|
|
|
|
return orderRepository.save(order); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |