Class ProductController
- java.lang.Object
-
- edu.cnm.deepdive.albuquirky.controller.ProductController
-
@RestController @RequestMapping("/products") @ExposesResourceFor(Product.class) public class ProductController extends ObjectThe ProductController class is the @RestController that maps the endpoints of "/products" for communication between the server-side and client-side forProduct.
-
-
Constructor Summary
Constructors Constructor Description ProductController(ProductService productService)Constructs the instance of ProductService object
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Iterable<Product>getAllProducts()The Get method which returns all existing products.StringgetDescription(long productId)The Get method which returns the description of a productStringgetName(long productId)The Get method which returns a product from the product nameintgetPrice(long productId)The Get method which returns the price of a product.ProductgetProduct(long productId)The Get method which returns a product from a product ID.Iterable<Product>getProductsMatchingKeyword(String keyword)The Get method which returns a product matching a keywordIterable<Product>getProductsWhereSelling(boolean mine, org.springframework.security.core.Authentication auth)The Get method which returns products from a seller.intgetStock(long productId)The Get method which returns the stock of a product.Productpost(Product product, org.springframework.security.core.Authentication auth)The Post method which lets a profile post a product.StringupdateDescription(String description, long productId)The Put method which updates the description of a product.StringupdateName(String name, long productId)The Put method which updates a product name.intupdatePrice(int price, long productId)The Put method which updates the price of a product.intupdateStock(int stock, long productId)The Put method which updates the stock of a product
-
-
-
Constructor Detail
-
ProductController
public ProductController(ProductService productService)
Constructs the instance of ProductService object- Parameters:
productService- The instance ofProductServiceto be initialized.
-
-
Method Detail
-
getAllProducts
@GetMapping(produces="application/json") public Iterable<Product> getAllProducts()
The Get method which returns all existing products.- Returns:
- An
Iterablecontaining all existingProductobjects.
-
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
Iterablecontaining all existingProductobjects matching thekeywordby 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.
-
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.
-
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.
-
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
-
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 theProductto 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
-
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 theProductto 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.
-
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 theProductto 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.
-
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 theProductto be updated.- Returns:
- The new stock value.
-
-