From b0febfae643fad547453300736eda4c258bff42a Mon Sep 17 00:00:00 2001 From: Stefan Hardegger Date: Tue, 21 Jul 2026 12:25:31 +0200 Subject: [PATCH] fix image upload for collection when editing --- .../controller/CollectionController.java | 19 +++++-------------- .../storycove/service/CollectionService.java | 10 +++++++++- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/com/storycove/controller/CollectionController.java b/backend/src/main/java/com/storycove/controller/CollectionController.java index f00a810..dc72370 100644 --- a/backend/src/main/java/com/storycove/controller/CollectionController.java +++ b/backend/src/main/java/com/storycove/controller/CollectionController.java @@ -126,10 +126,7 @@ public class CollectionController { // Upload cover image if provided if (coverImage != null && !coverImage.isEmpty()) { String imagePath = imageService.uploadImage(coverImage, ImageService.ImageType.COVER); - collection.setCoverImagePath(imagePath); - collection = collectionService.updateCollection( - collection.getId(), null, null, null, null - ); + collection = collectionService.updateCoverImagePath(collection.getId(), imagePath); } logger.info("Successfully created collection with image: {} (ID: {})", collection.getName(), collection.getId()); @@ -255,12 +252,9 @@ public class CollectionController { try { String imagePath = imageService.uploadImage(file, ImageService.ImageType.COVER); - - // Update collection with new cover path - collectionService.updateCollection(id, null, null, null, null); - Collection collection = collectionService.findByIdBasic(id); - collection.setCoverImagePath(imagePath); - + + collectionService.updateCoverImagePath(id, imagePath); + return ResponseEntity.ok(Map.of( "message", "Cover uploaded successfully", "coverPath", imagePath, @@ -278,10 +272,7 @@ public class CollectionController { */ @DeleteMapping("/{id}/cover") public ResponseEntity> removeCoverImage(@PathVariable UUID id) { - Collection collection = collectionService.findByIdBasic(id); - collection.setCoverImagePath(null); - collectionService.updateCollection(id, null, null, null, null); - + collectionService.updateCoverImagePath(id, null); return ResponseEntity.ok(Map.of("message", "Cover removed successfully")); } diff --git a/backend/src/main/java/com/storycove/service/CollectionService.java b/backend/src/main/java/com/storycove/service/CollectionService.java index 7c2f1a6..6d392af 100644 --- a/backend/src/main/java/com/storycove/service/CollectionService.java +++ b/backend/src/main/java/com/storycove/service/CollectionService.java @@ -160,7 +160,15 @@ public class CollectionService { logger.info("Updated collection: {}", id); return savedCollection; } - + + public Collection updateCoverImagePath(UUID id, String coverImagePath) { + Collection collection = findByIdBasic(id); + collection.setCoverImagePath(coverImagePath); + Collection saved = collectionRepository.save(collection); + logger.info("Updated cover image for collection: {}", id); + return saved; + } + /** * Delete a collection (stories remain in the system) */