Skip to content

Conversation

@neellii
Copy link

@neellii neellii commented Sep 16, 2025

refs: #194

@DenTray DenTray requested a review from Copilot September 23, 2025 03:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the search request generation to add enhanced validation for the order_by parameter by constraining it to only accept orderable fields from the corresponding model class.

  • Adds model class import to search request templates
  • Updates order_by validation rule to include dynamic field validation using self::getOrderableFields()
  • Updates test fixtures and template generation logic to support the new validation pattern

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/fixtures/RequestGeneratorTest/search_request.php Updated search request fixture with model import and enhanced order_by validation
tests/fixtures/CommandTest/subfolder/search_request.php New search request fixture with model-specific validation
tests/fixtures/CommandTest/search_request.php Updated search request fixture with model import and validation
tests/CommandTest.php Updated test to reference correct fixture path
stubs/request.blade.php Enhanced template to conditionally add model import and order_by validation logic
src/Generators/RequestsGenerator.php Added entityNamespace parameter to template data

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@foreach($parameters as $parameter)
'{{ $parameter['name'] }}' => '{{ implode('|', $parameter['rules']) }}',
@if($method === $requestsGenerator::SEARCH_METHOD && $parameter['name'] === 'order_by')
'{{ $parameter['name'] }}' => '{{ implode('|', $parameter['rules']) }}|in:' . self::getOrderableFields({{ Str::singular($entity) }}::class),
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The validation rule construction concatenates strings in a complex way that could be error-prone. Consider extracting this logic into a helper method or variable for better readability and maintainability.

Suggested change
'{{ $parameter['name'] }}' => '{{ implode('|', $parameter['rules']) }}|in:' . self::getOrderableFields({{ Str::singular($entity) }}::class),
@php
$orderByRule = implode('|', $parameter['rules']) . '|in:' . self::getOrderableFields({{ Str::singular($entity) }}::class);
@endphp
'{{ $parameter['name'] }}' => '{{ $orderByRule }}',

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neellii may we add the in rule in this method

protected function getRules($name, $type, $required, $nullable, $present): array
and just concat the Model namespace in the stub?

@foreach($parameters as $parameter)
'{{ $parameter['name'] }}' => '{{ implode('|', $parameter['rules']) }}',
@if($method === $requestsGenerator::SEARCH_METHOD && $parameter['name'] === 'order_by')
'{{ $parameter['name'] }}' => '{{ implode('|', $parameter['rules']) }}|in:' . self::getOrderableFields({{ Str::singular($entity) }}::class),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neellii may we add the in rule in this method

protected function getRules($name, $type, $required, $nullable, $present): array
and just concat the Model namespace in the stub?

$this->assertGeneratedFileEquals('create_request.php', 'app/Http/Requests/Post/CreatePostRequest.php');
$this->assertGeneratedFileEquals('get_request.php', 'app/Http/Requests/Post/GetPostRequest.php');
$this->assertGeneratedFileEquals('search_request.php', 'app/Http/Requests/Post/SearchPostsRequest.php');
$this->assertGeneratedFileEquals('subfolder/search_request.php', 'app/Http/Requests/Post/SearchPostsRequest.php');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's strange, could you please investigate the reason of why search request generated in the subfolder?

'page' => 'integer',
'per_page' => 'integer',
'order_by' => 'string',
'order_by' => 'string|in:' . self::getOrderableFields(Post::class),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'order_by' => 'string|in:' . self::getOrderableFields(Post::class),
'order_by' => 'string|in:' . $this->getOrderableFields(Post::class),

@DenTray DenTray assigned neellii and unassigned DenTray Sep 23, 2025
@neellii neellii assigned DenTray and unassigned neellii Sep 26, 2025
@DenTray DenTray merged commit 23f100d into master Sep 29, 2025
4 of 6 checks passed
@DenTray DenTray deleted the 194-order-by-request branch September 29, 2025 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants