Class EquipmentService
java.lang.Object
com.equipmentrental.equipment_rental_system.service.EquipmentService
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 Summary
ConstructorsConstructorDescriptionEquipmentService(EquipmentRepository equipmentRepository, BookingRepository bookingRepository) -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteById(Long equipmentId) Deletes an equipment item if it has no active (confirmed) bookings (BR-07).findAll()Returns all equipment items in the system.findByCategoryId(Long categoryId) Finds all equipment items belonging to a specific category.Finds an equipment item by its ID.findByStatus(EquipmentStatus status) Finds all equipment items with a specific availability status.Saves a new or updated equipment item.searchByName(String name) Searches for equipment items whose name contains the given text (case-insensitive).voidupdateStatus(Long equipmentId, EquipmentStatus newStatus) Updates the availability status of an equipment item (BR-08).voidverifyAvailableForBooking(Equipment equipment) Verifies that an equipment item is available for booking (BR-01).
-
Constructor Details
-
EquipmentService
public EquipmentService(EquipmentRepository equipmentRepository, BookingRepository bookingRepository)
-
-
Method Details
-
findAll
-
findById
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
-
findByStatus
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
-
save
-
deleteById
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 IDDeletionBlockedException- if the equipment has active bookings
-
verifyAvailableForBooking
Verifies that an equipment item is available for booking (BR-01). Equipment must not be in MAINTENANCE or UNAVAILABLE status. Called byBookingService.createBooking(Booking)before creating a new booking.- Parameters:
equipment- the equipment item to check- Throws:
EquipmentNotAvailableException- if the equipment status prevents booking
-
updateStatus
Updates the availability status of an equipment item (BR-08). Called byBookingServicewhen 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 updatenewStatus- the new status to set- Throws:
ResourceNotFoundException- if no equipment exists with the given ID
-