Class ProductController

java.lang.Object
com.mt.ecommerce.product.controller.ProductController

@RestController @RequestMapping("/product") public class ProductController extends Object
Controller for managing products. Provides endpoints for adding, updating, deleting, and retrieving products.
  • Constructor Details

    • ProductController

      public ProductController(ProductService productService)
  • 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 retrieved
      page - 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 retrieved
      categoryId - the ID of the category to filter products
      page - 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 details
      productBO - 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 update
      userDetails - 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)