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