fix collection creation

This commit is contained in:
Stefan Hardegger
2026-07-21 10:08:54 +02:00
parent 78c3f1be19
commit dc75cc41ce
2 changed files with 8 additions and 4 deletions

View File

@@ -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++;

View File

@@ -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">