feat: automatic saving of drafts when editing bookings

This commit is contained in:
Björn Fromme
2026-03-16 12:01:09 +01:00
parent 721016a00e
commit 0b5c7af4be
7 changed files with 759 additions and 52 deletions
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace App\Repository;
use App\Entity\BookingEditDraft;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<BookingEditDraft>
*/
class BookingEditDraftRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, BookingEditDraft::class);
}
/**
* Finds a draft for a specific user and booking combination.
*
* @param User $user The user who owns the draft
* @param int $bookingId The BusProNet booking ID
*
* @return BookingEditDraft|null The draft if found, null otherwise
*/
public function findByUserAndBooking(User $user, int $bookingId): ?BookingEditDraft
{
return $this->findOneBy([
'user' => $user,
'bookingId' => $bookingId,
]);
}
/**
* Deletes a draft for a specific user and booking combination.
*
* @param User $user The user who owns the draft
* @param int $bookingId The BusProNet booking ID
*/
public function deleteByUserAndBooking(User $user, int $bookingId): void
{
$this->createQueryBuilder('d')
->delete()
->where('d.user = :user')
->andWhere('d.bookingId = :bookingId')
->setParameter('user', $user)
->setParameter('bookingId', $bookingId)
->getQuery()
->execute();
}
}