From 598ad622e795b4b5d68c1e6c52f5415be6df3dc3 Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 8 Jun 2026 19:31:30 +0200 Subject: [PATCH] =?UTF-8?q?fix(journeyitem):=20use=20specific=20error=20co?= =?UTF-8?q?des=20in=20append()=20=E2=80=94=20JOURNEY=5FAT=5FCAPACITY=20and?= =?UTF-8?q?=20GESCHICHTE=5FTYPE=5FMISMATCH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - JourneyItemService.append(): replace VALIDATION_ERROR with GESCHICHTE_TYPE_MISMATCH (409 conflict) for non-JOURNEY type guard and JOURNEY_AT_CAPACITY (409 conflict) for 100-item cap - JourneyItemServiceTest: update assertions to expect the new specific error codes - CLAUDE.md: expand geschichte/ package table entry with GeschichteQueryService and journeyitem/ sub-domain Co-Authored-By: Claude Sonnet 4.6 --- CLAUDE.md | 3 ++- .../geschichte/journeyitem/JourneyItemService.java | 8 ++++---- .../geschichte/journeyitem/JourneyItemServiceTest.java | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 639dd2ba..bba08400 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -86,7 +86,8 @@ backend/src/main/java/org/raddatz/familienarchiv/ │ └── transcription/ TranscriptionBlock, TranscriptionService, TranscriptionBlockQueryService ├── exception/ DomainException, ErrorCode, GlobalExceptionHandler ├── filestorage/ FileService (S3/MinIO) -├── geschichte/ Geschichte (story) domain +├── geschichte/ Geschichte (story) domain — GeschichteService, GeschichteQueryService +│ └── journeyitem/ JourneyItem sub-domain — JourneyItemService, JourneyItemController ├── importing/ CanonicalImportOrchestrator + four loaders (TagTree/PersonRegister/PersonTree/Document) + CanonicalSheetReader ├── notification/ Notification domain + SseEmitterRegistry ├── ocr/ OCR domain — OcrService, OcrBatchService, training diff --git a/backend/src/main/java/org/raddatz/familienarchiv/geschichte/journeyitem/JourneyItemService.java b/backend/src/main/java/org/raddatz/familienarchiv/geschichte/journeyitem/JourneyItemService.java index e05382ec..5b83af6a 100644 --- a/backend/src/main/java/org/raddatz/familienarchiv/geschichte/journeyitem/JourneyItemService.java +++ b/backend/src/main/java/org/raddatz/familienarchiv/geschichte/journeyitem/JourneyItemService.java @@ -47,14 +47,14 @@ public class JourneyItemService { "Journey not found: " + geschichteId)); if (g.getType() != GeschichteType.JOURNEY) { - throw DomainException.badRequest(ErrorCode.VALIDATION_ERROR, - "Geschichte is not a JOURNEY — cannot append items"); + throw DomainException.conflict(ErrorCode.GESCHICHTE_TYPE_MISMATCH, + "Journey items can only be added to a JOURNEY-type Geschichte"); } long count = journeyItemRepository.countByGeschichteId(geschichteId); if (count >= MAX_ITEMS) { - throw DomainException.badRequest(ErrorCode.VALIDATION_ERROR, - "Journey already has the maximum of " + MAX_ITEMS + " items"); + throw DomainException.conflict(ErrorCode.JOURNEY_AT_CAPACITY, + "Journey has reached the maximum of 100 items"); } String note = normalizeNote(dto.getNote()); diff --git a/backend/src/test/java/org/raddatz/familienarchiv/geschichte/journeyitem/JourneyItemServiceTest.java b/backend/src/test/java/org/raddatz/familienarchiv/geschichte/journeyitem/JourneyItemServiceTest.java index f3d9a97f..14e299d9 100644 --- a/backend/src/test/java/org/raddatz/familienarchiv/geschichte/journeyitem/JourneyItemServiceTest.java +++ b/backend/src/test/java/org/raddatz/familienarchiv/geschichte/journeyitem/JourneyItemServiceTest.java @@ -221,7 +221,7 @@ class JourneyItemServiceTest { } @Test - void append_returns400_on_non_JOURNEY_type() { + void append_returns409_on_non_JOURNEY_type() { Geschichte story = Geschichte.builder() .id(geschichteId) .title("Story") @@ -236,7 +236,7 @@ class JourneyItemServiceTest { assertThatThrownBy(() -> journeyItemService.append(geschichteId, dto)) .isInstanceOf(DomainException.class) .satisfies(e -> assertThat(((DomainException) e).getCode()) - .isEqualTo(ErrorCode.VALIDATION_ERROR)); + .isEqualTo(ErrorCode.GESCHICHTE_TYPE_MISMATCH)); } @Test @@ -257,7 +257,7 @@ class JourneyItemServiceTest { } @Test - void append_returns400_when_100_items_exist() { + void append_returns409_when_100_items_exist() { Geschichte journey = journey(geschichteId); when(geschichteRepository.findById(geschichteId)).thenReturn(Optional.of(journey)); when(journeyItemRepository.countByGeschichteId(geschichteId)).thenReturn(100L); @@ -268,7 +268,7 @@ class JourneyItemServiceTest { assertThatThrownBy(() -> journeyItemService.append(geschichteId, dto)) .isInstanceOf(DomainException.class) .satisfies(e -> assertThat(((DomainException) e).getCode()) - .isEqualTo(ErrorCode.VALIDATION_ERROR)); + .isEqualTo(ErrorCode.JOURNEY_AT_CAPACITY)); } @Test