fix image upload for collection when editing

This commit is contained in:
Stefan Hardegger
2026-07-21 12:25:31 +02:00
parent dc75cc41ce
commit b0febfae64
2 changed files with 14 additions and 15 deletions

View File

@@ -126,10 +126,7 @@ public class CollectionController {
// Upload cover image if provided // Upload cover image if provided
if (coverImage != null && !coverImage.isEmpty()) { if (coverImage != null && !coverImage.isEmpty()) {
String imagePath = imageService.uploadImage(coverImage, ImageService.ImageType.COVER); String imagePath = imageService.uploadImage(coverImage, ImageService.ImageType.COVER);
collection.setCoverImagePath(imagePath); collection = collectionService.updateCoverImagePath(collection.getId(), imagePath);
collection = collectionService.updateCollection(
collection.getId(), null, null, null, null
);
} }
logger.info("Successfully created collection with image: {} (ID: {})", collection.getName(), collection.getId()); logger.info("Successfully created collection with image: {} (ID: {})", collection.getName(), collection.getId());
@@ -256,10 +253,7 @@ public class CollectionController {
try { try {
String imagePath = imageService.uploadImage(file, ImageService.ImageType.COVER); String imagePath = imageService.uploadImage(file, ImageService.ImageType.COVER);
// Update collection with new cover path collectionService.updateCoverImagePath(id, imagePath);
collectionService.updateCollection(id, null, null, null, null);
Collection collection = collectionService.findByIdBasic(id);
collection.setCoverImagePath(imagePath);
return ResponseEntity.ok(Map.of( return ResponseEntity.ok(Map.of(
"message", "Cover uploaded successfully", "message", "Cover uploaded successfully",
@@ -278,10 +272,7 @@ public class CollectionController {
*/ */
@DeleteMapping("/{id}/cover") @DeleteMapping("/{id}/cover")
public ResponseEntity<Map<String, String>> removeCoverImage(@PathVariable UUID id) { public ResponseEntity<Map<String, String>> removeCoverImage(@PathVariable UUID id) {
Collection collection = collectionService.findByIdBasic(id); collectionService.updateCoverImagePath(id, null);
collection.setCoverImagePath(null);
collectionService.updateCollection(id, null, null, null, null);
return ResponseEntity.ok(Map.of("message", "Cover removed successfully")); return ResponseEntity.ok(Map.of("message", "Cover removed successfully"));
} }

View File

@@ -161,6 +161,14 @@ public class CollectionService {
return savedCollection; 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) * Delete a collection (stories remain in the system)
*/ */