IndexReactionRequest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use App\Models\Reaction;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rule;
  6. /**
  7. * `GET /v3/reactions` 的入参:某个 target 下的公共 reaction 列表。
  8. *
  9. * `target_id` 必填不是随口加的:likes 表没有全表可读的用例,
  10. * 不带条件就能拉全表的列表端点是设计错误。
  11. */
  12. class IndexReactionRequest extends FormRequest
  13. {
  14. /**
  15. * 公共只读端点,不需要鉴权。
  16. */
  17. public function authorize(): bool
  18. {
  19. return true;
  20. }
  21. /**
  22. * @return array<string, array<int, mixed>>
  23. */
  24. public function rules(): array
  25. {
  26. return [
  27. 'target_id' => ['required', 'uuid'],
  28. 'type' => ['nullable', 'string', Rule::in(Reaction::TYPES)],
  29. 'page' => ['integer', 'min:1'],
  30. // 上限 200 与 v3 其它列表一致:没有上限时 ?per_page=100000 能一次拉空一个 target
  31. 'per_page' => ['integer', 'min:1', 'max:200'],
  32. ];
  33. }
  34. }