Class ProductController

java.lang.Object
ntnu.idatt2016.v233.SmartMat.controller.product.ProductController

@RestController @RequestMapping("/api/product") public class ProductController extends Object
The product controller is responsible for handling requests related to products. It uses the product service to handle the requests.
Version:
1.0
  • Constructor Details

    • ProductController

      public ProductController()
  • Method Details

    • createProduct

      @PostMapping("/") public org.springframework.http.ResponseEntity<Product> createProduct(@RequestBody ProductRequest productRequest)
      Creates a product if it does not already exist.
      Parameters:
      productRequest - The product to be registered.
      Returns:
      The product that was registered.
    • getProduct

      @GetMapping("ean/{ean}") public org.springframework.http.ResponseEntity<Product> getProduct(@PathVariable long ean)
      Returns a product with the given ean.
      Parameters:
      ean - The ean of the product to be returned.
      Returns:
      The product with the given ean.
    • getAllProducts

      @GetMapping("/") public org.springframework.http.ResponseEntity<List<Product>> getAllProducts()
      Returns all products in the database.
      Returns:
      A list of all products in the database.
    • deleteProduct

      @DeleteMapping("ean/{ean}") public org.springframework.http.ResponseEntity<String> deleteProduct(@PathVariable long ean)
      Deletes a product with the given ean.
      Parameters:
      ean - The ean of the product to be deleted.
      Returns:
      The product that was deleted.
    • updateProduct

      @PutMapping("ean/{ean}") public org.springframework.http.ResponseEntity<Product> updateProduct(@PathVariable long ean, @RequestBody ProductRequest productRequest)
      Updates a product with the given ean.
      Parameters:
      ean - The ean of the product to be updated.
      productRequest - The product to be updated.
      Returns:
      The product that was updated.
    • getProductByName

      @GetMapping("name/{name}") public org.springframework.http.ResponseEntity<Product> getProductByName(@PathVariable String name)
      Retrieve a product by name using a GET request.
      Parameters:
      name - The name of the product to retrieve.
      Returns:
      A ResponseEntity containing the product if found, or a 404 Not Found response if not found.