Don't use primary key for offers
This commit is contained in:
parent
539b7edffe
commit
d190971718
8 changed files with 65 additions and 15 deletions
32
migrations/Version20220117175334.php
Normal file
32
migrations/Version20220117175334.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20220117175334 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Add an offer ID to be displayed in the URL';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE offering ADD url_id VARCHAR(13) NOT NULL');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql('ALTER TABLE offering DROP url_id');
|
||||||
|
}
|
||||||
|
}
|
|
@ -83,6 +83,7 @@ class OfferController extends AbstractController
|
||||||
if ($form->isSubmitted() && $form->isValid()) {
|
if ($form->isSubmitted() && $form->isValid()) {
|
||||||
$offer->setByUser($user);
|
$offer->setByUser($user);
|
||||||
$offer->setCreatedAt(new \DateTime());
|
$offer->setCreatedAt(new \DateTime());
|
||||||
|
$offer->setUrlId(uniqid());
|
||||||
|
|
||||||
$coordinate = $plzconverter->convertPlzToCoordinate($form['zipCode']->getData());
|
$coordinate = $plzconverter->convertPlzToCoordinate($form['zipCode']->getData());
|
||||||
if ($coordinate != null) {
|
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
|
public function showOffer(Offering $offer, WishRepository $wishRepository, PlzToCoordinate $plzconverter, DistanceCalculator $distanceCalculator): Response
|
||||||
{
|
{
|
||||||
$distance = null;
|
$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
|
public function editOffer(Offering $offer, OfferingRepository $offerRepository, Request $request, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response
|
||||||
{
|
{
|
||||||
$form = $this->createForm(OfferingFormType::class, $offer);
|
$form = $this->createForm(OfferingFormType::class, $offer);
|
||||||
|
@ -175,7 +176,7 @@ class OfferController extends AbstractController
|
||||||
throw new HttpException(403, "No permission");
|
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
|
public function deleteOffer(Offering $offer, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response
|
||||||
{
|
{
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
|
|
|
@ -49,6 +49,6 @@ class TradeController extends AbstractController
|
||||||
$this->addFlash('error','You can\'t trade with yourself!');
|
$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()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,11 @@ class Offering
|
||||||
*/
|
*/
|
||||||
private $lng;
|
private $lng;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\Column(type="string", length=13)
|
||||||
|
*/
|
||||||
|
private $urlId;
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
|
@ -141,7 +146,7 @@ class Offering
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return (string) $this->getTitle();
|
return (string) $this-getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCoordinate(): ?Coordinate
|
public function getCoordinate(): ?Coordinate
|
||||||
|
@ -158,4 +163,16 @@ class Offering
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUrlId(): ?string
|
||||||
|
{
|
||||||
|
return $this->urlId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUrlId(string $urlId): self
|
||||||
|
{
|
||||||
|
$this->urlId = $urlId;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -47,7 +47,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if offer.byUser == user %}
|
{% if offer.byUser == user %}
|
||||||
<a href="{{ path('edit_offer', {'id': offer.id}) }}" class="btn btn-info mb-3"><i class="fas fa-pen"></i></a>
|
<a href="{{ path('edit_offer', {'urlId': offer.urlId}) }}" class="btn btn-info mb-3"><i class="fas fa-pen"></i></a>
|
||||||
<button type="button" class="btn btn-danger mb-3" data-toggle="modal" data-target="#exampleModal"><i class="fas fa-trash-alt"></i></button>
|
<button type="button" class="btn btn-danger mb-3" data-toggle="modal" data-target="#exampleModal"><i class="fas fa-trash-alt"></i></button>
|
||||||
<!-- Modal -->
|
<!-- Modal -->
|
||||||
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||||
<a type="button" class="btn btn-danger" href="{{ path('delete_offer', {'id': offer.id}) }}">Delete</a>
|
<a type="button" class="btn btn-danger" href="{{ path('delete_offer', {'urlId': offer.urlId}) }}">Delete</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -85,6 +85,6 @@
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<a class="btn btn-primary mb-3" href="{{ path('trade', {'id': offer.id}) }}">Offer trade</a>
|
<a class="btn btn-primary mb-3" href="{{ path('trade', {'urlId': offer.urlId}) }}">Offer trade</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
{% for offer in offers %}
|
{% for offer in offers %}
|
||||||
<div class="mb-5">
|
<div class="mb-5">
|
||||||
<div class="card offer h-100">
|
<div class="card offer h-100">
|
||||||
<a href="{{ path('show_offer', {'id': offer.id }) }}">
|
<a href="{{ path('show_offer', {'urlId': offer.urlId }) }}">
|
||||||
{% if offer.photoFilename %}
|
{% if offer.photoFilename %}
|
||||||
<img class="card-img-top offer-img" src="{{ asset('uploads/photos/' ~ offer.photofilename) }}" />
|
<img class="card-img-top offer-img" src="{{ asset('uploads/photos/' ~ offer.photofilename) }}" />
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
{% for offer in offers %}
|
{% for offer in offers %}
|
||||||
<div class="mb-5">
|
<div class="mb-5">
|
||||||
<div class="card offer h-100">
|
<div class="card offer h-100">
|
||||||
<a href="{{ path('show_offer', {'id': offer.id }) }}">
|
<a href="{{ path('show_offer', {'urlId': offer.urlId }) }}">
|
||||||
{% if offer.photoFilename %}
|
{% if offer.photoFilename %}
|
||||||
<img class="card-img-top offer-img" src="{{ asset('uploads/photos/' ~ offer.photofilename) }}" />
|
<img class="card-img-top offer-img" src="{{ asset('uploads/photos/' ~ offer.photofilename) }}" />
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -26,12 +26,12 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
<div class="card-footer offer-footer">
|
<div class="card-footer offer-footer">
|
||||||
<a href="{{ path('edit_offer', {'id': offer.id}) }}" class="btn btn-info"><i class="fas fa-pen"></i></a>
|
<a href="{{ path('edit_offer', {'urlId': offer.urlId}) }}" class="btn btn-info"><i class="fas fa-pen"></i></a>
|
||||||
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#offer-modal-{{ offer.id }}"><i class="fas fa-trash-alt"></i></button>
|
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#offer-modal-{{ offer.urlId }}"><i class="fas fa-trash-alt"></i></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- Modal -->
|
<!-- Modal -->
|
||||||
<div class="modal fade" id="offer-modal-{{ offer.id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
<div class="modal fade" id="offer-modal-{{ offer.urlId }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||||
<a type="button" class="btn btn-danger" href="{{ path('delete_offer', {'id': offer.id}) }}">Delete</a>
|
<a type="button" class="btn btn-danger" href="{{ path('delete_offer', {'urlId': offer.urlId}) }}">Delete</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
{% for offer in offers %}
|
{% for offer in offers %}
|
||||||
<div class="mb-5">
|
<div class="mb-5">
|
||||||
<div class="card offer h-100">
|
<div class="card offer h-100">
|
||||||
<a href="{{ path('show_offer', {'id': offer.id }) }}">
|
<a href="{{ path('show_offer', {'urlId': offer.urlId }) }}">
|
||||||
{% if offer.photoFilename %}
|
{% if offer.photoFilename %}
|
||||||
<img class="card-img-top offer-img" src="{{ asset('uploads/photos/' ~ offer.photofilename) }}" />
|
<img class="card-img-top offer-img" src="{{ asset('uploads/photos/' ~ offer.photofilename) }}" />
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
Reference in a new issue