Files
ninemine/src/Controller/IssueController.php
2025-07-07 17:30:12 +02:00

86 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 lordre 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,
]);
}
}