fix: address code review issues
- Rename `read` column to `is_read` (PostgreSQL reserved word) - Wrap navbar + modal in parent div for Stimulus controller scope - Set temporary filePath before first flush in ImportController - Use RETURNING clause for atomic incrementProcessedBatches - Return proper empty 204 response in NotificationController Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,7 @@ final class Version20260329000003 extends AbstractMigration
|
|||||||
public function up(Schema $schema): void
|
public function up(Schema $schema): void
|
||||||
{
|
{
|
||||||
// this up() migration is auto-generated, please modify it to your needs
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
$this->addSql('CREATE TABLE notification (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, user_id INT NOT NULL, message VARCHAR(255) NOT NULL, read BOOLEAN NOT NULL DEFAULT false, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY (id))');
|
$this->addSql('CREATE TABLE notification (id INT GENERATED BY DEFAULT AS IDENTITY NOT NULL, user_id INT NOT NULL, message VARCHAR(255) NOT NULL, is_read BOOLEAN NOT NULL DEFAULT false, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY (id))');
|
||||||
$this->addSql('CREATE INDEX IDX_BF5476CAA76ED395 ON notification (user_id)');
|
$this->addSql('CREATE INDEX IDX_BF5476CAA76ED395 ON notification (user_id)');
|
||||||
$this->addSql('COMMENT ON COLUMN notification.created_at IS \'(DC2Type:datetime_immutable)\'');
|
$this->addSql('COMMENT ON COLUMN notification.created_at IS \'(DC2Type:datetime_immutable)\'');
|
||||||
$this->addSql('ALTER TABLE notification ADD CONSTRAINT FK_BF5476CAA76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
$this->addSql('ALTER TABLE notification ADD CONSTRAINT FK_BF5476CAA76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class ImportController extends AbstractController
|
|||||||
|
|
||||||
$import = new Import();
|
$import = new Import();
|
||||||
$import->setUser($user);
|
$import->setUser($user);
|
||||||
|
$import->setFilePath('pending');
|
||||||
|
|
||||||
$em->persist($import);
|
$em->persist($import);
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|||||||
@@ -37,13 +37,13 @@ class NotificationController extends AbstractController
|
|||||||
|
|
||||||
#[Route('/api/notifications/read', methods: ['POST'])]
|
#[Route('/api/notifications/read', methods: ['POST'])]
|
||||||
#[IsGranted('ROLE_USER')]
|
#[IsGranted('ROLE_USER')]
|
||||||
public function markRead(NotificationRepository $notificationRepository): JsonResponse
|
public function markRead(NotificationRepository $notificationRepository): Response
|
||||||
{
|
{
|
||||||
/** @var User $user */
|
/** @var User $user */
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
|
|
||||||
$notificationRepository->markAllReadForUser($user);
|
$notificationRepository->markAllReadForUser($user);
|
||||||
|
|
||||||
return $this->json(null, Response::HTTP_NO_CONTENT);
|
return new Response('', Response::HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class Notification
|
|||||||
#[ORM\Column(length: 255)]
|
#[ORM\Column(length: 255)]
|
||||||
private ?string $message = null;
|
private ?string $message = null;
|
||||||
|
|
||||||
#[ORM\Column]
|
#[ORM\Column(name: 'is_read')]
|
||||||
private bool $read = false;
|
private bool $read = false;
|
||||||
|
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
|
|||||||
@@ -20,13 +20,8 @@ class ImportRepository extends ServiceEntityRepository
|
|||||||
|
|
||||||
public function incrementProcessedBatches(Import $import): int
|
public function incrementProcessedBatches(Import $import): int
|
||||||
{
|
{
|
||||||
$this->getEntityManager()->getConnection()->executeStatement(
|
|
||||||
'UPDATE import SET processed_batches = processed_batches + 1 WHERE id = :id',
|
|
||||||
['id' => $import->getId()]
|
|
||||||
);
|
|
||||||
|
|
||||||
return (int) $this->getEntityManager()->getConnection()->fetchOne(
|
return (int) $this->getEntityManager()->getConnection()->fetchOne(
|
||||||
'SELECT processed_batches FROM import WHERE id = :id',
|
'UPDATE import SET processed_batches = processed_batches + 1 WHERE id = :id RETURNING processed_batches',
|
||||||
['id' => $import->getId()]
|
['id' => $import->getId()]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{% if app.user %}
|
{% if app.user %}
|
||||||
|
<div data-controller="import-modal">
|
||||||
<nav class="navbar" data-controller="notifications">
|
<nav class="navbar" data-controller="notifications">
|
||||||
<div class="navbar-left">
|
<div class="navbar-left">
|
||||||
<a href="{{ path('app_homepage') }}" class="navbar-brand">Actorle</a>
|
<a href="{{ path('app_homepage') }}" class="navbar-brand">Actorle</a>
|
||||||
@@ -38,7 +39,7 @@
|
|||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
{# Import Modal #}
|
{# Import Modal #}
|
||||||
<div class="modal-overlay" data-controller="import-modal" data-import-modal-target="overlay" hidden>
|
<div class="modal-overlay" data-import-modal-target="overlay" hidden>
|
||||||
<div class="modal">
|
<div class="modal">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h2>Importer ses films</h2>
|
<h2>Importer ses films</h2>
|
||||||
@@ -56,4 +57,5 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user