-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCartController.java
More file actions
40 lines (32 loc) · 1.39 KB
/
CartController.java
File metadata and controls
40 lines (32 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.clone.animan.controller;
import com.clone.animan.domain.Cart;
import com.clone.animan.dto.CartRequestDto;
import com.clone.animan.security.UserDetailsImpl;
import com.clone.animan.service.CartService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RequiredArgsConstructor
@RestController
public class CartController {
private final CartService cartService;
@GetMapping("/cart")
public List<Cart> getCart(@AuthenticationPrincipal UserDetailsImpl userDetails) {
return cartService.getCart(userDetails.getUsername());
}
// 만약 장바구니 등록할려는 상품이 이미 존재했다면 그걸 찾아서 + 해주는 것을 해줘야함
//
@PostMapping("/cart/{productId}")
public void createCart(@PathVariable Long productId, @RequestBody CartRequestDto requestDto) {
cartService.createCart(productId, requestDto);
}
@PutMapping("/cart/update/{productId}")
public void updateCart(@PathVariable Long productId, @RequestBody CartRequestDto requestDto) {
cartService.updateQuantityCart(productId, requestDto);
}
@DeleteMapping("/cart/{cartId}")
public void deleteCart(@PathVariable Long cartId) {
cartService.deleteCart(cartId);
}
}