add Basic Shopware API

add Tests
This commit is contained in:
Marko
2022-06-28 17:20:37 +02:00
parent b5085fc848
commit 460411ab43
13 changed files with 2328 additions and 247 deletions

View File

@@ -5,6 +5,8 @@ namespace App\Repository;
use App\Entity\Orders;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* @extends ServiceEntityRepository<Orders>
@@ -16,13 +18,21 @@ use Doctrine\Persistence\ManagerRegistry;
*/
class OrdersRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
private ValidatorInterface $validator;
public function __construct(ManagerRegistry $registry,ValidatorInterface $validator)
{
parent::__construct($registry, Orders::class);
$this->validator = $validator;
}
public function add(Orders $entity, bool $flush = false): void
{
$errors = $this->validator->validate($entity);
if (count($errors) > 0) {
var_dump($errors);
}
$this->getEntityManager()->persist($entity);
if ($flush) {
@@ -30,6 +40,18 @@ class OrdersRepository extends ServiceEntityRepository
}
}
public function update(Orders $entity, bool $flush = false): void
{
$order = $this->getEntityManager()->find(Orders::class, $entity->getId());
if(!$order) {
throw $this->createNotFoundException('Order not found: '.$entity->getId());
}
}
public function remove(Orders $entity, bool $flush = false): void
{
$this->getEntityManager()->remove($entity);