2
0

StudioChannelController.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Http\Controllers\V3;
  3. use App\Http\Controllers\Concerns\ResolvesCurrentUser;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\Requests\V3\IndexStudioChannelRequest;
  6. use App\Http\Requests\V3\StoreChannelRequest;
  7. use App\Http\Resources\V3\ChannelResource;
  8. use App\Services\V3\ChannelService;
  9. /**
  10. * 某个 studio(本人或团队)的 channel:工作区列表与新建。
  11. *
  12. * 取代 `GET /v2/channel?view=studio|studio-all`(含 `view2`、`collaborator`)、`GET /v2/channel-my-number`
  13. * (数量读 `meta.total`)与 `POST /v2/channel`(`ChannelController`)。`{studio}` 一律是 uuid:
  14. * 用户 uuid 或团队 uuid(团队空间)。v2 那份在 dashboard-v4 下线前原样保留,不要改动。
  15. */
  16. class StudioChannelController extends Controller
  17. {
  18. use ResolvesCurrentUser;
  19. public function __construct(private readonly ChannelService $channels) {}
  20. /**
  21. * 列出 studio 的 channel
  22. *
  23. * 只有本人,或该团队的成员能看。`relation`:own 它名下的(默认),shared 直接共享给它的
  24. * (个人空间不含经团队转来的——团队的在团队空间里看),all 两者合起来。
  25. *
  26. * @urlParam studio string required 用户 uuid 或团队 uuid
  27. *
  28. * @queryParam relation string 关系。Enum: own,shared,all Default: own
  29. * @queryParam collaborator string 只看这个拥有者共享过来的(uuid)
  30. * @queryParam search string 按名字模糊匹配
  31. * @queryParam type string channel 类型。Enum: translation,nissaya,original,wbw,commentary,similar
  32. * @queryParam lang string 语言
  33. * @queryParam book integer 章节所在的书(与 para 同时给)
  34. * @queryParam para integer 章节起始段(与 book 同时给)
  35. * @queryParam order string 排序字段。Enum: updated_at,created_at,name,progress Default: updated_at
  36. * @queryParam dir string 排序方向。Enum: asc,desc Default: desc
  37. * @queryParam page integer 页码。Default: 1
  38. * @queryParam per_page integer 每页数量,最大 200。Default: 20
  39. *
  40. * @responseStatus 403 不能查看这个 studio
  41. */
  42. public function index(IndexStudioChannelRequest $request, string $studio)
  43. {
  44. return ChannelResource::collection($this->channels->listForStudio(
  45. $studio,
  46. $this->currentUser($request)['user_uid'],
  47. $request->safe()->except(['page', 'per_page']),
  48. $request->integer('per_page', 20),
  49. ));
  50. }
  51. /**
  52. * 在 studio 名下建 channel
  53. *
  54. * 本人名下,或团队名下(团队 owner / manager)。同一 studio 内不能重名。默认私有。AI 模型不能建。
  55. *
  56. * @urlParam studio string required 用户 uuid 或团队 uuid
  57. *
  58. * @bodyParam name string required 名字,最长 128
  59. * @bodyParam type string required 类型。Enum: translation,nissaya,original,wbw,commentary,similar
  60. * @bodyParam lang string required 语言,最长 16
  61. * @bodyParam summary string 简介,最长 1024
  62. * @bodyParam status integer 10 私有、20 公开不列出(拿到链接能看,不进任何公开列表)、30 公开。Default: 10
  63. * @bodyParam source_type string 来源。Enum: original,reprint,ai
  64. * @bodyParam source_id string 来源 id
  65. *
  66. * @responseStatus 201 建好了
  67. * @responseStatus 403 不能在这个 studio 名下建
  68. */
  69. public function store(StoreChannelRequest $request, string $studio)
  70. {
  71. $user = $this->currentUser($request);
  72. return ChannelResource::make($this->channels->create(
  73. $studio,
  74. $user['user_uid'],
  75. (int) $user['user_id'],
  76. $request->validated(),
  77. ));
  78. }
  79. }