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) {
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
List<Story> stories = storyRepository.findAllById(storyIds);
if (stories.size() != storyIds.size()) {
List<Story> stories = storyRepository.findAllById(uniqueStoryIds);
if (stories.size() != uniqueStoryIds.size()) {
throw new ResourceNotFoundException("One or more stories not found");
}
@@ -203,7 +206,7 @@ public class CollectionService {
// Get starting position
int position = startPosition != null ? startPosition : collectionStoryRepository.getNextPosition(collectionId);
for (UUID storyId : storyIds) {
for (UUID storyId : uniqueStoryIds) {
// Check if story is already in collection
if (collectionStoryRepository.existsByCollectionIdAndStoryId(collectionId, storyId)) {
skipped++;

View File

@@ -359,6 +359,7 @@ export default function CollectionForm({
type="checkbox"
checked={isSelected}
onChange={() => toggleStorySelection(story)}
onClick={(e) => e.stopPropagation()}
className="rounded border-gray-300 text-blue-600 focus:ring-blue-500"
/>
<div className="flex-1 min-w-0">