Class LoadUnitService
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateLoadUnit(LoadUnitRequest request) Creates a new load unit and persists it to the database.org.springframework.data.domain.Page<LoadUnitResponse> findAll(org.springframework.data.domain.Pageable pageable) Returns a paginated list of all load units as DTOs.org.springframework.data.domain.Page<LoadUnit> findAllEntities(org.springframework.data.domain.Pageable pageable) Returns a paginated list of all load unit entities.Retrieves a load unit by its database ID and returns it as a DTO.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 givenLoadUnitStatusas DTOs.findByTrackingCode(String trackingCode) Retrieves a load unit by its unique tracking code and returns it as a DTO.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 givenLoadUnitStatus.findEntityById(Long id) Finds a load unit entity by its database ID.findEntityByTrackingCode(String trackingCode) Finds a load unit entity by its unique tracking code.
-
Constructor Details
-
LoadUnitService
public LoadUnitService()
-
-
Method Details
-
createLoadUnit
Creates a new load unit and persists it to the database.Before persisting, this method validates that the provided
trackingCodeis 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
LoadUnitResponserepresenting the newly created and saved load unit - Throws:
LoadUnitTrackingCodeExistsException- if a load unit with the same tracking code already exists
-
findById
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
LoadUnitResponsefor the matching load unit - Throws:
LoadUnitNotFoundException- if no load unit exists with the givenid
-
findByTrackingCode
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
LoadUnitResponsefor the matching load unit - Throws:
LoadUnitNotFoundException- if no load unit exists with the giventrackingCode
-
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
PageofLoadUnitResponse
-
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 givenLoadUnitStatusas DTOs.- Parameters:
status- the status to filter by (e.g.AVAILABLE,RESERVED, etc.)pageable- pagination and sorting configuration- Returns:
- a
PageofLoadUnitResponsematching the specified status
-
findEntityById
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
LoadUnitentity - Throws:
LoadUnitNotFoundException- if no load unit exists with the givenid
-
findEntityByTrackingCode
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
LoadUnitentity - Throws:
LoadUnitNotFoundException- if no load unit exists with the giventrackingCode
-
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
PageofLoadUnitentities
-
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 givenLoadUnitStatus.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 bypageable- pagination and sorting configuration- Returns:
- a
PageofLoadUnitentities matching the specified status
-