Ver Fonte

feat(api-v13): 新建批注的 title 改为非必填

批注 / 脚注、注释对照这类正文就是全部,本来就没有标题;审稿意见 / 问答 /
求助才需要。store() 去掉 title 的 required 规则,docblock 同步,补一条
「不给 title 也能建」的测试。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
visuddhinanda há 3 semanas atrás
pai
commit
915e1d360e

+ 1 - 2
api-v13/app/Http/Controllers/DiscussionController.php

@@ -338,7 +338,7 @@ class DiscussionController extends Controller
      * @bodyParam parent string 父讨论 id,传入表示这是一条回复
      * @bodyParam res_id string required 关联资源 uid(有 parent 时忽略并继承父节点)
      * @bodyParam res_type string required 关联资源类型(有 parent 时忽略并继承父节点)。Enum: sentence,wbw,article
-     * @bodyParam title string required 标题(有 parent 时非必填)
+     * @bodyParam title string 标题(可选)
      * @bodyParam content string 正文内容
      * @bodyParam content_type string 正文格式。Default: markdown
      * @bodyParam type string 讨论类型。Enum: discussion,qa,help,note,commentary Default: discussion
@@ -377,7 +377,6 @@ class DiscussionController extends Controller
             $rules = array_merge([
                 'res_id' => 'required',
                 'res_type' => 'required',
-                'title' => 'required',
             ], $annotationRules);
         }
 

+ 15 - 0
api-v13/tests/Feature/DiscussionControllerTest.php

@@ -61,6 +61,21 @@ it('leaves annotation selector fields null when not provided', function () {
     expect($saved->quote_suffix)->toBeNull();
 });
 
+it('creates a discussion without a title', function () {
+    $userUid = makeStudio('annotator');
+
+    $this->postJson('/api/v2/discussion', [
+        'res_id' => (string) Str::uuid(),
+        'res_type' => 'sentence',
+        'type' => 'note',
+        'content' => '这里的 dassana 指见到佛陀。',
+        'notification' => false,
+    ], authHeader($userUid))->assertOk();
+
+    // 批注 / 脚注一类正文就是全部,标题可以没有
+    expect(Discussion::where('editor_uid', $userUid)->first()->title)->toBeNull();
+});
+
 it('rejects an invalid annotation selector', function () {
     $userUid = makeStudio('annotator');