-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Wassim-Rached/detached
just for testing
- Loading branch information
Showing
67 changed files
with
2,872 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?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 Version20240510205810 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('ALTER TABLE application_user DROP FOREIGN KEY FK_7A7FBEC11623CB0A'); | ||
$this->addSql('ALTER TABLE product DROP FOREIGN KEY FK_D34A04AD12469DE2'); | ||
$this->addSql('ALTER TABLE command DROP FOREIGN KEY FK_8ECAEAD44C3A3BB'); | ||
$this->addSql('DROP TABLE user_verification'); | ||
$this->addSql('DROP TABLE category'); | ||
$this->addSql('DROP TABLE payment_detail'); | ||
$this->addSql('ALTER TABLE address DROP country, CHANGE address_line2 address_line2 VARCHAR(255) DEFAULT NULL'); | ||
$this->addSql('DROP INDEX UNIQ_7A7FBEC11623CB0A ON application_user'); | ||
$this->addSql('ALTER TABLE application_user DROP verification_id, DROP first_name, DROP last_name, DROP is_banned'); | ||
$this->addSql('ALTER TABLE command DROP FOREIGN KEY FK_8ECAEAD4DC9C2434'); | ||
$this->addSql('DROP INDEX IDX_8ECAEAD4DC9C2434 ON command'); | ||
$this->addSql('DROP INDEX UNIQ_8ECAEAD44C3A3BB ON command'); | ||
$this->addSql('ALTER TABLE command DROP payment_id, CHANGE total total INT NOT NULL, CHANGE by_user_id for_user_id INT NOT NULL'); | ||
$this->addSql('ALTER TABLE command ADD CONSTRAINT FK_8ECAEAD49B5BB4B8 FOREIGN KEY (for_user_id) REFERENCES application_user (id)'); | ||
$this->addSql('CREATE INDEX IDX_8ECAEAD49B5BB4B8 ON command (for_user_id)'); | ||
$this->addSql('ALTER TABLE product DROP FOREIGN KEY FK_D34A04AD5B075477'); | ||
$this->addSql('DROP INDEX IDX_D34A04AD5B075477 ON product'); | ||
$this->addSql('DROP INDEX IDX_D34A04AD12469DE2 ON product'); | ||
$this->addSql('ALTER TABLE product ADD created_by_id INT NOT NULL, DROP category_id, DROP published_by_id, DROP photo, DROP is_banned, CHANGE price price INT NOT NULL, CHANGE description description LONGTEXT DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE product ADD CONSTRAINT FK_D34A04ADB03A8386 FOREIGN KEY (created_by_id) REFERENCES application_user (id)'); | ||
$this->addSql('CREATE INDEX IDX_D34A04ADB03A8386 ON product (created_by_id)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE TABLE user_verification (id INT AUTO_INCREMENT NOT NULL, cin VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, cin_photo VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, person_photo VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); | ||
$this->addSql('CREATE TABLE category (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, description LONGTEXT CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); | ||
$this->addSql('CREATE TABLE payment_detail (id INT AUTO_INCREMENT NOT NULL, provider VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, status VARCHAR(255) CHARACTER SET utf8mb4 NOT NULL COLLATE `utf8mb4_unicode_ci`, amount DOUBLE PRECISION NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = \'\' '); | ||
$this->addSql('ALTER TABLE address ADD country VARCHAR(255) NOT NULL, CHANGE address_line2 address_line2 VARCHAR(255) NOT NULL'); | ||
$this->addSql('ALTER TABLE application_user ADD verification_id INT DEFAULT NULL, ADD first_name VARCHAR(255) NOT NULL, ADD last_name VARCHAR(255) NOT NULL, ADD is_banned TINYINT(1) DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE application_user ADD CONSTRAINT FK_7A7FBEC11623CB0A FOREIGN KEY (verification_id) REFERENCES user_verification (id) ON UPDATE NO ACTION ON DELETE NO ACTION'); | ||
$this->addSql('CREATE UNIQUE INDEX UNIQ_7A7FBEC11623CB0A ON application_user (verification_id)'); | ||
$this->addSql('ALTER TABLE command DROP FOREIGN KEY FK_8ECAEAD49B5BB4B8'); | ||
$this->addSql('DROP INDEX IDX_8ECAEAD49B5BB4B8 ON command'); | ||
$this->addSql('ALTER TABLE command ADD payment_id INT DEFAULT NULL, CHANGE total total DOUBLE PRECISION NOT NULL, CHANGE for_user_id by_user_id INT NOT NULL'); | ||
$this->addSql('ALTER TABLE command ADD CONSTRAINT FK_8ECAEAD44C3A3BB FOREIGN KEY (payment_id) REFERENCES payment_detail (id) ON UPDATE NO ACTION ON DELETE NO ACTION'); | ||
$this->addSql('ALTER TABLE command ADD CONSTRAINT FK_8ECAEAD4DC9C2434 FOREIGN KEY (by_user_id) REFERENCES application_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION'); | ||
$this->addSql('CREATE INDEX IDX_8ECAEAD4DC9C2434 ON command (by_user_id)'); | ||
$this->addSql('CREATE UNIQUE INDEX UNIQ_8ECAEAD44C3A3BB ON command (payment_id)'); | ||
$this->addSql('ALTER TABLE product DROP FOREIGN KEY FK_D34A04ADB03A8386'); | ||
$this->addSql('DROP INDEX IDX_D34A04ADB03A8386 ON product'); | ||
$this->addSql('ALTER TABLE product ADD published_by_id INT NOT NULL, ADD photo VARCHAR(255) DEFAULT NULL, ADD is_banned TINYINT(1) DEFAULT NULL, CHANGE price price DOUBLE PRECISION NOT NULL, CHANGE description description LONGTEXT NOT NULL, CHANGE created_by_id category_id INT NOT NULL'); | ||
$this->addSql('ALTER TABLE product ADD CONSTRAINT FK_D34A04AD12469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON UPDATE NO ACTION ON DELETE NO ACTION'); | ||
$this->addSql('ALTER TABLE product ADD CONSTRAINT FK_D34A04AD5B075477 FOREIGN KEY (published_by_id) REFERENCES application_user (id) ON UPDATE NO ACTION ON DELETE NO ACTION'); | ||
$this->addSql('CREATE INDEX IDX_D34A04AD5B075477 ON product (published_by_id)'); | ||
$this->addSql('CREATE INDEX IDX_D34A04AD12469DE2 ON product (category_id)'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
|
||
// most likely it will be deleted later | ||
class AddressController extends AbstractController{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Entity\Command; | ||
use App\Entity\Product; | ||
use App\Form\CommandType; | ||
use App\Repository\CommandRepository; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
#[Route('/command')] | ||
class CommandController extends AbstractController | ||
{ | ||
|
||
#[Route('/product/{id}/new', name: 'app_command_new', methods: ['GET', 'POST'])] | ||
public function new( | ||
Request $request, | ||
EntityManagerInterface $entityManager, | ||
Product $product | ||
): Response | ||
{ | ||
$command = new Command(); | ||
$form = $this->createForm(CommandType::class, $command); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$command->setProduct($product); | ||
$command->setForUser($this->getUser()); | ||
$command->setCreatedAt(new \DateTimeImmutable()); | ||
$command->setStatus('pending'); | ||
$command->setTotal($product->getPrice() * $command->getQuantity()); | ||
$entityManager->persist($command); | ||
$entityManager->flush(); | ||
|
||
return $this->redirectToRoute('app_command_show', ['id' => $command->getId()], Response::HTTP_SEE_OTHER); | ||
} | ||
|
||
return $this->render('command/new.html.twig', [ | ||
'command' => $command, | ||
'form' => $form, | ||
]); | ||
} | ||
|
||
|
||
#[Route('/my-cart', name: 'app_my_cart', methods: ['GET'])] | ||
public function my_cart(CommandRepository $commandRepository): Response | ||
{ | ||
return $this->render('command/my_cart.html.twig', [ | ||
'commands' => $commandRepository->findBy(['for_user' => $this->getUser()]) | ||
]); | ||
} | ||
|
||
// accept command | ||
#[Route('/{id}/accept', name: 'app_command_accept', methods: ['GET'])] | ||
public function accept(Command $command, EntityManagerInterface $entityManager): Response | ||
{ | ||
if ($command->getProduct()->getCreatedBy() !== $this->getUser()) { | ||
throw $this->createAccessDeniedException(); | ||
} | ||
$command->setStatus('accepted'); | ||
$entityManager->flush(); | ||
return $this->redirectToRoute('app_product_commands', ['id' => $command->getProduct()->getId()], Response::HTTP_SEE_OTHER); | ||
} | ||
|
||
#[Route('/product/{id}', name: 'app_product_commands', methods: ['GET'])] | ||
public function product_commands(Product $product, CommandRepository $commandRepository): Response | ||
{ | ||
if ($product->getCreatedBy() !== $this->getUser()) { | ||
throw $this->createAccessDeniedException(); | ||
} | ||
return $this->render('command/product_commands.html.twig', [ | ||
'commands' => $commandRepository->findBy(['product' => $product]), | ||
'product' => $product | ||
]); | ||
} | ||
|
||
#[Route('/{id}', name: 'app_command_show', methods: ['GET'])] | ||
public function show(Command $command): Response | ||
{ | ||
return $this->render('command/show.html.twig', [ | ||
'command' => $command, | ||
]); | ||
} | ||
|
||
#[Route('/{id}', name: 'app_command_delete', methods: ['POST'])] | ||
public function delete(Request $request, Command $command, EntityManagerInterface $entityManager): Response | ||
{ | ||
if ($this->isCsrfTokenValid('delete' . $command->getId(), $request->getPayload()->get('_token'))) { | ||
$entityManager->remove($command); | ||
$entityManager->flush(); | ||
} | ||
|
||
return $this->redirectToRoute('app_main', [], Response::HTTP_SEE_OTHER); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Repository\ProductRepository; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
class MainController extends AbstractController | ||
{ | ||
#[Route('/', name: 'app_main')] | ||
public function index(ProductRepository $productRepository): Response | ||
{ | ||
$products = $productRepository->findAll(); | ||
return $this->render('main/index.html.twig', [ | ||
'products' => $products, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Entity\Command; | ||
use App\Entity\Product; | ||
use App\Form\Product1Type; | ||
use App\Repository\ProductRepository; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
|
||
class ProductController extends AbstractController | ||
{ | ||
|
||
#[Route('/product', name: 'app_product_index', methods: ['GET'])] | ||
public function index(ProductRepository $productRepository): Response | ||
{ | ||
return $this->render('product/index.html.twig', [ | ||
'products' => $productRepository->findBy(['status' => 'accepted']) | ||
]); | ||
} | ||
|
||
#[Route('/product/new', name: 'app_product_new', methods: ['GET', 'POST'])] | ||
public function new(Request $request, EntityManagerInterface $entityManager): Response | ||
{ | ||
$product = new Product(); | ||
$form = $this->createForm(Product1Type::class, $product); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$product->setCreatedBy($this->getUser()); | ||
$product->setStatus('pending'); | ||
$entityManager->persist($product); | ||
$entityManager->flush(); | ||
|
||
return $this->redirectToRoute('app_product_index', [], Response::HTTP_SEE_OTHER); | ||
} | ||
|
||
return $this->render('product/new.html.twig', [ | ||
'product' => $product, | ||
'form' => $form, | ||
]); | ||
} | ||
|
||
#[Route('/product/{id}', name: 'app_product_show', methods: ['GET'])] | ||
public function show(Product $product): Response | ||
{ | ||
return $this->render('product/show.html.twig', [ | ||
'product' => $product | ||
]); | ||
} | ||
|
||
|
||
#[Route('/product/{id}', name: 'app_product_delete', methods: ['POST'])] | ||
public function delete(Request $request, Product $product, EntityManagerInterface $entityManager): Response | ||
{ | ||
if ($this->isCsrfTokenValid('delete'.$product->getId(), $request->getPayload()->get('_token'))) { | ||
if ($this->getUser() !== $product->getCreatedBy()) { | ||
return $this->redirectToRoute('app_product_index', [], Response::HTTP_SEE_OTHER); | ||
} | ||
$entityManager->remove($product); | ||
$entityManager->flush(); | ||
} | ||
|
||
return $this->redirectToRoute('app_product_index', [], Response::HTTP_SEE_OTHER); | ||
} | ||
|
||
// my products route | ||
#[Route('/my-products', name: 'app_my_products', methods: ['GET'])] | ||
public function myProducts(ProductRepository $productRepository): Response | ||
{ | ||
return $this->render('product/my_products.html.twig', [ | ||
'products' => $productRepository->findBy(['created_by' => $this->getUser()]), | ||
'user'=> $this->getUser() | ||
|
||
]); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.