1
0
Fork 0
mirror of https://github.com/s-frick/effigenix.git synced 2026-03-28 19:30:16 +01:00

feat(inventory): Lagerorte abfragen mit Filter nach Typ und Status (#3)

Query UseCase: ListStorageLocations mit optionalen Filtern storageType und active
GET /api/inventory/storage-locations mit STOCK_READ oder STOCK_WRITE
Tests: 10 neue Integrationstests (35 gesamt)
This commit is contained in:
Sebastian Frick 2026-02-19 12:42:25 +01:00
parent 9b9b7311d1
commit 6010820944
4 changed files with 224 additions and 2 deletions

View file

@ -0,0 +1,51 @@
package de.effigenix.application.inventory;
import de.effigenix.domain.inventory.*;
import de.effigenix.shared.common.RepositoryError;
import de.effigenix.shared.common.Result;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional(readOnly = true)
public class ListStorageLocations {
private final StorageLocationRepository storageLocationRepository;
public ListStorageLocations(StorageLocationRepository storageLocationRepository) {
this.storageLocationRepository = storageLocationRepository;
}
public Result<StorageLocationError, List<StorageLocation>> execute(String storageType, Boolean active) {
if (storageType != null) {
return findByStorageType(storageType, active);
}
if (Boolean.TRUE.equals(active)) {
return mapResult(storageLocationRepository.findActive());
}
return mapResult(storageLocationRepository.findAll());
}
private Result<StorageLocationError, List<StorageLocation>> findByStorageType(String storageType, Boolean active) {
StorageType type;
try {
type = StorageType.valueOf(storageType);
} catch (IllegalArgumentException e) {
return Result.failure(new StorageLocationError.InvalidStorageType(storageType));
}
var result = mapResult(storageLocationRepository.findByStorageType(type));
if (result.isSuccess() && Boolean.TRUE.equals(active)) {
return Result.success(result.unsafeGetValue().stream().filter(StorageLocation::active).toList());
}
return result;
}
private Result<StorageLocationError, List<StorageLocation>> mapResult(
Result<RepositoryError, List<StorageLocation>> result) {
return switch (result) {
case Result.Failure(var err) -> Result.failure(new StorageLocationError.RepositoryFailure(err.message()));
case Result.Success(var locations) -> Result.success(locations);
};
}
}

View file

@ -3,6 +3,7 @@ package de.effigenix.infrastructure.config;
import de.effigenix.application.inventory.ActivateStorageLocation;
import de.effigenix.application.inventory.CreateStorageLocation;
import de.effigenix.application.inventory.DeactivateStorageLocation;
import de.effigenix.application.inventory.ListStorageLocations;
import de.effigenix.application.inventory.UpdateStorageLocation;
import de.effigenix.domain.inventory.StorageLocationRepository;
import org.springframework.context.annotation.Bean;
@ -32,4 +33,9 @@ public class InventoryUseCaseConfiguration {
public ActivateStorageLocation activateStorageLocation(StorageLocationRepository storageLocationRepository) {
return new ActivateStorageLocation(storageLocationRepository);
}
@Bean
public ListStorageLocations listStorageLocations(StorageLocationRepository storageLocationRepository) {
return new ListStorageLocations(storageLocationRepository);
}
}

View file

@ -3,6 +3,7 @@ package de.effigenix.infrastructure.inventory.web.controller;
import de.effigenix.application.inventory.ActivateStorageLocation;
import de.effigenix.application.inventory.CreateStorageLocation;
import de.effigenix.application.inventory.DeactivateStorageLocation;
import de.effigenix.application.inventory.ListStorageLocations;
import de.effigenix.application.inventory.UpdateStorageLocation;
import de.effigenix.application.inventory.command.CreateStorageLocationCommand;
import de.effigenix.application.inventory.command.UpdateStorageLocationCommand;
@ -22,6 +23,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/inventory/storage-locations")
@SecurityRequirement(name = "Bearer Authentication")
@ -34,17 +37,38 @@ public class StorageLocationController {
private final UpdateStorageLocation updateStorageLocation;
private final DeactivateStorageLocation deactivateStorageLocation;
private final ActivateStorageLocation activateStorageLocation;
private final ListStorageLocations listStorageLocations;
public StorageLocationController(
CreateStorageLocation createStorageLocation,
UpdateStorageLocation updateStorageLocation,
DeactivateStorageLocation deactivateStorageLocation,
ActivateStorageLocation activateStorageLocation
ActivateStorageLocation activateStorageLocation,
ListStorageLocations listStorageLocations
) {
this.createStorageLocation = createStorageLocation;
this.updateStorageLocation = updateStorageLocation;
this.deactivateStorageLocation = deactivateStorageLocation;
this.activateStorageLocation = activateStorageLocation;
this.listStorageLocations = listStorageLocations;
}
@GetMapping
@PreAuthorize("hasAuthority('STOCK_READ') or hasAuthority('STOCK_WRITE')")
public ResponseEntity<List<StorageLocationResponse>> listStorageLocations(
@RequestParam(value = "storageType", required = false) String storageType,
@RequestParam(value = "active", required = false) Boolean active
) {
var result = listStorageLocations.execute(storageType, active);
if (result.isFailure()) {
throw new StorageLocationDomainErrorException(result.unsafeGetError());
}
var response = result.unsafeGetValue().stream()
.map(StorageLocationResponse::from)
.toList();
return ResponseEntity.ok(response);
}
@PostMapping