Class ProductController
java.lang.Object
ntnu.idatt2016.v233.SmartMat.controller.product.ProductController
The product controller is responsible for handling requests related to products.
It uses the product service to handle the requests.
- Version:
- 1.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Product>
createProduct
(ProductRequest productRequest) Creates a product if it does not already exist.org.springframework.http.ResponseEntity<String>
deleteProduct
(long ean) Deletes a product with the given ean.Returns all products in the database.org.springframework.http.ResponseEntity<Product>
getProduct
(long ean) Returns a product with the given ean.org.springframework.http.ResponseEntity<Product>
getProductByName
(String name) Retrieve a product by name using a GET request.org.springframework.http.ResponseEntity<Product>
updateProduct
(long ean, ProductRequest productRequest) Updates a product with the given ean.
-
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
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.
-