Rename offering to offer

This commit is contained in:
Jannis Portmann 2022-01-19 19:59:35 +01:00
parent a7b4bf09e4
commit f54f663fb0
12 changed files with 90 additions and 59 deletions

View file

@ -35,7 +35,7 @@ widget.start()
// Dsiplay Filename when uploading // Dsiplay Filename when uploading
document.querySelector('.custom-file-input').addEventListener('change', function (e) { document.querySelector('.custom-file-input').addEventListener('change', function (e) {
var fileName = document.getElementById('offering_form_photo').files[0].name; var fileName = document.getElementById('offer_form_photo').files[0].name;
var nextSibling = e.target.nextElementSibling var nextSibling = e.target.nextElementSibling
nextSibling.innerText = fileName nextSibling.innerText = fileName
}) })

View file

@ -0,0 +1,31 @@
<?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 Version20220119172053 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('RENAME TABLE offering TO offer');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('RENAME TABLE offer TO offering');
}
}

View file

@ -3,7 +3,7 @@
namespace App\Controller\Admin; namespace App\Controller\Admin;
use App\Entity\User; use App\Entity\User;
use App\Entity\Offering; use App\Entity\Offer;
use App\Entity\Wish; use App\Entity\Wish;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard; use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem; use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
@ -36,7 +36,7 @@ class DashboardController extends AbstractDashboardController
yield MenuItem::linktoRoute('Back to the website', 'fas fa-arrow-left', 'offers'); yield MenuItem::linktoRoute('Back to the website', 'fas fa-arrow-left', 'offers');
yield MenuItem::linktoDashboard('Dashboard', 'fa fa-home'); yield MenuItem::linktoDashboard('Dashboard', 'fa fa-home');
yield MenuItem::linkToCrud('User', 'fas fa-user', User::class); yield MenuItem::linkToCrud('User', 'fas fa-user', User::class);
yield MenuItem::linkToCrud('Offering', 'fas fa-seedling', Offering::class); yield MenuItem::linkToCrud('Offer', 'fas fa-seedling', Offer::class);
yield MenuItem::linkToCrud('Wish', 'fas fa-star', Wish::class); yield MenuItem::linkToCrud('Wish', 'fas fa-star', Wish::class);
} }
} }

View file

