fix image upload for collection when editing
This commit is contained in:
@@ -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<Map<String, String>> 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"));
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user