Don't use primary key for offers

This commit is contained in:
Jannis Portmann 2022-01-17 19:11:00 +01:00
parent 539b7edffe
commit d190971718
8 changed files with 65 additions and 15 deletions

View file

@ -83,6 +83,7 @@ class OfferController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$offer->setByUser($user);
$offer->setCreatedAt(new \DateTime());
$offer->setUrlId(uniqid());
$coordinate = $plzconverter->convertPlzToCoordinate($form['zipCode']->getData());
if ($coordinate != null) {
@ -108,7 +109,7 @@ class OfferController extends AbstractController
]);
}
#[Route('/offer/{id}', name: 'show_offer')]
#[Route('/offer/{urlId}', name: 'show_offer')]
public function showOffer(Offering $offer, WishRepository $wishRepository, PlzToCoordinate $plzconverter, DistanceCalculator $distanceCalculator): Response
{
$distance = null;
@ -142,7 +143,7 @@ class OfferController extends AbstractController
]);
}
#[Route('/offer/edit/{id}', name: 'edit_offer')]
#[Route('/offer/edit/{urlId}', name: 'edit_offer')]
public function editOffer(Offering $offer, OfferingRepository $offerRepository, Request $request, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response
{
$form = $this->createForm(OfferingFormType::class, $offer);
@ -175,7 +176,7 @@ class OfferController extends AbstractController
throw new HttpException(403, "No permission");
}
#[Route('/offer/delete/{id}', name: 'delete_offer')]
#[Route('/offer/delete/{urlId}', name: 'delete_offer')]
public function deleteOffer(Offering $offer, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response
{
$user = $this->getUser();

View file

@ -49,6 +49,6 @@ class TradeController extends AbstractController
$this->addFlash('error','You can\'t trade with yourself!');
}
return $this->redirectToRoute('show_offer', ['id' => $offer->getId()]);
return $this->redirectToRoute('show_offer', ['urlId' => $offer->getId()]);
}
}

View file

@ -62,6 +62,11 @@ class Offering
*/
private $lng;
/**
* @ORM\Column(type="string", length=13)
*/
private $urlId;
public function getId(): ?int
{
return $this->id;
@ -141,7 +146,7 @@ class Offering
public function __toString(): string
{
return (string) $this->getTitle();
return (string) $this-getTitle();
}
public function getCoordinate(): ?Coordinate
@ -158,4 +163,16 @@ class Offering
return $this;
}
public function getUrlId(): ?string
{
return $this->urlId;
}
public function setUrlId(string $urlId): self
{
$this->urlId = $urlId;
return $this;
}
}