Class ProductController
java.lang.Object
com.mt.ecommerce.product.controller.ProductController
Controller for managing products.
Provides endpoints for adding, updating, deleting, and retrieving products.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateProduct
(org.springframework.security.core.userdetails.UserDetails userDetails, ProductBO productBO) Endpoint to create a new product.void
deleteProduct
(String id) getAllProducts
(String vendorId, int page, int size) Endpoint to retrieve all products for a specific vendor.getAllProductsWithCategory
(String vendorId, String categoryId, int page, int size) Endpoint to retrieve all products for a specific vendor and category.updateProduct
(ProductBO productBO, org.springframework.security.core.userdetails.UserDetails userDetails) Endpoint to update an existing product.
-
Constructor Details
-
ProductController
-
-
Method Details
-
getAllProducts
@GetMapping(value="/unsecured/all", produces="application/json") public List<ProductBO> getAllProducts(@RequestParam(name="vendorId") String vendorId, @RequestParam(name="page",defaultValue="0") int page, @RequestParam(name="size",defaultValue="10") int size) Endpoint to retrieve all products for a specific vendor. Accessible without authentication.- Parameters:
vendorId
- the ID of the vendor whose products are to be retrievedpage
- the page number for pagination (default is 0)size
- the number of records per page (default is 10)- Returns:
- a list of ProductBO objects representing the vendor's products
-
getAllProductsWithCategory
@GetMapping(value="/unsecured/category/all", produces="application/json") public List<ProductBO> getAllProductsWithCategory(@RequestParam(name="vendorId") String vendorId, @RequestParam(name="categoryId") String categoryId, @RequestParam(name="page",defaultValue="0") int page, @RequestParam(name="size",defaultValue="10") int size) Endpoint to retrieve all products for a specific vendor and category. Accessible without authentication.- Parameters:
vendorId
- the ID of the vendor whose products are to be retrievedcategoryId
- the ID of the category to filter productspage
- the page number for pagination (default is 0)size
- the number of records per page (default is 10)- Returns:
- a list of ProductBO objects representing the vendor's products in the specified category
-
createProduct
@PreAuthorize("hasAnyAuthority(\'ROLE_VENDOR\', \'ROLE_ADMIN\')") @PostMapping(value="", produces="application/json", consumes="application/json") public ProductBO createProduct(@AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails, @RequestBody ProductBO productBO) Endpoint to create a new product. Accessible by users with ROLE_VENDOR or ROLE_ADMIN.- Parameters:
userDetails
- the authenticated user's detailsproductBO
- the product information to create- Returns:
- the created ProductBO
-
updateProduct
@PreAuthorize("hasAnyAuthority(\'ROLE_VENDOR\', \'ROLE_ADMIN\')") @PutMapping(value="", produces="application/json", consumes="application/json") public ProductBO updateProduct(@RequestBody ProductBO productBO, @AuthenticationPrincipal org.springframework.security.core.userdetails.UserDetails userDetails) Endpoint to update an existing product. Accessible by users with ROLE_VENDOR or ROLE_ADMIN.- Parameters:
productBO
- the product information to updateuserDetails
- the authenticated user's details- Returns:
- the updated ProductBO
-
deleteProduct
@PreAuthorize("hasAnyAuthority(\'ROLE_VENDOR\', \'ROLE_ADMIN\')") @DeleteMapping(value="", produces="application/json", consumes="application/json") public void deleteProduct(@RequestParam(name="id") String id)
-