Show wishes on offer page

This commit is contained in:
Jannis Portmann 2021-05-04 12:33:58 +02:00
parent 4e7b8ec340
commit eaebcaad57
4 changed files with 59 additions and 1 deletions

View file

@ -6,6 +6,8 @@ use App\Entity\Offering;
use App\Form\OfferingFormType; use App\Form\OfferingFormType;
use App\Repository\OfferingRepository; use App\Repository\OfferingRepository;
use App\Repository\WishRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -70,10 +72,11 @@ class OfferController extends AbstractController
} }
#[Route('/offer/{id}', name: 'show_offer')] #[Route('/offer/{id}', name: 'show_offer')]
public function show_offer(Offering $offering): Response public function show_offer(Offering $offering, WishRepository $wishRepository): Response
{ {
return $this->render('app/offer.html.twig', [ return $this->render('app/offer.html.twig', [
'offer' => $offering, 'offer' => $offering,
'wishes' => $wishRepository->findByUser($offering->getByUser()),
]); ]);
} }
} }

View file

@ -3,6 +3,7 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\Wish; use App\Entity\Wish;
use App\Entity\User;
use App\Form\WishFormType; use App\Form\WishFormType;
use App\Repository\WishRepository; use App\Repository\WishRepository;
@ -56,4 +57,14 @@ class UserController extends AbstractController
'wish_form' => $form->createView(), 'wish_form' => $form->createView(),
]); ]);
} }
#[Route('/user/{id}', name: 'public_wishlist')]
public function show_user(User $user, WishRepository $wishRepository): Response
{
return $this->render('user/public_wishlist.html.twig', [
'username' => $user->getUsername(),
'wishes' => $wishRepository->findByUser($user),
]);
}
} }

View file

@ -16,6 +16,21 @@
From From
</h3> </h3>
<p>{{ offer.byUser }} in {{ offer.zipCode }}</p> <p>{{ offer.byUser }} in {{ offer.zipCode }}</p>
<h3>Wishes</h3>
<p>{{ offer.byUser }} would like some of the following in return:</p>
<div class="mb-3">
{% if wishes == [] %}
<div class="alert alert-warning" role="alert">
There are currently no wishes!
</div>
{% else %}
<ul class="list-group">
{% for wish in wishes %}
<li class="list-group-item"> {{ wish.title }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}

View file

@ -0,0 +1,29 @@
{% extends 'base.html.twig' %}
{% block title %}Whishlist{% endblock %}
{% block body %}
{% for message in app.flashes('success') %}
<div class="alert alert-success" role="alert">
{{ message }}
</div>
{% endfor %}
<div class="mb-3">
<h1>{{ username }}'s' Wishlist</h1>
</div>
<div class="mb-3">
{% if wishes == [] %}
<div class="alert alert-warning" role="alert">
There are currently no wishes!
</div>
{% else %}
<ul class="list-group">
{% for wish in wishes %}
<li class="list-group-item"> {{ wish.title }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
{% endblock %}