Class CategoryService

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

@Service public class CategoryService extends Object
Service class for handling business logic related to Category entities.
  • Constructor Details

    • CategoryService

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

    • getCategories

      public List<Category> getCategories()
      Retrieves all categories from the repository.
      Returns:
      a list of all categories
    • getCategoryById

      public Category getCategoryById(Long id)
      Retrieves a category by its ID.
      Parameters:
      id - the ID of the category to retrieve
      Returns:
      the Category object if found, or null if not found
    • addCategory

      public Category addCategory(Category category)
      Adds a new category to the repository.
      Parameters:
      category - the Category object to add
      Returns:
      the saved Category object
    • updateCategory

      public Category updateCategory(Long id, Category categoryToUpdate)
      Updates an existing category in the repository.
      Parameters:
      id - the ID of the category to update
      categoryToUpdate - the Category object containing the updated data
      Returns:
      the updated Category object if found, or null if not found
    • deleteCategory

      public boolean deleteCategory(Long id)
      Deletes a category by its ID.
      Parameters:
      id - the ID of the category to delete
      Returns:
      true if the category was deleted, false if the category was not found