TipitakaRelatedParagraphController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Http\Controllers\V3;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\V3\IndexTipitakaRelatedParagraphRequest;
  5. use App\Http\Resources\V3\RelatedParagraphResource;
  6. use App\Services\V3\TipitakaRelatedParagraphService;
  7. /**
  8. * 段落关联关系(mūla / aṭṭhakathā / ṭīkā 的注释对应)。
  9. *
  10. * 取代 `GET /v2/related-paragraph`。按 book_id 分组一本一条,批量联表消除 N+1;
  11. * 新增 `book_name`/`cs_para` 直接过滤器。
  12. */
  13. class TipitakaRelatedParagraphController extends Controller
  14. {
  15. public function __construct(private readonly TipitakaRelatedParagraphService $related) {}
  16. /**
  17. * 列出一个段落的关联段落
  18. *
  19. * 按 book_id 分组,一本书一条,附带书名、标签、目录路径与该书内的段落列表。
  20. * 没有关联段落时返回空集(这是正常结果,不是错误)。
  21. *
  22. * @unauthenticated
  23. *
  24. * @queryParam book integer 典籍文件号(1-217)。与 para 一起用,prohibits 下面那组。Example: 1
  25. * @queryParam para integer 段落号。与 book 一起用。Example: 2
  26. * @queryParam book_name string SC 风格书名缩写(如 dn1、an2)。与 cs_para 一起用,prohibits 上面那组。Example: dn1
  27. * @queryParam cs_para integer 书内段落号。与 book_name 一起用。Example: 4
  28. * @queryParam book_id integer 真书号(book_titles.sn),可选收窄。
  29. *
  30. * @meta count integer 命中的书籍条数
  31. */
  32. public function index(IndexTipitakaRelatedParagraphRequest $request)
  33. {
  34. $rows = $this->related->related($request->validated());
  35. return RelatedParagraphResource::collection($rows)
  36. ->additional(['meta' => ['count' => count($rows)]]);
  37. }
  38. }