86 lines
2.8 KiB
PHP
86 lines
2.8 KiB
PHP
<?php
|
||
|
||
namespace App\Controller;
|
||
|
||
use App\Repository\IssueRepository;
|
||
use App\Service\RedmineService;
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||
use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
|
||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||
use Symfony\Component\HttpFoundation\Request;
|
||
use Symfony\Component\HttpFoundation\Response;
|
||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||
use Symfony\Component\Routing\Attribute\Route;
|
||
|
||
class IssueController extends AbstractController
|
||
{
|
||
private RedmineService $redmineService;
|
||
|
||
public function __construct(RedmineService $redmineService)
|
||
{
|
||
$this->redmineService = $redmineService;
|
||
}
|
||
|
||
#[Route('/user/issue/{id}', name: 'app_issue_view')]
|
||
public function viewIssue(int $id, IssueRepository $issueRepository): Response
|
||
{
|
||
$issue = $issueRepository->find($id);
|
||
if (!$issue) {
|
||
throw new NotFoundHttpException('La ressource demandée est introuvable.');
|
||
}
|
||
if (!$issue->getProject()->getUsers()->contains($this->getUser())) {
|
||
throw new AccessDeniedException('Vous n\'avez pas accès à cette ressource.');
|
||
}
|
||
|
||
return $this->render('issue/view.html.twig', [
|
||
'issue' => $issue,
|
||
]);
|
||
}
|
||
|
||
#[Route('/user/issue/order/{id}', name: 'app_issue_order', methods: ['POST'])]
|
||
public function orderIssue(int $id, Request $request): JsonResponse
|
||
{
|
||
$data = $request->request;
|
||
|
||
$sourceIssues = $data->all('sourceIssues');
|
||
$source = explode('|', $data->get('source'));
|
||
$sourceStatus = $source[0];
|
||
$sourceSprint = $source[1];
|
||
$sourceVersion = $source[2];
|
||
|
||
$target = explode('|', $data->get('target'));
|
||
$targetStatus = $target[0];
|
||
$targetSprint = $target[1];
|
||
$targetVersion = $target[2];
|
||
|
||
$targetIssues = $data->all('targetIssues');
|
||
|
||
if (!$sourceIssues || !$source || !$targetIssues || !$target) {
|
||
return new JsonResponse(['error' => 'Données incomplètes.'], 400);
|
||
}
|
||
|
||
$payload = [
|
||
'fixed_version_id' => $target,
|
||
];
|
||
|
||
// $redmineService->updateIssue($id, $payload);
|
||
|
||
// ✅ Tu peux stocker l’ordre si besoin dans Redmine via custom field (optionnel)
|
||
// ou en interne selon ta logique métier
|
||
|
||
return new JsonResponse([
|
||
'message' => 'Ordre mis à jour',
|
||
'moved' => $id,
|
||
'sourceIssues' => $sourceIssues,
|
||
'sourceStatus' => $targetStatus,
|
||
'sourceSprint' => $sourceSprint,
|
||
'sourceVersion' => $sourceVersion,
|
||
|
||
'targetIssues' => $targetIssues,
|
||
'targetStatus' => $targetStatus,
|
||
'targetSprint' => $targetSprint,
|
||
'targetVersion' => $targetVersion,
|
||
]);
|
||
}
|
||
}
|