Untitled
unknown
plain_text
2 years ago
2.4 kB
2
Indexable
Never
String message = environment.getProperty("CustomerCartAPI.PRODUCT_ADDED_TO_CART"); returnnewResponseEntity<>(message+" "+cartId,HttpStatus.CREATED); } @GetMapping(value="/customer/{customerEmailId}/products") publicResponseEntity<Set<CartProductDTO>>getProductsFromCart( @Pattern(regexp="[a-zA-Z0-9._]+@[a-zA-Z]{2,}\\.[a-zA-Z][a-zA-Z.]+",message= "{invalid.customeremail.format}")@PathVariable("customerEmailId")StringcustomerEmailId) throwsEKartCustomerCartException{ logger.info("Received a requestto getproducts details from the cartof"+ customerEmailId); //StringproductURI=""; Set<CartProductDTO> cartProductDTOs = customerCartService.getProductsFromCart(customerEmailId); for(CartProductDTOcartProductDTO:cartProductDTOs){ /*ProductDTOproductDTO=template.getForEntity( "http://localhost:3334/Ekart/product-api/product/" + cartProductDTO.getProduct().getProductId(), ProductDTO.class).getBody();*/ //WearecallingtheproductAPIusinghard-codedURI //ReplacethiscallwiththeappropriateMSname //ProductAPIisupscaled(availablein2numbers).Hence,useloadbalanced //templatetomakecalltotheProductAPI /*List<ServiceInstance> listOfProductInstances= client.getInstances("ProductMS"); if(listOfProductInstances!=null&&!listOfProductInstances.isEmpty()) productURI=listOfProductInstances.get(0).getUri().toString(); ProductDTO productDTO =template.getForEntity(productURI+"/Ekart/product- api/product/"+cartProductDTO.getProduct().getProductId(),ProductDTO.class).getBody(); */ ProductDTO productDTO = template.getForEntity("http://ProductMS/"+"/Ekart/product-api/product/" + cartProductDTO.getProduct() .getProductId(),ProductDTO.class).getBody(); cartProductDTO.setProduct(productDTO); } returnnewResponseEntity<>(cartProductDTOs,HttpStatus.OK); } //Deletetheproductdetailsfromthecartofcustomerbycalling //deleteProductFromCart()methodofCustomerCartService //Settheappropriatesuccessorfailuremessageandreturnthesame @DeleteMapping(value="/customer/{customerEmailId}/product/{productId}") publicResponseEntity<String>deleteProductFromCart( @Pattern(regexp="[a-zA-Z0-9._]+@[a-zA-Z]{2,}\\.[a-zA-Z][a-zA-Z.]+",message= "{invalid.customeremail.format}")@PathVariable("customerEmailId")StringcustomerEmailId, @NotNull(message = "{invalid.email.format}") @PathVariable("productId") IntegerproductId) throwsEKartCustomerCartException{ //writeyourlogichere