fix collection creation
This commit is contained in:
@@ -191,9 +191,12 @@ public class CollectionService {
|
|||||||
public Map<String, Object> addStoriesToCollection(UUID collectionId, List<UUID> storyIds, Integer startPosition) {
|
public Map<String, Object> addStoriesToCollection(UUID collectionId, List<UUID> storyIds, Integer startPosition) {
|
||||||
Collection collection = findByIdBasic(collectionId);
|
Collection collection = findByIdBasic(collectionId);
|
||||||
|
|
||||||
|
// Deduplicate story IDs before validation (UI may send duplicates due to event handling)
|
||||||
|
List<UUID> uniqueStoryIds = storyIds.stream().distinct().collect(java.util.stream.Collectors.toList());
|
||||||
|
|
||||||
// Validate stories exist
|
// Validate stories exist
|
||||||
List<Story> stories = storyRepository.findAllById(storyIds);
|
List<Story> stories = storyRepository.findAllById(uniqueStoryIds);
|
||||||
if (stories.size() != storyIds.size()) {
|
if (stories.size() != uniqueStoryIds.size()) {
|
||||||
throw new ResourceNotFoundException("One or more stories not found");
|
throw new ResourceNotFoundException("One or more stories not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +206,7 @@ public class CollectionService {
|
|||||||
// Get starting position
|
// Get starting position
|
||||||
int position = startPosition != null ? startPosition : collectionStoryRepository.getNextPosition(collectionId);
|
int position = startPosition != null ? startPosition : collectionStoryRepository.getNextPosition(collectionId);
|
||||||
|
|
||||||
for (UUID storyId : storyIds) {
|
for (UUID storyId : uniqueStoryIds) {
|
||||||
// Check if story is already in collection
|
// Check if story is already in collection
|
||||||
if (collectionStoryRepository.existsByCollectionIdAndStoryId(collectionId, storyId)) {
|
if (collectionStoryRepository.existsByCollectionIdAndStoryId(collectionId, storyId)) {
|
||||||
skipped++;
|
skipped++;
|
||||||
|
|||||||
@@ -359,6 +359,7 @@ export default function CollectionForm({
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={isSelected}
|
checked={isSelected}
|
||||||
onChange={() => toggleStorySelection(story)}
|
onChange={() => toggleStorySelection(story)}
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
className="rounded border-gray-300 text-blue-600 focus:ring-blue-500"
|
className="rounded border-gray-300 text-blue-600 focus:ring-blue-500"
|
||||||
/>
|
/>
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
|
|||||||
Reference in New Issue
Block a user