fix collection creation
This commit is contained in:
@@ -190,10 +190,13 @@ 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++;
|
||||
|
||||
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user