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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Category> addCategory(Category category) Creates a new category.org.springframework.http.ResponseEntity<Void> deleteCategory(Long id) Deletes a category by its ID.Retrieves a list of all categories.org.springframework.http.ResponseEntity<Category> getCategoryById(Long id) Retrieves a category by its ID.org.springframework.http.ResponseEntity<Category> updateCategory(Long id, Category updated) Updates an existing category.
-
Constructor Details
-
CategoryController
public CategoryController()Default constructor for CategoryController.
-
-
Method Details
-
getCategories
-
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
-
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.
-