mirror of
https://github.com/s-frick/effigenix.git
synced 2026-03-28 15:49:35 +01:00
fix(inventory): Instant.MIN/MAX, performed_at-Index, batchReference-Naming und -Validierung, Lasttest-Zeiträume
- Instant.MIN/MAX durch separate Repository-Methoden ersetzt (findAllByPerformedAtAfter/Before) - DB-Index auf performed_at für Zeitraum-Abfragen - Naming-Konsistenz: findAllByBatchId → findAllByBatchReference im Domain-Repository - batchReference-Validierung (Blank-Check) mit InvalidBatchReference-Error - Lasttest: variierende Zeiträume (7–90 Tage) statt statischem 10-Jahres-Fenster
This commit is contained in:
parent
0e5d8f7025
commit
a8bbe3a951
9 changed files with 114 additions and 25 deletions
|
|
@ -62,7 +62,11 @@ public class ListStockMovements {
|
|||
}
|
||||
|
||||
if (batchReference != null) {
|
||||
return mapResult(stockMovementRepository.findAllByBatchId(batchReference));
|
||||
if (batchReference.isBlank()) {
|
||||
return Result.failure(new StockMovementError.InvalidBatchReference(
|
||||
"Batch reference must not be blank"));
|
||||
}
|
||||
return mapResult(stockMovementRepository.findAllByBatchReference(batchReference));
|
||||
}
|
||||
|
||||
if (movementType != null) {
|
||||
|
|
@ -81,9 +85,13 @@ public class ListStockMovements {
|
|||
return Result.failure(new StockMovementError.InvalidDateRange(
|
||||
"'from' must not be after 'to'"));
|
||||
}
|
||||
Instant effectiveFrom = from != null ? from : Instant.MIN;
|
||||
Instant effectiveTo = to != null ? to : Instant.MAX;
|
||||
return mapResult(stockMovementRepository.findAllByPerformedAtBetween(effectiveFrom, effectiveTo));
|
||||
if (from != null && to != null) {
|
||||
return mapResult(stockMovementRepository.findAllByPerformedAtBetween(from, to));
|
||||
}
|
||||
if (from != null) {
|
||||
return mapResult(stockMovementRepository.findAllByPerformedAtAfter(from));
|
||||
}
|
||||
return mapResult(stockMovementRepository.findAllByPerformedAtBefore(to));
|
||||
}
|
||||
|
||||
return mapResult(stockMovementRepository.findAll());
|
||||
|
|
|
|||
|
|
@ -20,9 +20,13 @@ public interface StockMovementRepository {
|
|||
|
||||
Result<RepositoryError, List<StockMovement>> findAllByMovementType(MovementType movementType);
|
||||
|
||||
Result<RepositoryError, List<StockMovement>> findAllByBatchId(String batchId);
|
||||
Result<RepositoryError, List<StockMovement>> findAllByBatchReference(String batchReference);
|
||||
|
||||
Result<RepositoryError, List<StockMovement>> findAllByPerformedAtBetween(Instant from, Instant to);
|
||||
|
||||
Result<RepositoryError, List<StockMovement>> findAllByPerformedAtAfter(Instant from);
|
||||
|
||||
Result<RepositoryError, List<StockMovement>> findAllByPerformedAtBefore(Instant to);
|
||||
|
||||
Result<RepositoryError, Void> save(StockMovement stockMovement);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,14 +95,14 @@ public class JpaStockMovementRepository implements StockMovementRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result<RepositoryError, List<StockMovement>> findAllByBatchId(String batchId) {
|
||||
public Result<RepositoryError, List<StockMovement>> findAllByBatchReference(String batchReference) {
|
||||
try {
|
||||
List<StockMovement> result = jpaRepository.findAllByBatchId(batchId).stream()
|
||||
List<StockMovement> result = jpaRepository.findAllByBatchId(batchReference).stream()
|
||||
.map(mapper::toDomain)
|
||||
.toList();
|
||||
return Result.success(result);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Database error in findAllByBatchId", e);
|
||||
logger.warn("Database error in findAllByBatchReference", e);
|
||||
return Result.failure(new RepositoryError.DatabaseError(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
|
@ -120,6 +120,32 @@ public class JpaStockMovementRepository implements StockMovementRepository {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<RepositoryError, List<StockMovement>> findAllByPerformedAtAfter(Instant from) {
|
||||
try {
|
||||
List<StockMovement> result = jpaRepository.findAllByPerformedAtGreaterThanEqual(from).stream()
|
||||
.map(mapper::toDomain)
|
||||
.toList();
|
||||
return Result.success(result);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Database error in findAllByPerformedAtAfter", e);
|
||||
return Result.failure(new RepositoryError.DatabaseError(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<RepositoryError, List<StockMovement>> findAllByPerformedAtBefore(Instant to) {
|
||||
try {
|
||||
List<StockMovement> result = jpaRepository.findAllByPerformedAtLessThanEqual(to).stream()
|
||||
.map(mapper::toDomain)
|
||||
.toList();
|
||||
return Result.success(result);
|
||||
} catch (Exception e) {
|
||||
logger.warn("Database error in findAllByPerformedAtBefore", e);
|
||||
return Result.failure(new RepositoryError.DatabaseError(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Result<RepositoryError, Void> save(StockMovement stockMovement) {
|
||||
|
|
|
|||
|
|
@ -17,4 +17,8 @@ public interface StockMovementJpaRepository extends JpaRepository<StockMovementE
|
|||
List<StockMovementEntity> findAllByBatchId(String batchId);
|
||||
|
||||
List<StockMovementEntity> findAllByPerformedAtBetween(Instant from, Instant to);
|
||||
|
||||
List<StockMovementEntity> findAllByPerformedAtGreaterThanEqual(Instant from);
|
||||
|
||||
List<StockMovementEntity> findAllByPerformedAtLessThanEqual(Instant to);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<databaseChangeLog
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
|
||||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
|
||||
|
||||
<changeSet id="031-add-performed-at-index-to-stock-movements" author="effigenix">
|
||||
<createIndex indexName="idx_stock_movements_performed_at" tableName="stock_movements">
|
||||
<column name="performed_at"/>
|
||||
</createIndex>
|
||||
</changeSet>
|
||||
|
||||
</databaseChangeLog>
|
||||
|
|
@ -35,5 +35,6 @@
|
|||
<include file="db/changelog/changes/028-create-stock-movements-table.xml"/>
|
||||
<include file="db/changelog/changes/029-seed-stock-movement-permissions.xml"/>
|
||||
<include file="db/changelog/changes/030-add-batch-id-index-to-stock-movements.xml"/>
|
||||
<include file="db/changelog/changes/031-add-performed-at-index-to-stock-movements.xml"/>
|
||||
|
||||
</databaseChangeLog>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue