Class CategoryController

java.lang.Object
org.codewithmagret.rest.category.CategoryController

@RestController @RequestMapping("/api/v1/categories") public class CategoryController extends Object
REST controller for managing categories.
  • Constructor Details

    • CategoryController

      public CategoryController()
      Default constructor for CategoryController.
  • Method Details

    • getCategories

      @GetMapping public List<Category> getCategories()
      Retrieves a list of all categories.
      Returns:
      A list of Category objects.
    • getCategoryById

      @GetMapping("/{id}") public org.springframework.http.ResponseEntity<Category> getCategoryById(@PathVariable Long id)
      Retrieves a category by its ID.
      Parameters:
      id - The ID of the category to retrieve.
      Returns:
      A ResponseEntity containing the Category object if found, or a 404 Not Found status if not found.
    • addCategory

      @PostMapping public org.springframework.http.ResponseEntity<Category> addCategory(@RequestBody Category category)
      Creates a new category.
      Parameters:
      category - The Category object to create.
      Returns:
      A ResponseEntity containing the created Category object.
    • updateCategory

      @PutMapping("/{id}") public org.springframework.http.ResponseEntity<Category> updateCategory(@PathVariable Long id, @RequestBody Category updated)
      Updates an existing category.
      Parameters:
      id - The ID of the category to update.
      updated - The Category object containing the updated data.
      Returns:
      A ResponseEntity containing the updated Category object if found, or a 404 Not Found status if not found.
    • deleteCategory

      @DeleteMapping("/{id}") public org.springframework.http.ResponseEntity<Void> deleteCategory(@PathVariable Long id)
      Deletes a category by its ID.
      Parameters:
      id - The ID of the category to delete.
      Returns:
      A ResponseEntity with a 204 No Content status if deleted, or a 404 Not Found status if not found.