BatchCountDiscussionRequest.php 878 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Validation\Rule;
  5. /**
  6. * `POST /v3/discussions/batch-count` 的入参:一批讨论对象(句子 / 逐词)。
  7. *
  8. * 用 POST 是因为一页可能有几百个对象,uuid 放查询串会超长。上限写死,免得一次请求拖垮库。
  9. */
  10. class BatchCountDiscussionRequest extends FormRequest
  11. {
  12. public const MAX_TARGETS = 500;
  13. public function authorize(): bool
  14. {
  15. return true;
  16. }
  17. /**
  18. * @return array<string, array<int, mixed>>
  19. */
  20. public function rules(): array
  21. {
  22. return [
  23. 'targets' => ['required', 'array', 'min:1', 'max:'.self::MAX_TARGETS],
  24. 'targets.*.type' => ['required', 'string', Rule::in(['sentence', 'wbw'])],
  25. 'targets.*.id' => ['required', 'uuid'],
  26. ];
  27. }
  28. }