diff --git a/server/web_app/src/Controller/ItemController.php b/server/web_app/src/Controller/ItemController.php index f045664604e8d356391ffd805de1904cea5e58f9..15d28288db2f3efbc61e21f59162558d73881945 100644 --- a/server/web_app/src/Controller/ItemController.php +++ b/server/web_app/src/Controller/ItemController.php @@ -69,16 +69,36 @@ final class ItemController extends AbstractController return new JsonResponse(['error' => 'No items found'], Response::HTTP_NOT_FOUND); } - $itemArray = array_map(fn($item) => [ - 'id' => $item->getId(), - 'wishList' => $item->getWishList()->getId(), - 'title' => $item->getTitle(), - 'description' => $item->getDescription(), - 'price' => $item->getPrice(), - 'purchaseUrl' => $item->getPurchaseUrl(), - 'createdAt' => $item->getCreatedAt() - ], $items); - + $itemArray = array_map(function ($item) { + $wishList = $item->getWishList(); + $user = $wishList->getUser(); // Assuming each wishlist has an associated user + + return [ + 'id' => $item->getId(), + 'wishList' => [ + 'id' => $wishList->getId(), + 'user' => [ + 'id' => $user->getId(), + 'username' => $user->getUserName(), + 'mail' => $user->getEmail(), + 'role' => $user->getRoles(), + 'isBlocked' => $user->isBlocked(), + 'createdAt' => $user->getCreatedAt()->format('Y-m-d H:i:s'), + ], + 'name' => $wishList->getName(), + 'description' => $wishList->getDescription(), + 'expirationDate' => $wishList->getExpirationDate()->format('Y-m-d'), + 'isActive' => $wishList->isActive(), + 'createdAt' => $wishList->getCreatedAt()->format('Y-m-d H:i:s'), + ], + 'title' => $item->getTitle(), + 'description' => $item->getDescription(), + 'price' => $item->getPrice(), + 'purchaseUrl' => $item->getPurchaseUrl(), + 'createdAt' => $item->getCreatedAt()->format('Y-m-d H:i:s'), + ]; + }, $items); + return $this->json([ 'items' => $itemArray, 'page' => $page, @@ -92,30 +112,48 @@ final class ItemController extends AbstractController } #[Route('/{itemId}', methods: ['GET'])] - public function getItemsById($itemId): JsonResponse - { - $item = $this->itemRepository->findOneById($itemId); - - if (!$item) { - return new JsonResponse(['error' => 'Item not found'], Response::HTTP_NOT_FOUND); - } - - $itemDTO = [ - 'id' => $item->getId(), - 'wishList' => $item->getWishList(), - 'title' => $item->getTitle(), - 'description' =>$item->getDescription(), - 'price' =>$item->getPrice(), - 'purchaseUrl' =>$item->getPurchaseUrl(), - 'createdAt' => $item->getCreatedAt() - ]; +public function getItemsById($itemId): JsonResponse +{ + $item = $this->itemRepository->findOneById($itemId); - return $this->json([ - 'user' => $itemDTO, - 'path' => 'src/Controller/ItemController.php', - ]); + if (!$item) { + return new JsonResponse(['error' => 'Item not found'], Response::HTTP_NOT_FOUND); } + $wishList = $item->getWishList(); + $user = $wishList->getUser(); // Assuming a wishlist has an associated user + + $itemDTO = [ + 'id' => $item->getId(), + 'wishList' => [ + 'id' => $wishList->getId(), + 'user' => [ + 'id' => $user->getId(), + 'username' => $user->getUserName(), + 'mail' => $user->getEmail(), + 'role' => $user->getRoles(), + 'isBlocked' => $user->isBlocked(), + 'createdAt' => $user->getCreatedAt()->format('Y-m-d H:i:s'), + ], + 'name' => $wishList->getName(), + 'description' => $wishList->getDescription(), + 'expirationDate' => $wishList->getExpirationDate()->format('Y-m-d'), + 'isActive' => $wishList->isActive(), + 'createdAt' => $wishList->getCreatedAt()->format('Y-m-d H:i:s'), + ], + 'title' => $item->getTitle(), + 'description' => $item->getDescription(), + 'price' => $item->getPrice(), + 'purchaseUrl' => $item->getPurchaseUrl(), + 'createdAt' => $item->getCreatedAt()->format('Y-m-d H:i:s'), + ]; + + return $this->json([ + 'item' => $itemDTO, + 'path' => 'src/Controller/ItemController.php', + ]); +} + } diff --git a/server/web_app/src/Controller/WishListController.php b/server/web_app/src/Controller/WishListController.php index 0a0aa4f3a9364c056cd49c7914ec7d02d8005abb..8a888468f28cc4bd57cd79147d01fede94ffea91 100644 --- a/server/web_app/src/Controller/WishListController.php +++ b/server/web_app/src/Controller/WishListController.php @@ -124,10 +124,39 @@ final class WishListController extends AbstractController $max = (int) $request->query->get('max', 10); // Default 10 per page $page = (int) $request->query->get('page', 1); // Default page 1 - $wishLists = $this->itemRepository->findWishListsSortedByTotalBought($sort, $max, $page); + $info = $this->itemRepository->findWishListsSortedByTotalBought($sort, $max, $page); + + if (!$info) { + return new JsonResponse(['error' => 'No wishLists found with item boughs'], Response::HTTP_NOT_FOUND); + } + + $wishListsData = array_map(function ($item) { + $wishList = $this->wishListRepository->findOneById($item['wishListId']); + $user = $wishList->getUser(); + + return [ + 'wishList' => [ + 'id' => $wishList->getId(), + 'user' => [ + 'id' => $user->getId(), + 'username' => $user->getUserName(), + 'mail' => $user->getEmail(), + 'role' => $user->getRoles(), + 'isBlocked' => $user->isBlocked(), + 'createdAt' => $user->getCreatedAt()->format('Y-m-d H:i:s'), // Format DateTime + ], + 'name' => $wishList->getName(), + 'description' => $wishList->getDescription(), + 'expirationDate' => $wishList->getExpirationDate()->format('Y-m-d'), // Format Date + 'isActive' => $wishList->isActive(), + 'createdAt' => $wishList->getCreatedAt()->format('Y-m-d H:i:s'), // Format DateTime + ], + 'totalPrice' => $item['totalPrice'], + ]; + }, $info); return $this->json([ - 'wishLists' => $wishLists, + 'wishLists' => $wishListsData, 'pagination' => [ 'max' => $max, 'page' => $page diff --git a/server/web_app/src/DataFixtures/ItemFixtures.php b/server/web_app/src/DataFixtures/ItemFixtures.php index f383d423be0b9b4d2ccd367eb0bc333dac2c1e7e..b0b60578b539810be938528f9035385faddfeea9 100644 --- a/server/web_app/src/DataFixtures/ItemFixtures.php +++ b/server/web_app/src/DataFixtures/ItemFixtures.php @@ -19,7 +19,7 @@ class ItemFixtures extends Fixture implements DependentFixtureInterface } $itemsData = [ - [ + [ 'wishList' => $wishLists[0], 'title' => 'Smartphone', 'description' => 'Latest model with high-end specs', @@ -41,20 +41,55 @@ class ItemFixtures extends Fixture implements DependentFixtureInterface 'purchase_url' => 'https://example.com/headphones', ], [ - 'wishList' => $wishLists[0], + 'wishList' => $wishLists[3], 'title' => 'Coffee Maker', 'description' => 'Automatic coffee maker with multiple settings', 'price' => 89.99, 'purchase_url' => 'https://example.com/coffee-maker', ], [ - 'wishList' => $wishLists[1], + 'wishList' => $wishLists[4], 'title' => 'Gaming Chair', 'description' => 'Ergonomic chair for long gaming sessions', 'price' => 249.99, 'purchase_url' => 'https://example.com/gaming-chair', - ] - ]; + ], + [ + 'wishList' => $wishLists[0], + 'title' => 'Smartwatch', + 'description' => 'Fitness tracker with health monitoring features', + 'price' => 299.99, + 'purchase_url' => 'https://example.com/smartwatch', + ], + [ + 'wishList' => $wishLists[1], + 'title' => 'Mechanical Keyboard', + 'description' => 'RGB backlit mechanical keyboard for gaming', + 'price' => 149.99, + 'purchase_url' => 'https://example.com/keyboard', + ], + [ + 'wishList' => $wishLists[2], + 'title' => 'E-Reader', + 'description' => 'Portable e-reader with high-resolution display', + 'price' => 129.99, + 'purchase_url' => 'https://example.com/e-reader', + ], + [ + 'wishList' => $wishLists[3], + 'title' => 'Noise Cancelling Earbuds', + 'description' => 'True wireless earbuds with superior noise cancellation', + 'price' => 179.99, + 'purchase_url' => 'https://example.com/earbuds', + ], + [ + 'wishList' => $wishLists[4], + 'title' => 'Camera Drone', + 'description' => 'High-resolution drone with advanced stabilization', + 'price' => 999.99, + 'purchase_url' => 'https://example.com/drone', + ], + ]; foreach ($itemsData as $itemData) { $item = new Item(); diff --git a/server/web_app/src/DataFixtures/PurchaseFixtures.php b/server/web_app/src/DataFixtures/PurchaseFixtures.php index 5a332e6fcbe049806f54143278ad64cb1e1e32df..c8cfe609622905ac141651ff62ace5025c87b2b2 100644 --- a/server/web_app/src/DataFixtures/PurchaseFixtures.php +++ b/server/web_app/src/DataFixtures/PurchaseFixtures.php @@ -25,17 +25,65 @@ class PurchaseFixtures extends Fixture implements DependentFixtureInterface $purchasesData = [ [ 'user' => $users[0], - 'item' => $items[0], + 'item' => $items[0], // Smartphone 'url_proof' => 'https://example.com/proof1.jpg', 'message' => 'Hope you like this gift!', ], [ 'user' => $users[1], - 'item' => $items[1], + 'item' => $items[1], // Laptop 'url_proof' => 'https://example.com/proof2.jpg', 'message' => 'A little surprise for you!', - ] - ]; + ], + [ + 'user' => $users[3], + 'item' => $items[2], // Wireless Headphones + 'url_proof' => 'https://example.com/proof3.jpg', + 'message' => 'Something special just for you!', + ], + [ + 'user' => $users[4], + 'item' => $items[3], // Coffee Maker + 'url_proof' => 'https://example.com/proof4.jpg', + 'message' => 'Enjoy your new gadget!', + ], + [ + 'user' => $users[6], + 'item' => $items[4], // Gaming Chair + 'url_proof' => 'https://example.com/proof5.jpg', + 'message' => 'Hope this makes your day!', + ], + [ + 'user' => $users[7], + 'item' => $items[5], // Smartwatch + 'url_proof' => 'https://example.com/proof6.jpg', + 'message' => 'A little something for you!', + ], + [ + 'user' => $users[8], + 'item' => $items[6], // Mechanical Keyboard + 'url_proof' => 'https://example.com/proof7.jpg', + 'message' => 'Enjoy your gift!', + ], + [ + 'user' => $users[9], + 'item' => $items[7], // E-Reader + 'url_proof' => 'https://example.com/proof8.jpg', + 'message' => 'Something I thought you’d love!', + ], + [ + 'user' => $users[5], + 'item' => $items[8], // Noise Cancelling Earbuds + 'url_proof' => 'https://example.com/proof9.jpg', + 'message' => 'A special gift for a special person!', + ], + [ + 'user' => $users[2], + 'item' => $items[9], // Camera Drone + 'url_proof' => 'https://example.com/proof10.jpg', + 'message' => 'Just a small token of appreciation!', + ], + ]; foreach ($purchasesData as $data) { $purchase = new Purchase(); diff --git a/server/web_app/src/DataFixtures/UserFixtures.php b/server/web_app/src/DataFixtures/UserFixtures.php index fdb357ff333ff6fd83cd82a1693a670a6b596101..153a4964c132ba54477cc967f8d1e4ddfe2a48e9 100644 --- a/server/web_app/src/DataFixtures/UserFixtures.php +++ b/server/web_app/src/DataFixtures/UserFixtures.php @@ -46,9 +46,72 @@ class UserFixtures extends Fixture 'password' => 'test123', 'is_blocked' => true, 'role' => UserRole::USER, - ] + ], + [ + 'user_name' => 'alice_johnson', + 'name' => 'Alice', + 'surname' => 'Johnson', + 'email' => 'alice.johnson@example.com', + 'password' => 'alicepass', + 'is_blocked' => false, + 'role' => UserRole::USER, + ], + [ + 'user_name' => 'charlie_brown', + 'name' => 'Charlie', + 'surname' => 'Brown', + 'email' => 'charlie.brown@example.com', + 'password' => 'charlie123', + 'is_blocked' => false, + 'role' => UserRole::USER, + ], + [ + 'user_name' => 'david_wilson', + 'name' => 'David', + 'surname' => 'Wilson', + 'email' => 'david.wilson@example.com', + 'password' => 'wilsonpass', + 'is_blocked' => true, + 'role' => UserRole::USER, + ], + [ + 'user_name' => 'emily_clark', + 'name' => 'Emily', + 'surname' => 'Clark', + 'email' => 'emily.clark@example.com', + 'password' => 'emilypass', + 'is_blocked' => false, + 'role' => UserRole::USER, + ], + [ + 'user_name' => 'frank_miller', + 'name' => 'Frank', + 'surname' => 'Miller', + 'email' => 'frank.miller@example.com', + 'password' => 'millerpass', + 'is_blocked' => false, + 'role' => UserRole::ADMIN, + ], + [ + 'user_name' => 'grace_lee', + 'name' => 'Grace', + 'surname' => 'Lee', + 'email' => 'grace.lee@example.com', + 'password' => 'gracepass', + 'is_blocked' => true, + 'role' => UserRole::USER, + ], + [ + 'user_name' => 'henry_adams', + 'name' => 'Henry', + 'surname' => 'Adams', + 'email' => 'henry.adams@example.com', + 'password' => 'henrypass', + 'is_blocked' => false, + 'role' => UserRole::USER, + ], ]; - + foreach ($usersData as $userData) { $user = new User(); $user->setUserName($userData['user_name']); diff --git a/server/web_app/src/DataFixtures/WishListFixtures.php b/server/web_app/src/DataFixtures/WishListFixtures.php index 1a0a557d415ecbc11808770a32e631ed2288a5f2..19d395fcd205a1b841c925a5baddfa853c312790 100644 --- a/server/web_app/src/DataFixtures/WishListFixtures.php +++ b/server/web_app/src/DataFixtures/WishListFixtures.php @@ -23,31 +23,94 @@ class WishListFixtures extends Fixture implements DependentFixtureInterface [ 'name' => 'John\'s Birthday Wishlist', 'description' => 'Birthday Wishlist', - 'user' => $users[0], // Assuming at least one user exists + 'user' => $users[0], 'expiration_date' => new \DateTime('+30 days'), 'is_active' => true, - 'url_view_mode' => 'http://url_view_mode.com', - 'url_edit_mode' => 'http://url_edit_mode.com', + 'url_view_mode' => 'http://url_view_mode.com/john-birthday', + 'url_edit_mode' => 'http://url_edit_mode.com/john-birthday', ], [ 'name' => 'Tech Gadgets Wishlist', 'description' => 'Gadgets Wishlist', - 'user' => $users[1], // Use second user if available, else first user + 'user' => $users[1], 'expiration_date' => new \DateTime('+60 days'), 'is_active' => true, - 'url_view_mode' => 'http://url_view_mode.com', - 'url_edit_mode' => 'http://url_edit_mode.com', + 'url_view_mode' => 'http://url_view_mode.com/tech-gadgets', + 'url_edit_mode' => 'http://url_edit_mode.com/tech-gadgets', ], [ 'name' => 'Home Essentials Wishlist', 'description' => 'Essentials Wishlist', - 'user' => $users[2], // Use third user if available, else first user + 'user' => $users[2], 'expiration_date' => new \DateTime('+90 days'), 'is_active' => false, - 'url_view_mode' => 'http://url_view_mode.com', - 'url_edit_mode' => 'http://url_edit_mode.com', + 'url_view_mode' => 'http://url_view_mode.com/home-essentials', + 'url_edit_mode' => 'http://url_edit_mode.com/home-essentials', ], - ]; + [ + 'name' => 'Fitness Gear Wishlist', + 'description' => 'Wishlist for workout equipment and gear', + 'user' => $users[3], + 'expiration_date' => new \DateTime('+45 days'), + 'is_active' => true, + 'url_view_mode' => 'http://url_view_mode.com/fitness-gear', + 'url_edit_mode' => 'http://url_edit_mode.com/fitness-gear', + ], + [ + 'name' => 'Gaming Setup Wishlist', + 'description' => 'High-end gaming accessories and equipment', + 'user' => $users[4], + 'expiration_date' => new \DateTime('+75 days'), + 'is_active' => true, + 'url_view_mode' => 'http://url_view_mode.com/gaming-setup', + 'url_edit_mode' => 'http://url_edit_mode.com/gaming-setup', + ], + [ + 'name' => 'Travel Essentials Wishlist', + 'description' => 'Must-have travel accessories', + 'user' => $users[5], + 'expiration_date' => new \DateTime('+100 days'), + 'is_active' => false, + 'url_view_mode' => 'http://url_view_mode.com/travel-essentials', + 'url_edit_mode' => 'http://url_edit_mode.com/travel-essentials', + ], + [ + 'name' => 'Photography Gear Wishlist', + 'description' => 'Cameras, lenses, and accessories', + 'user' => $users[6], + 'expiration_date' => new \DateTime('+120 days'), + 'is_active' => true, + 'url_view_mode' => 'http://url_view_mode.com/photography-gear', + 'url_edit_mode' => 'http://url_edit_mode.com/photography-gear', + ], + [ + 'name' => 'Books & Stationery Wishlist', + 'description' => 'Books, notebooks, and writing accessories', + 'user' => $users[7], + 'expiration_date' => new \DateTime('+150 days'), + 'is_active' => true, + 'url_view_mode' => 'http://url_view_mode.com/books-stationery', + 'url_edit_mode' => 'http://url_edit_mode.com/books-stationery', + ], + [ + 'name' => 'Kitchen Appliances Wishlist', + 'description' => 'Modern kitchen gadgets and appliances', + 'user' => $users[8], + 'expiration_date' => new \DateTime('+180 days'), + 'is_active' => false, + 'url_view_mode' => 'http://url_view_mode.com/kitchen-appliances', + 'url_edit_mode' => 'http://url_edit_mode.com/kitchen-appliances', + ], + [ + 'name' => 'Fashion & Accessories Wishlist', + 'description' => 'Trendy clothes, shoes, and accessories', + 'user' => $users[9], + 'expiration_date' => new \DateTime('+200 days'), + 'is_active' => true, + 'url_view_mode' => 'http://url_view_mode.com/fashion-accessories', + 'url_edit_mode' => 'http://url_edit_mode.com/fashion-accessories', + ], + ]; foreach ($wishListsData as $wishListData) { $wishList = new WishList(); diff --git a/server/web_app/src/DataFixtures/WishListMemberFixtures.php b/server/web_app/src/DataFixtures/WishListMemberFixtures.php index b2100cd6040a69f6fdbf9d855a24c6bbd6aa37b6..a4b291398bbd9b4a6b749c9aa3c375ebdd2a0e2a 100644 --- a/server/web_app/src/DataFixtures/WishListMemberFixtures.php +++ b/server/web_app/src/DataFixtures/WishListMemberFixtures.php @@ -39,7 +39,49 @@ class WishListMemberFixtures extends Fixture implements DependentFixtureInterfac 'user' => $users[2], 'can_edit' => true, 'is_accepted' => false, - ] + ], + [ + 'wishList' => $wishLists[1], + 'user' => $users[3], + 'can_edit' => false, + 'is_accepted' => true, + ], + [ + 'wishList' => $wishLists[2], + 'user' => $users[4], + 'can_edit' => true, + 'is_accepted' => true, + ], + [ + 'wishList' => $wishLists[2], + 'user' => $users[5], + 'can_edit' => false, + 'is_accepted' => false, + ], + [ + 'wishList' => $wishLists[3], + 'user' => $users[6], + 'can_edit' => true, + 'is_accepted' => true, + ], + [ + 'wishList' => $wishLists[3], + 'user' => $users[7], + 'can_edit' => false, + 'is_accepted' => true, + ], + [ + 'wishList' => $wishLists[4], + 'user' => $users[8], + 'can_edit' => true, + 'is_accepted' => false, + ], + [ + 'wishList' => $wishLists[4], + 'user' => $users[9], + 'can_edit' => false, + 'is_accepted' => true, + ], ]; foreach ($wishListMembersData as $data) { diff --git a/server/web_app/src/Repository/WishListRepository.php b/server/web_app/src/Repository/WishListRepository.php index 2d45f9299e6e33c6531ee0e527325836737fad86..86d1f4da1bb5be0974a80216f39451718c46c9d1 100644 --- a/server/web_app/src/Repository/WishListRepository.php +++ b/server/web_app/src/Repository/WishListRepository.php @@ -16,6 +16,10 @@ class WishListRepository extends ServiceEntityRepository parent::__construct($registry, WishList::class); } + public function findOneById(int $id): ?WishList { + return $this->findOneBy(['id' => $id]); + } + public function findAllItems (): array { return $this->findAll(); }