|
|
@@ -2,20 +2,18 @@ package com.example.plantsforyou.cart;
|
|
|
|
|
|
import com.example.plantsforyou.appuser.AppUser;
|
|
|
import com.example.plantsforyou.appuser.AppUserService;
|
|
|
-import com.example.plantsforyou.dto.AddToCartDto;
|
|
|
+import com.example.plantsforyou.dto.CartDto;
|
|
|
+import com.example.plantsforyou.dto.ItemCartDto;
|
|
|
import com.example.plantsforyou.exceptions.RejectedRequestException;
|
|
|
import com.example.plantsforyou.plant.Plant;
|
|
|
import com.example.plantsforyou.plant.PlantService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
-import java.util.Optional;
|
|
|
-
|
|
|
@RestController
|
|
|
@RequestMapping("api/v1/cart")
|
|
|
public class CartController {
|
|
|
@@ -31,18 +29,11 @@ public class CartController {
|
|
|
}
|
|
|
|
|
|
@PostMapping
|
|
|
- public ResponseEntity<Object> addToCart(@RequestBody AddToCartDto addToCartDto) throws RejectedRequestException {
|
|
|
+ public ResponseEntity<Object> addToCart(@RequestBody ItemCartDto itemCartDto) throws RejectedRequestException {
|
|
|
String token = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getHeader("Authorization").substring("Bearer ".length());
|
|
|
AppUser appUser = appUserService.getUserFromToken(token);
|
|
|
- Plant plant = plantService.findPlantById(addToCartDto.getPlantId());
|
|
|
- cartService.addToCart(addToCartDto, plant, appUser);
|
|
|
+ Plant plant = plantService.findPlantById(itemCartDto.getId());
|
|
|
+ cartService.addToCart(itemCartDto, plant, appUser);
|
|
|
return new ResponseEntity<>(HttpStatus.CREATED);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|