Class CategoryService

java.lang.Object
com.equipmentrental.equipment_rental_system.service.CategoryService

@Service @Transactional(readOnly=true) public class CategoryService extends Object
Service layer for managing Category entities. Handles CRUD operations and enforces BR-06 (a category cannot be deleted while equipment items are assigned to it).
See Also:
  • Constructor Details

  • Method Details

    • findAll

      public List<Category> findAll()
      Returns all categories in the system.
      Returns:
      list of all categories
    • findById

      public Category findById(Long categoryId)
      Finds a category by its ID.
      Parameters:
      categoryId - the ID of the category to find
      Returns:
      the category
      Throws:
      ResourceNotFoundException - if no category exists with the given ID
    • save

      @Transactional public Category save(Category category)
      Saves a new or updated category.
      Parameters:
      category - the category to save
      Returns:
      the saved category with generated ID (if new)
    • deleteById

      @Transactional public void deleteById(Long categoryId)
      Deletes a category if no equipment items are assigned to it (BR-06).
      Parameters:
      categoryId - the ID of the category to delete
      Throws:
      ResourceNotFoundException - if no category exists with the given ID
      DeletionBlockedException - if equipment items are still assigned to this category