1
0
Fork 0
mirror of https://github.com/s-frick/effigenix.git synced 2026-03-28 17:39:57 +01:00

feat(inventory): GET Endpoint für einzelnen Lagerort (StorageLocation by ID)

GetStorageLocation Use Case mit AuthorizationPort, GET /{id} Endpoint im Controller.
6 Unit Tests und 5 Integrationstests für alle Edge Cases.
This commit is contained in:
Sebastian Frick 2026-02-23 22:40:30 +01:00
parent df1d1dfdd3
commit 42c9ca9d19
5 changed files with 264 additions and 2 deletions

View file

@ -0,0 +1,40 @@
package de.effigenix.application.inventory;
import de.effigenix.domain.inventory.InventoryAction;
import de.effigenix.domain.inventory.StorageLocation;
import de.effigenix.domain.inventory.StorageLocationError;
import de.effigenix.domain.inventory.StorageLocationId;
import de.effigenix.domain.inventory.StorageLocationRepository;
import de.effigenix.shared.common.Result;
import de.effigenix.shared.security.ActorId;
import de.effigenix.shared.security.AuthorizationPort;
import org.springframework.transaction.annotation.Transactional;
@Transactional(readOnly = true)
public class GetStorageLocation {
private final StorageLocationRepository storageLocationRepository;
private final AuthorizationPort authPort;
public GetStorageLocation(StorageLocationRepository storageLocationRepository, AuthorizationPort authPort) {
this.storageLocationRepository = storageLocationRepository;
this.authPort = authPort;
}
public Result<StorageLocationError, StorageLocation> execute(String storageLocationId, ActorId performedBy) {
if (!authPort.can(performedBy, InventoryAction.STOCK_READ)) {
return Result.failure(new StorageLocationError.Unauthorized("Not authorized to view storage location"));
}
if (storageLocationId == null || storageLocationId.isBlank()) {
return Result.failure(new StorageLocationError.StorageLocationNotFound(storageLocationId));
}
return switch (storageLocationRepository.findById(StorageLocationId.of(storageLocationId))) {
case Result.Failure(var err) -> Result.failure(new StorageLocationError.RepositoryFailure(err.message()));
case Result.Success(var opt) -> opt
.<Result<StorageLocationError, StorageLocation>>map(Result::success)
.orElseGet(() -> Result.failure(new StorageLocationError.StorageLocationNotFound(storageLocationId)));
};
}
}

View file

@ -13,6 +13,7 @@ import de.effigenix.application.inventory.RemoveStockBatch;
import de.effigenix.application.inventory.UnblockStockBatch;
import de.effigenix.application.inventory.CreateStorageLocation;
import de.effigenix.application.inventory.DeactivateStorageLocation;
import de.effigenix.application.inventory.GetStorageLocation;
import de.effigenix.application.inventory.ListStorageLocations;
import de.effigenix.application.inventory.UpdateStorageLocation;
import de.effigenix.application.usermanagement.AuditLogger;
@ -38,8 +39,8 @@ public class InventoryUseCaseConfiguration {
}
@Bean
public DeactivateStorageLocation deactivateStorageLocation(StorageLocationRepository storageLocationRepository) {
return new DeactivateStorageLocation(storageLocationRepository);
public DeactivateStorageLocation deactivateStorageLocation(StorageLocationRepository storageLocationRepository, StockRepository stockRepository) {
return new DeactivateStorageLocation(storageLocationRepository, stockRepository);
}
@Bean
@ -47,6 +48,11 @@ public class InventoryUseCaseConfiguration {
return new ActivateStorageLocation(storageLocationRepository);
}
@Bean
public GetStorageLocation getStorageLocation(StorageLocationRepository storageLocationRepository, AuthorizationPort authorizationPort) {
return new GetStorageLocation(storageLocationRepository, authorizationPort);
}
@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.GetStorageLocation;
import de.effigenix.application.inventory.ListStorageLocations;
import de.effigenix.application.inventory.UpdateStorageLocation;
import de.effigenix.application.inventory.command.CreateStorageLocationCommand;
@ -34,6 +35,7 @@ public class StorageLocationController {
private static final Logger logger = LoggerFactory.getLogger(StorageLocationController.class);
private final CreateStorageLocation createStorageLocation;
private final GetStorageLocation getStorageLocation;
private final UpdateStorageLocation updateStorageLocation;
private final DeactivateStorageLocation deactivateStorageLocation;
private final ActivateStorageLocation activateStorageLocation;
@ -41,12 +43,14 @@ public class StorageLocationController {
public StorageLocationController(
CreateStorageLocation createStorageLocation,
GetStorageLocation getStorageLocation,
UpdateStorageLocation updateStorageLocation,
DeactivateStorageLocation deactivateStorageLocation,
ActivateStorageLocation activateStorageLocation,
ListStorageLocations listStorageLocations
) {
this.createStorageLocation = createStorageLocation;
this.getStorageLocation = getStorageLocation;
this.updateStorageLocation = updateStorageLocation;
this.deactivateStorageLocation = deactivateStorageLocation;
this.activateStorageLocation = activateStorageLocation;
@ -71,6 +75,22 @@ public class StorageLocationController {
return ResponseEntity.ok(response);
}
@GetMapping("/{id}")
@PreAuthorize("hasAuthority('STOCK_READ') or hasAuthority('STOCK_WRITE')")
public ResponseEntity<StorageLocationResponse> getStorageLocation(
@PathVariable("id") String storageLocationId,
Authentication authentication
) {
var actorId = extractActorId(authentication);
var result = getStorageLocation.execute(storageLocationId, actorId);
if (result.isFailure()) {
throw new StorageLocationDomainErrorException(result.unsafeGetError());
}
return ResponseEntity.ok(StorageLocationResponse.from(result.unsafeGetValue()));
}
@PostMapping
@PreAuthorize("hasAuthority('STOCK_WRITE')")
public ResponseEntity<StorageLocationResponse> createStorageLocation(