<?php
/*
* Created on Fri Dec 02 2022
*
* DAVID-OLIVIER DESCOMBES
*
* @licence
* You may not sell, sub-license, rent or lease any portion of the Software or Documentation to anyone.
*
* Copyright (c) 2022 dodarchitecte.com (https://dodarchitecte.com)
*
* Developed by developpeur-informatique.ma (https://www.developpeur-informatique.ma)
*/
namespace App\Controller\Project;
use App\Entity\Project\Project;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\AsController;
// use App\Service\FileUploader;
#[AsController]
final class ProjectPurchasesController extends AbstractController
{
public function __invoke(Project $project): JsonResponse
{
$projectPurchases = $project->getPurchases();
$purchases = [];
foreach ($projectPurchases as $purchase) {
$purchases[] = $purchase;
}
usort($purchases, function ($a, $b) {
return $a->getId() < $b->getId();
});
// return $this->json($purchases, 200, []);
return $this->json($purchases, 200, [], ['groups' => ['Project:purchases']]);
}
}