IndexDiscussionRequest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use App\Models\Discussion;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rule;
  6. /**
  7. * `GET /v3/discussions` 的入参:某个对象上的话题列表。
  8. *
  9. * target 必填:discussions 没有全表可读的用例,不带条件就能拉全表的列表端点是设计错误。
  10. */
  11. class IndexDiscussionRequest extends FormRequest
  12. {
  13. /**
  14. * 可选登录,权限在 Service 里按查看者过滤。
  15. */
  16. public function authorize(): bool
  17. {
  18. return true;
  19. }
  20. /**
  21. * @return array<string, array<int, mixed>>
  22. */
  23. public function rules(): array
  24. {
  25. return [
  26. 'target_type' => ['required', 'string', Rule::in(Discussion::TARGET_TYPES)],
  27. 'target_id' => ['required', 'uuid'],
  28. 'type' => ['sometimes', 'string', Rule::in(Discussion::COMMENT_TYPES)],
  29. 'status' => ['sometimes', 'string', Rule::in(Discussion::STATUSES)],
  30. // 逗号分隔多选,如 error,warning
  31. 'severity' => ['sometimes', 'string', 'regex:/^[a-z]+(,[a-z]+)*$/'],
  32. 'sort' => ['sometimes', 'string', Rule::in(['created_at', '-created_at', 'updated_at', '-updated_at'])],
  33. 'page' => ['integer', 'min:1'],
  34. 'per_page' => ['integer', 'min:1', 'max:200'],
  35. ];
  36. }
  37. }