Skip to content

Commit

Permalink
Merge pull request #7 from Wassim-Rached/detached
Browse files Browse the repository at this point in the history
just for testing
  • Loading branch information
Wassim-Rached authored May 10, 2024
2 parents ed23a03 + 908965d commit 65cfeea
Show file tree
Hide file tree
Showing 67 changed files with 2,872 additions and 6 deletions.
16 changes: 14 additions & 2 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,26 @@ security:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
providers:
users_in_memory: { memory: null }
# used to reload user from session & other features (e.g. switch_user)
app_user_provider:
entity:
class: App\Entity\ApplicationUser
property: username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
lazy: true
provider: users_in_memory
provider: app_user_provider
form_login:
login_path: app_login
check_path: app_login
enable_csrf: true
logout:
path: app_logout
# where to redirect after logout
# target: app_any_route

# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#the-firewall
Expand Down
Binary file added diagrams/activity_diagram_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/activity_diagram_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/cas_utilisation.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/class_diagram.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/classes_preliminaires .jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/contexte_statique.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/diagram_class_raffine.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/diagram_sequence_object_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/diagram_sequence_object_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/relationel.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added diagrams/sequence_system_order.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ services:
mysql:
container_name: mini-shop_mysql
image: mysql:latest
ports:
- "3306:3306"
volumes:
- mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: mini-shop
MYSQL_USER: wsaz
MYSQL_PASSWORD: wsaz
Expand All @@ -46,15 +48,20 @@ services:
- mysql
image: phpmyadmin:latest
restart: always
links:
- mysql
ports:
- "1002:80"
environment:
MYSQL_ROOT_PASSWORD: password
PMA_HOST: mysql
networks:
- main_network


networks:
main_network:
driver: bridge
driver: bridge

volumes:
mysql-data:
Expand Down
7 changes: 7 additions & 0 deletions info.dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
symfony project up on : localhost:1001
phpmyadmin up on: localhost:1002
mysql access:
user: root
password: root
database: mini_shop

# to shut down the containers
docker-compose down
Expand All @@ -13,3 +17,6 @@ git checkout -b branch_name
git add .
git commit -m "message"
git push origin branch_name

# for any command that effects symfony use this to open terminal in the container
docker exec -it mini-shop_fpm bash
71 changes: 71 additions & 0 deletions migrations/Version20240510205810.php
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)');
}
}
8 changes: 8 additions & 0 deletions src/Controller/AddressController.php
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{}
100 changes: 100 additions & 0 deletions src/Controller/CommandController.php
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);
}

}
15 changes: 14 additions & 1 deletion src/Controller/HealthCheckController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,18 @@ public function test_db(EntityManagerInterface $entityManager): JsonResponse
}
} catch (\Exception $e) {
return $this->json('E: Failed to connect to the database.', 500);
} }
}
}

// check the current user
#[Route('/health-check/user', name: 'app_health_check_user')]
public function test_user(): JsonResponse
{
$user = $this->getUser();
if ($user) {
return $this->json('User '.$user->getUserIdentifier().' is authenticated.');
} else {
return $this->json('User is not authenticated.', 401);
}
}
}
20 changes: 20 additions & 0 deletions src/Controller/MainController.php
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,
]);
}
}
83 changes: 83 additions & 0 deletions src/Controller/ProductController.php
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()

]);
}


}
Loading

0 comments on commit 65cfeea

Please sign in to comment.