Class LoadUnitService

java.lang.Object
com.v1rex.liftnexus.loadunit.service.LoadUnitService

@Service public class LoadUnitService extends Object
Service layer for managing LoadUnit entities.

This class provides two tiers of access:

  • External API Boundary – Methods that return DTOs (LoadUnitResponse) to controllers and external callers. These methods handle validation, business logic, and mapping.
  • Internal Domain Boundary – Methods that return domain entities (LoadUnit) for use by other services, internal components, or the Timefold solver, bypassing DTO conversion.
  • Constructor Details

    • LoadUnitService

      public LoadUnitService()
  • Method Details

    • createLoadUnit

      @Transactional public LoadUnitResponse createLoadUnit(LoadUnitRequest request)
      Creates a new load unit and persists it to the database.

      Before persisting, this method validates that the provided trackingCode is unique. If a storage bin ID is supplied, the load unit will be assigned to the referenced bin (the bin must already exist).

      Parameters:
      request - the DTO containing the load unit details (tracking code, weight, optional storage bin ID, etc.)
      Returns:
      a LoadUnitResponse representing the newly created and saved load unit
      Throws:
      LoadUnitTrackingCodeExistsException - if a load unit with the same tracking code already exists
    • findById

      @Transactional(readOnly=true) public LoadUnitResponse findById(Long id)
      Retrieves a load unit by its database ID and returns it as a DTO.
      Parameters:
      id - the primary key of the load unit
      Returns:
      a LoadUnitResponse for the matching load unit
      Throws:
      LoadUnitNotFoundException - if no load unit exists with the given id
    • findByTrackingCode

      @Transactional(readOnly=true) public LoadUnitResponse findByTrackingCode(String trackingCode)
      Retrieves a load unit by its unique tracking code and returns it as a DTO.
      Parameters:
      trackingCode - the unique tracking code to search for
      Returns:
      a LoadUnitResponse for the matching load unit
      Throws:
      LoadUnitNotFoundException - if no load unit exists with the given trackingCode
    • findAll

      @Transactional(readOnly=true) public org.springframework.data.domain.Page<LoadUnitResponse> findAll(org.springframework.data.domain.Pageable pageable)
      Returns a paginated list of all load units as DTOs.
      Parameters:
      pageable - pagination and sorting configuration
      Returns:
      a Page of LoadUnitResponse
    • findByStatus

      @Transactional(readOnly=true) public org.springframework.data.domain.Page<LoadUnitResponse> findByStatus(LoadUnitStatus status, org.springframework.data.domain.Pageable pageable)
      Returns a paginated list of load units filtered by the given LoadUnitStatus as DTOs.
      Parameters:
      status - the status to filter by (e.g. AVAILABLE, RESERVED, etc.)
      pageable - pagination and sorting configuration
      Returns:
      a Page of LoadUnitResponse matching the specified status
    • findEntityById

      public LoadUnit findEntityById(Long id)
      Finds a load unit entity by its database ID.

      This method is intended for internal use by other services, domain components, or the Timefold solver that require direct access to the domain entity rather than a DTO.

      Parameters:
      id - the primary key of the load unit
      Returns:
      the LoadUnit entity
      Throws:
      LoadUnitNotFoundException - if no load unit exists with the given id
    • findEntityByTrackingCode

      public LoadUnit findEntityByTrackingCode(String trackingCode)
      Finds a load unit entity by its unique tracking code.

      This method is intended for internal use by other services, domain components, or the Timefold solver that require direct access to the domain entity rather than a DTO.

      Parameters:
      trackingCode - the unique tracking code to search for
      Returns:
      the LoadUnit entity
      Throws:
      LoadUnitNotFoundException - if no load unit exists with the given trackingCode
    • findAllEntities

      public org.springframework.data.domain.Page<LoadUnit> findAllEntities(org.springframework.data.domain.Pageable pageable)
      Returns a paginated list of all load unit entities.

      This method is intended for internal use by other services, domain components, or the Timefold solver that require direct access to the domain entity rather than a DTO.

      Parameters:
      pageable - pagination and sorting configuration
      Returns:
      a Page of LoadUnit entities
    • findEntitiesByStatus

      public org.springframework.data.domain.Page<LoadUnit> findEntitiesByStatus(LoadUnitStatus status, org.springframework.data.domain.Pageable pageable)
      Returns a paginated list of load unit entities filtered by the given LoadUnitStatus.

      This method is intended for internal use by other services, domain components, or the Timefold solver that require direct access to the domain entity rather than a DTO.

      Parameters:
      status - the status to filter by
      pageable - pagination and sorting configuration
      Returns:
      a Page of LoadUnit entities matching the specified status