Fix prepopulated uuids

This commit is contained in:
Ryan Prather 2024-05-16 18:53:53 -04:00
parent 9e7e84a4fc
commit 3e278c27fa
2 changed files with 19 additions and 14 deletions

View File

@ -98,8 +98,8 @@ class AjaxController extends AbstractController
$user = $this->getUser();
$speaker = new Speaker();
$speaker->setName($data->speakerName);
$speaker->setUser($user);
$speaker->setName($data->speakerName)
->setUser($user);
$emi->persist($speaker);
$emi->flush();
@ -139,8 +139,8 @@ class AjaxController extends AbstractController
$user = $this->getUser();
$series = new Series();
$series->setName($data->seriesName);
$series->setUser($user);
$series->setName($data->seriesName)
->setUser($user);
$emi->persist($series);
$emi->flush();
@ -267,22 +267,28 @@ class AjaxController extends AbstractController
public function saveNote(Request $req, EntityManagerInterface $emi): Response
{
$data = json_decode($req->getContent());
$note = $emi->getRepository(Note::class)->find($data->id);
$newNote = false;
if (isset($data->id) && $data->id) {
/** @var Note|array $note */
$note = $emi->getRepository(Note::class)->findBy(['id' => $data->id, 'user' => $this->getUser()]);
if (!$note) {
if (is_array($note) && count($note) > 0) {
/** @var Note $note */
$note = $note[0];
}
} else {
$note = new Note();
$uuid = Uuid::fromString($data->id);
$note->setId($uuid);
$newNote = true;
$note->setUser($this->getUser());
}
$refs = json_decode(json_encode($data->refs), true);
$series = $emi->getRepository(Series::class)->find($data->series);
$speaker = $emi->getRepository(Speaker::class)->find($data->speaker);
$user = $this->getUser();
$note->setUser($user)
->setTitle($data->title)
/** @var Note $note */
$note->setTitle($data->title)
->setDate(new DateTime($data->date))
->setSeries($series)
->setSpeaker($speaker)
@ -296,7 +302,8 @@ class AjaxController extends AbstractController
$res = new Response();
$res->setContent(json_encode([
'msg' => 'saved',
'id' => $note->getId()
'id' => $note->getId(),
'new' => $newNote,
]));
return $res;

View File

@ -26,11 +26,9 @@ class DefaultController extends AbstractController
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$last4Notes = $emi->getRepository(Note::class)->getLast4Notes($user);
$uuid = Uuid::v4();
return $this->render('default/home.html.twig', [
'last4Notes' => $last4Notes,
'id' => $uuid,
'isAdmin' => $this->isGranted('ROLE_ADMIN'),
]);
}