Przeglądaj źródła

fix(cfc-backend): guard null userId in ArticleService.recordRead to prevent creator_id NOT NULL error

When unauthenticated users call POST /api/articles/record-read, userId is
null. The method previously passed null to task.setCreatorId(), causing a
DataIntegrityViolationException on INSERT. Added null guard before task creation.
Xiaogang Liao 3 miesięcy temu
rodzic
commit
a41ec4b3c3

+ 7 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/ArticleService.java

@@ -187,6 +187,13 @@ public class ArticleService {
             return result;
             return result;
         }
         }
 
 
+        // If no userId, can't create task (unauthenticated request)
+        if (userId == null) {
+            result.put("belowThreshold", true);
+            result.put("minSeconds", minSeconds);
+            return result;
+        }
+
         // 5. Check if a task already exists for this article+child (avoid duplicates)
         // 5. Check if a task already exists for this article+child (avoid duplicates)
         Task existingTask = taskMapper.selectOne(
         Task existingTask = taskMapper.selectOne(
                 new LambdaQueryWrapper<Task>()
                 new LambdaQueryWrapper<Task>()