Skip to content

Conversation

Hafsa-Naeem
Copy link
Contributor

for #11833

Copy link
Contributor

@Vitaliy-1 Vitaliy-1 left a comment

Choose a reason for hiding this comment

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

Thanks, I left a couple of comments

/**
* GET /api/v1/editTaskTemplates
*/
public function index(ListTaskTemplates $illuminateRequest): JsonResponse
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to rename to getMany()

public function index(ListTaskTemplates $illuminateRequest): JsonResponse
{
$context = $this->getRequest()->getContext();
$validated = $illuminateRequest->validated();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need any validation here. It's a get request for the list of templates

}

$items = $q->orderByPkDesc()->get()
->map(fn ($tpl) => (new EditTaskTemplateResource($tpl))->toArray($illuminateRequest))
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to pass a collection of templates instead of a single resource:

EditTaskTemplateResource::collection(Template::query()...->get())

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class ListTaskTemplates extends FormRequest
Copy link
Contributor

Choose a reason for hiding this comment

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

We can just re-use already created class that extends FormRequest, and get requests usually don't require any validation. It's relevant for operations like create and edit

Copy link
Contributor

@Vitaliy-1 Vitaliy-1 left a comment

Choose a reason for hiding this comment

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

One small comment and it's ready to go! Thanks.

{
$context = $this->getRequest()->getContext();

$q = Template::query()
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to use our already established pattern and scopes to avoid snake case props
$collector = Template::byContextId((int) $context->getId())->with('userGroups');

foreach ($request->query() as $param => $val) {
      switch ($param) {
          case 'stageId':
              $collector = $collector->withStageId((int) $val);
              break;
           ...   
      }
}

@Vitaliy-1
Copy link
Contributor

@Hafsa-Naeem, is any help here required? Seems like a small tweak an it's ready to go.

Copy link
Contributor

@Vitaliy-1 Vitaliy-1 left a comment

Choose a reason for hiding this comment

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

Thanks! I've added a couple of comments


// Apply supported filters from query params via model scopes
foreach ($request->query() as $param => $val) {
switch ($param) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you take a look at the example of the params filtering in the submission controller: https://github.com/pkp/pkp-lib/blob/main/api/v1/submissions/PKPSubmissionController.php#L473?

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class EditTaskTemplateResource extends JsonResource
Copy link
Contributor

Choose a reason for hiding this comment

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

@Hafsa-Naeem Hafsa-Naeem merged commit 1fa36e2 into pkp:main Sep 30, 2025
2 checks passed
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.

2 participants