package by.intexsoft.controller;

import by.intexsoft.model.Product;
import by.intexsoft.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {

    private static final Logger LOGGER = LoggerFactory.getLogger(SimpleController.class);

    @Autowired
    private ProductService productService;

    @RequestMapping("/all")
    public List<Product> loadAllProducts() {
        LOGGER.info("Start loadAllProducts");
        try {
            return productService.findAll();
        } catch (NullPointerException e) {
            LOGGER.error("Exception in loadAllProducts. " + e.getLocalizedMessage());
            return null;
        }
    }
}

@@ -23,24 +23,60 @@
 ontroller;%0A%0A
+import by.intexsoft.dto.ProductDTO;%0A
 import by.in
@@ -98,16 +98,16 @@
 roduct;%0A
-
 import b
@@ -262,16 +262,76 @@
 owired;%0A
+import org.springframework.web.bind.annotation.RequestBody;%0A
 import o
@@ -385,16 +385,78 @@
 apping;%0A
+import org.springframework.web.bind.annotation.RequestMethod;%0A
 import o
@@ -1070,16 +1070,16 @@
 age());%0A
-
         
@@ -1110,11 +1110,367 @@
  %7D%0A    %7D
+%0A%0A    @RequestMapping(value = %22/add%22, method = RequestMethod.PUT)%0A    public void createProduct(@RequestBody Product product) %7B%0A        LOGGER.info(%22Start createProduct%22);%0A        try %7B%0A            productService.create(product);%0A        %7D catch (Exception e) %7B%0A            LOGGER.info(%22Error in createProduct. %22 + e.getLocalizedMessage());%0A        %7D%0A    %7D
 %0A%7D%0A

add put request to product