@ -2,7 +2,7 @@
namespace App\Controller\Admin; namespace App\Controller\Admin;
use App\Entity\Offering; use App\Entity\Offer;
use App\Entity\User; use App\Entity\User;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
@ -13,11 +13,11 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField; use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField; use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
class OfferingCrudController extends AbstractCrudController class OfferCrudController extends AbstractCrudController
{ {
public static function getEntityFqcn(): string public static function getEntityFqcn(): string
{ {
return Offering::class; return Offer::class;
} }
public function configureFields(string $pageName): iterable public function configureFields(string $pageName): iterable

View file

@ -2,11 +2,11 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\Offering; use App\Entity\Offer;
use App\Form\OfferingFormType; use App\Form\OfferFormType;
use App\Form\OfferFilterFormType; use App\Form\OfferFilterFormType;
use App\Repository\OfferingRepository; use App\Repository\OfferRepository;
use App\Repository\WishRepository; use App\Repository\WishRepository;
use App\Service\PlzToCoordinate; use App\Service\PlzToCoordinate;
@ -33,7 +33,7 @@ class OfferController extends AbstractController
} }
#[Route('/offers', name: 'offers', options: ["sitemap" => true])] #[Route('/offers', name: 'offers', options: ["sitemap" => true])]
public function showAll(Environment $twig, Request $request, OfferingRepository $offerRepository, PlzToCoordinate $plzconverter, DistanceCalculator $distanceCalculator): Response public function showAll(Environment $twig, Request $request, OfferRepository $offerRepository, PlzToCoordinate $plzconverter, DistanceCalculator $distanceCalculator): Response
{ {
$form = $this->createForm(OfferFilterFormType::class); $form = $this->createForm(OfferFilterFormType::class);
$form->handleRequest($request); $form->handleRequest($request);
@ -74,8 +74,8 @@ class OfferController extends AbstractController
#[Route('/new', name: 'new_offer')] #[Route('/new', name: 'new_offer')]
public function newOffer(Request $request, PlzToCoordinate $plzconverter, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response public function newOffer(Request $request, PlzToCoordinate $plzconverter, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response
{ {
$offer = new Offering(); $offer = new Offer();
$form = $this->createForm(OfferingFormType::class, $offer); $form = $this->createForm(OfferFormType::class, $offer);
$user = $this->getUser(); $user = $this->getUser();
$form->handleRequest($request); $form->handleRequest($request);
@ -110,7 +110,7 @@ class OfferController extends AbstractController
} }
#[Route('/offer/{urlId}', name: 'show_offer')] #[Route('/offer/{urlId}', name: 'show_offer')]
public function showOffer(Offering $offer, WishRepository $wishRepository, PlzToCoordinate $plzconverter, DistanceCalculator $distanceCalculator): Response public function showOffer(Offer $offer, WishRepository $wishRepository, PlzToCoordinate $plzconverter, DistanceCalculator $distanceCalculator): Response
{ {
$distance = null; $distance = null;
$user = $this->getUser(); $user = $this->getUser();
@ -144,9 +144,9 @@ class OfferController extends AbstractController
} }
#[Route('/offer/edit/{urlId}', 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(Offer $offer, OfferRepository $offerRepository, Request $request, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response
{ {
$form = $this->createForm(OfferingFormType::class, $offer); $form = $this->createForm(OfferFormType::class, $offer);
$user = $this->getUser(); $user = $this->getUser();
if ($offer->getByUser() === $user) if ($offer->getByUser() === $user)
{ {
@ -177,7 +177,7 @@ class OfferController extends AbstractController
} }
#[Route('/offer/delete/{urlId}', name: 'delete_offer')] #[Route('/offer/delete/{urlId}', name: 'delete_offer')]
public function deleteOffer(Offering $offer, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response public function deleteOffer(Offer $offer, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response
{ {
$user = $this->getUser(); $user = $this->getUser();
@ -200,13 +200,13 @@ class OfferController extends AbstractController
} }
#[Route('/myoffers', name: 'own_offers')] #[Route('/myoffers', name: 'own_offers')]
public function ownOffers(OfferingRepository $offeringRepository): Response public function ownOffers(OfferRepository $offerRepository): Response
{ {
$user = $this->getUser(); $user = $this->getUser();
return $this->render('user/offers.html.twig', [ return $this->render('user/offers.html.twig', [
'user' => $user, 'user' => $user,
'offers' => $offeringRepository->findByUser($user), 'offers' => $offerRepository->findByUser($user),
]); ]);
} }
} }

View file

@ -3,9 +3,9 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\User; use App\Entity\User;
use App\Entity\Offering; use App\Entity\Offer;
use App\Repository\OfferingRepository; use App\Repository\OfferRepository;
use App\Repository\WishRepository; use App\Repository\WishRepository;
use Symfony\Bridge\Twig\Mime\TemplatedEmail; use Symfony\Bridge\Twig\Mime\TemplatedEmail;
@ -20,7 +20,7 @@ use Symfony\Component\Routing\Annotation\Route;
class TradeController extends AbstractController class TradeController extends AbstractController
{ {
#[Route('/trade/{urlId}', name: 'trade')] #[Route('/trade/{urlId}', name: 'trade')]
public function sendEmail(MailerInterface $mailer, Offering $offer, OfferingRepository $offeringRepository, WishRepository $wishRepository): Response public function sendEmail(MailerInterface $mailer, Offer $offer, OfferRepository $offerRepository, WishRepository $wishRepository): Response
{ {
$user = $this->getUser(); $user = $this->getUser();

View file

@ -7,7 +7,7 @@ use App\Entity\User;
use App\Form\WishFormType; use App\Form\WishFormType;
use App\Form\ChangePasswordFormType; use App\Form\ChangePasswordFormType;
use App\Repository\OfferingRepository; use App\Repository\OfferRepository;
use App\Repository\WishRepository; use App\Repository\WishRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -30,7 +30,7 @@ class UserController extends AbstractController
} }
#[Route('/user', name: 'user_page')] #[Route('/user', name: 'user_page')]
public function user(OfferingRepository $offeringRepository, Request $request, UserPasswordHasherInterface $passwordEncoder): Response public function user(OfferRepository $offerRepository, Request $request, UserPasswordHasherInterface $passwordEncoder): Response
{ {
$user = $this->getUser(); $user = $this->getUser();
@ -64,23 +64,23 @@ class UserController extends AbstractController
} }
#[Route('/user/offers', name: 'user_offers')] #[Route('/user/offers', name: 'user_offers')]
public function userOffers(OfferingRepository $offeringRepository): Response public function userOffers(OfferRepository $offerRepository): Response
{ {
$user = $this->getUser(); $user = $this->getUser();
return $this->render('user/public.html.twig', [ return $this->render('user/public.html.twig', [
'user' => $user, 'user' => $user,
'offers' => $offeringRepository->findByUser($user), 'offers' => $offerRepository->findByUser($user),
]); ]);
} }
#[Route('/user/{urlId}', name: 'user_public')] #[Route('/user/{urlId}', name: 'user_public')]
public function show_user(User $user, OfferingRepository $offeringRepository, WishRepository $wishRepository): Response public function show_user(User $user, OfferRepository $offerRepository, WishRepository $wishRepository): Response
{ {
return $this->render('user/public.html.twig', [ return $this->render('user/public.html.twig', [
'username' => $user->getUsername(), 'username' => $user->getUsername(),
'wishes' => $wishRepository->findByUser($user), 'wishes' => $wishRepository->findByUser($user),
'offers' => $offeringRepository->findByUser($user), 'offers' => $offerRepository->findByUser($user),
]); ]);
} }

View file

@ -2,15 +2,15 @@
namespace App\Entity; namespace App\Entity;
use App\Repository\OfferingRepository; use App\Repository\OfferRepository;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
use Location\Coordinate; use Location\Coordinate;
use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Constraints as Assert;
/** /**
* @ORM\Entity(repositoryClass=OfferingRepository::class) * @ORM\Entity(repositoryClass=OfferRepository::class)
*/ */
class Offering class Offer
{ {
/** /**
* @ORM\Id * @ORM\Id
@ -20,7 +20,7 @@ class Offering
private $id; private $id;
/** /**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="offerings") * @ORM\ManyToOne(targetEntity=User::class, inversedBy="offers")
* @ORM\JoinColumn(nullable=false) * @ORM\JoinColumn(nullable=false)
*/ */
private $byUser; private $byUser;

View file

@ -51,9 +51,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
private $username; private $username;
/** /**
* @ORM\OneToMany(targetEntity=Offering::class, mappedBy="byUser", orphanRemoval=true) * @ORM\OneToMany(targetEntity=Offer::class, mappedBy="byUser", orphanRemoval=true)
*/ */
private $offerings; private $offers;
/** /**
* @ORM\OneToMany(targetEntity=Wish::class, mappedBy="byUser") * @ORM\OneToMany(targetEntity=Wish::class, mappedBy="byUser")
@ -72,7 +72,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
public function __construct() public function __construct()
{ {
$this->offerings = new ArrayCollection(); $this->offers = new ArrayCollection();
$this->wishes = new ArrayCollection(); $this->wishes = new ArrayCollection();
} }
@ -185,29 +185,29 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
} }
/** /**
* @return Collection|Offering[] * @return Collection|Offer[]
*/ */
public function getOfferings(): Collection public function getOffers(): Collection
{ {
return $this->offerings; return $this->offers;
} }
public function addOffering(Offering $offering): self public function addOffer(Offer $offer): self
{ {
if (!$this->offerings->contains($offering)) { if (!$this->offers->contains($offer)) {
$this->offerings[] = $offering; $this->offers[] = $offer;
$offering->setByUser($this); $offer->setByUser($this);
} }
return $this; return $this;
} }
public function removeOffering(Offering $offering): self public function removeOffer(Offer $offer): self
{ {
if ($this->offerings->removeElement($offering)) { if ($this->offers->removeElement($offer)) {
// set the owning side to null (unless already changed) // set the owning side to null (unless already changed)
if ($offering->getByUser() === $this) { if ($offer->getByUser() === $this) {
$offering->setByUser(null); $offer->setByUser(null);
} }
} }

View file

@ -2,7 +2,7 @@
namespace App\Form; namespace App\Form;
use App\Entity\Offering; use App\Entity\Offer;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
@ -12,7 +12,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Image; use Symfony\Component\Validator\Constraints\Image;
use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotBlank;
class OfferingFormType extends AbstractType class OfferFormType extends AbstractType
{ {
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
@ -43,7 +43,7 @@ class OfferingFormType extends AbstractType
public function configureOptions(OptionsResolver $resolver) public function configureOptions(OptionsResolver $resolver)
{ {
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => Offering::class, 'data_class' => Offer::class,
]); ]);
} }
} }

View file

@ -2,25 +2,25 @@
namespace App\Repository; namespace App\Repository;
use App\Entity\Offering; use App\Entity\Offer;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
/** /**
* @method Offering|null find($id, $lockMode = null, $lockVersion = null) * @method Offer|null find($id, $lockMode = null, $lockVersion = null)
* @method Offering|null findOneBy(array $criteria, array $orderBy = null) * @method Offer|null findOneBy(array $criteria, array $orderBy = null)
* @method Offering[] findAll() * @method Offer[] findAll()
* @method Offering[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) * @method Offer[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/ */
class OfferingRepository extends ServiceEntityRepository class OfferRepository extends ServiceEntityRepository
{ {
public function __construct(ManagerRegistry $registry) public function __construct(ManagerRegistry $registry)
{ {
parent::__construct($registry, Offering::class); parent::__construct($registry, Offer::class);
} }
// /** // /**
// * @return Offering[] Returns an array of Offering objects // * @return Offer[] Returns an array of Offer objects
// */ // */
public function findByUser($user) public function findByUser($user)
{ {
@ -45,7 +45,7 @@ class OfferingRepository extends ServiceEntityRepository
} }
/* /*
public function findOneBySomeField($value): ?Offering public function findOneBySomeField($value): ?Offer
{ {
return $this->createQueryBuilder('o') return $this->createQueryBuilder('o')
->andWhere('o.exampleField = :val') ->andWhere('o.exampleField = :val')

View file

@ -2,7 +2,7 @@
namespace App\Service; namespace App\Service;
use App\Entity\Offering; use App\Entity\Offer;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface; use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
@ -18,7 +18,7 @@ class OfferPhotoHelper
$this->filesystem = new Filesystem(); $this->filesystem = new Filesystem();
} }
public function uploadOfferPhoto(string $photoDir, UploadedFile $photo, Offering $offer) public function uploadOfferPhoto(string $photoDir, UploadedFile $photo, Offer $offer)
{ {
$filename = uniqid().'.'.$photo->guessExtension(); $filename = uniqid().'.'.$photo->guessExtension();
try { try {