Class EquipmentService

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

@Service @Transactional(readOnly=true) public class EquipmentService extends Object
Service layer for managing Equipment entities. Handles CRUD operations, search and filtering, and enforces the following business rules:
  • BR-01: equipment in MAINTENANCE or UNAVAILABLE status cannot be booked
  • BR-07: equipment with active bookings cannot be deleted
  • BR-08: equipment status is updated to reflect active bookings

This service is called by BookingService for availability verification and status updates, following the architectural principle that each service manages its own entity.

See Also:
  • Constructor Details

  • Method Details

    • findAll

      public List<Equipment> findAll()
      Returns all equipment items in the system.
      Returns:
      list of all equipment
    • findById

      public Equipment findById(Long equipmentId)
      Finds an equipment item by its ID.
      Parameters:
      equipmentId - the ID of the equipment to find
      Returns:
      the equipment item
      Throws:
      ResourceNotFoundException - if no equipment exists with the given ID
    • findByCategoryId

      public List<Equipment> findByCategoryId(Long categoryId)
      Finds all equipment items belonging to a specific category.
      Parameters:
      categoryId - the ID of the category to filter by
      Returns:
      list of equipment in the given category
    • findByStatus

      public List<Equipment> findByStatus(EquipmentStatus status)
      Finds all equipment items with a specific availability status.
      Parameters:
      status - the status to filter by
      Returns:
      list of equipment matching the given status
    • searchByName

      public List<Equipment> searchByName(String name)
      Searches for equipment items whose name contains the given text (case-insensitive).
      Parameters:
      name - the search text
      Returns:
      list of matching equipment items
    • save

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

      @Transactional public void deleteById(Long equipmentId)
      Deletes an equipment item if it has no active (confirmed) bookings (BR-07).
      Parameters:
      equipmentId - the ID of the equipment to delete
      Throws:
      ResourceNotFoundException - if no equipment exists with the given ID
      DeletionBlockedException - if the equipment has active bookings
    • verifyAvailableForBooking

      public void verifyAvailableForBooking(Equipment equipment)
      Verifies that an equipment item is available for booking (BR-01). Equipment must not be in MAINTENANCE or UNAVAILABLE status. Called by BookingService.createBooking(Booking) before creating a new booking.
      Parameters:
      equipment - the equipment item to check
      Throws:
      EquipmentNotAvailableException - if the equipment status prevents booking
    • updateStatus

      @Transactional public void updateStatus(Long equipmentId, EquipmentStatus newStatus)
      Updates the availability status of an equipment item (BR-08). Called by BookingService when bookings are created (status set to BOOKED) or cancelled (status reverted to AVAILABLE if no other active bookings remain).
      Parameters:
      equipmentId - the ID of the equipment to update
      newStatus - the new status to set
      Throws:
      ResourceNotFoundException - if no equipment exists with the given ID