Class ProductController


  • @RestController
    @RequestMapping("/products")
    @ExposesResourceFor(Product.class)
    public class ProductController
    extends Object
    The ProductController class is the @RestController that maps the endpoints of "/products" for communication between the server-side and client-side for Product.
    • Constructor Detail

      • ProductController

        public ProductController​(ProductService productService)
        Constructs the instance of ProductService object
        Parameters:
        productService - The instance of ProductService to be initialized.
    • Method Detail

      • getAllProducts

        @GetMapping(produces="application/json")
        public Iterable<Product> getAllProducts()
        The Get method which returns all existing products.
        Returns:
        An Iterable containing all existing Product objects.
      • getProductsMatchingKeyword

        @GetMapping(produces="application/json",
                    params="keyword")
        public Iterable<Product> getProductsMatchingKeyword​(@RequestParam
                                                            String keyword)
        The Get method which returns a product matching a keyword
        Parameters:
        keyword - The String keyword to filter products by.
        Returns:
        An Iterable containing all existing Product objects matching the keyword by name.
      • getProductsWhereSelling

        @GetMapping(produces="application/json",
                    params="mine")
        public Iterable<Product> getProductsWhereSelling​(@RequestParam
                                                         boolean mine,
                                                         org.springframework.security.core.Authentication auth)
        The Get method which returns products from a seller.
        Parameters:
        mine - A boolean indicating whether or not the Product were created by the user.
        auth - The user authentication.
        Returns:
        An Iterable containing all existing Product objects sold by the user.
      • post

        @PostMapping(consumes="application/json",
                     produces={"application/json","text/plain"})
        public Product post​(@RequestBody
                            Product product,
                            org.springframework.security.core.Authentication auth)
        The Post method which lets a profile post a product.
        Parameters:
        product - The Product to be created.
        auth - The authorization for the user.
        Returns:
        The Product object that was created.
      • getProduct

        @GetMapping(value="/{productId:\\d+}",
                    produces="application/json")
        public Product getProduct​(@PathVariable
                                  long productId)
        The Get method which returns a product from a product ID.
        Parameters:
        productId - The ID of the Product requested.
        Returns:
        The Product matching the provided ID.
      • getName

        @GetMapping(value="/{productId:\\d+}/name",
                    produces="application/json")
        public String getName​(@PathVariable
                              long productId)
        The Get method which returns a product from the product name
        Parameters:
        productId - The ID of the Product requested.
        Returns:
        The String name of the Product requested.
      • updateName

        @PutMapping(value="/{productId:\\d+}/name",
                    consumes={"application/json","text/plain"},
                    produces={"application/json","text/plain"})
        public String updateName​(@RequestBody
                                 String name,
                                 @PathVariable
                                 long productId)
        The Put method which updates a product name.
        Parameters:
        name - The new name content.
        productId - The ID of the Product to be updated.
        Returns:
        The updated name content.
      • getDescription

        @GetMapping(value="/{productId:\\d+}/description",
                    produces="application/json")
        public String getDescription​(@PathVariable
                                     long productId)
        The Get method which returns the description of a product
        Parameters:
        productId - The ID of the Product requested.
        Returns:
        The String description of the Product requested.
      • updateDescription

        @PutMapping(value="/{productId:\\d+}/description",
                    consumes={"application/json","text/plain"},
                    produces={"application/json","text/plain"})
        public String updateDescription​(@RequestBody
                                        String description,
                                        @PathVariable
                                        long productId)
        The Put method which updates the description of a product.
        Parameters:
        description - The new description content.
        productId - The ID of the Product to be updated.
        Returns:
        The updated description content.
      • getPrice

        @GetMapping(value="/{productId:\\d+}/price",
                    produces="application/json")
        public int getPrice​(@PathVariable
                            long productId)
        The Get method which returns the price of a product.
        Parameters:
        productId - The ID of the Product requested.
        Returns:
        The price of the Product requested.
      • updatePrice

        @PutMapping(value="/{productId:\\d+}/price",
                    consumes={"application/json","text/plain"},
                    produces={"application/json","text/plain"})
        public int updatePrice​(@RequestBody
                               int price,
                               @PathVariable
                               long productId)
        The Put method which updates the price of a product.
        Parameters:
        price - The new price.
        productId - The ID of the Product to be updated.
        Returns:
        The new price value.
      • getStock

        @GetMapping(value="/{productId:\\d+}/stock",
                    produces="application/json")
        public int getStock​(@PathVariable
                            long productId)
        The Get method which returns the stock of a product.
        Parameters:
        productId - The ID of the Product requested.
        Returns:
        The stock of the requested Product.
      • updateStock

        @PutMapping(value="/{productId:\\d+}/stock",
                    consumes={"application/json","text/plain"},
                    produces={"application/json","text/plain"})
        public int updateStock​(@RequestBody
                               int stock,
                               @PathVariable
                               long productId)
        The Put method which updates the stock of a product
        Parameters:
        stock - The new stock.
        productId - The ID of the Product to be updated.
        Returns:
        The new stock value.