From d9e935f7ded2b15be77460f90a31797c46ce8179 Mon Sep 17 00:00:00 2001 From: "ext.jeremy.guillot@maxicoffee.domains" Date: Tue, 25 Mar 2025 22:44:26 +0100 Subject: [PATCH] feat: ajout d'une route GetMangaByIdHandler.php et fix de la SearchBar.vue --- .../manga/application/queries/searchMangas.js | 2 +- .../manga/application/store/mangaStore.js | 26 ++-- .../app/domain/manga/domain/entities/manga.js | 2 + .../infrastructure/api/apiMangaRepository.js | 6 +- .../manga/presentation/pages/HomePage.vue | 33 ++--- .../manga/presentation/pages/MangaDetails.vue | 9 +- assets/vue/app/router/index.js | 5 +- .../shared/components/layout/SearchBar.vue | 13 +- .../Application/Query/SearchLocalManga.php | 13 ++ .../QueryHandler/GetMangaByIdHandler.php | 1 + .../QueryHandler/SearchLocalMangaHandler.php | 45 ++++++ .../Application/Response/MangaResponse.php | 3 +- .../Application/Response/MangaSearchItem.php | 4 +- .../Response/SearchLocalMangaResponse.php | 26 ++++ .../Repository/MangaRepositoryInterface.php | 2 + .../ApiPlatform/Dto/MangaListItem.php | 3 +- .../ApiPlatform/Dto/MangaSearchItem.php | 3 +- .../ApiPlatform/Resource/MangaResource.php | 2 +- .../Resource/MangaSearchResource.php | 4 +- .../Resource/SearchLocalMangaResource.php | 85 +++++++++++ .../Provider/GetMangaListStateProvider.php | 5 +- .../SearchLocalMangaStateProvider.php | 62 ++++++++ .../Persistence/LegacyMangaRepository.php | 68 +++++++-- .../Manga/Adapter/InMemoryMangaRepository.php | 33 ++++- tests/Feature/Manga/GetMangaTest.php | 4 +- tests/Feature/Manga/SearchMangaTest.php | 139 ++++++++++++++++++ 26 files changed, 519 insertions(+), 79 deletions(-) create mode 100644 src/Domain/Manga/Application/Query/SearchLocalManga.php create mode 100644 src/Domain/Manga/Application/QueryHandler/SearchLocalMangaHandler.php create mode 100644 src/Domain/Manga/Application/Response/SearchLocalMangaResponse.php create mode 100644 src/Domain/Manga/Infrastructure/ApiPlatform/Resource/SearchLocalMangaResource.php create mode 100644 src/Domain/Manga/Infrastructure/ApiPlatform/State/Provider/SearchLocalMangaStateProvider.php create mode 100644 tests/Feature/Manga/SearchMangaTest.php diff --git a/assets/vue/app/domain/manga/application/queries/searchMangas.js b/assets/vue/app/domain/manga/application/queries/searchMangas.js index a772aa9..4989381 100644 --- a/assets/vue/app/domain/manga/application/queries/searchMangas.js +++ b/assets/vue/app/domain/manga/application/queries/searchMangas.js @@ -15,4 +15,4 @@ export class SearchMangas { throw error; } } -} \ No newline at end of file +} diff --git a/assets/vue/app/domain/manga/application/store/mangaStore.js b/assets/vue/app/domain/manga/application/store/mangaStore.js index 30c190c..7400485 100644 --- a/assets/vue/app/domain/manga/application/store/mangaStore.js +++ b/assets/vue/app/domain/manga/application/store/mangaStore.js @@ -1,5 +1,5 @@ -import { defineStore } from 'pinia'; -import { ApiMangaRepository } from '../../infrastructure/api/apiMangaRepository'; +import {defineStore} from 'pinia'; +import {ApiMangaRepository} from '../../infrastructure/api/apiMangaRepository'; const mangaRepository = new ApiMangaRepository(); @@ -19,32 +19,26 @@ export const useMangaStore = defineStore('manga', { // Actions pour la collection async loadCollection() { if (this.loading) return; - - console.log('Starting loadCollection...'); + this.loading = true; this.error = null; - + try { - console.log('Fetching collection from repository...'); this.collection = await mangaRepository.getCollection(); - console.log('Collection loaded:', this.collection); } catch (err) { this.error = err.message; - console.error('Failed to load collection:', err); } finally { this.loading = false; - console.log('loadCollection finished. Loading:', this.loading); } }, async refreshCollectionInBackground() { if (this.isBackgroundLoading) return; - + this.isBackgroundLoading = true; - + try { - const updatedCollection = await mangaRepository.getCollection(); - this.collection = updatedCollection; + this.collection = await mangaRepository.getCollection(); } catch (err) { console.error('Failed to refresh collection:', err); } finally { @@ -70,12 +64,10 @@ export const useMangaStore = defineStore('manga', { this.error = null; try { const response = await mangaRepository.getChapters(mangaId); - console.log('API Response:', response); // Pour déboguer - this.chapters = Array.isArray(response) ? response : + this.chapters = Array.isArray(response) ? response : (response.items ? response.items : []); } catch (error) { this.error = error.message; - console.error('Failed to fetch chapters:', error); } finally { this.loading = false; } @@ -86,4 +78,4 @@ export const useMangaStore = defineStore('manga', { this.chapters = []; } } -}); \ No newline at end of file +}); diff --git a/assets/vue/app/domain/manga/domain/entities/manga.js b/assets/vue/app/domain/manga/domain/entities/manga.js index 5c42700..cba5686 100644 --- a/assets/vue/app/domain/manga/domain/entities/manga.js +++ b/assets/vue/app/domain/manga/domain/entities/manga.js @@ -6,6 +6,7 @@ export class Manga { description = null, authors = [], imageUrl = null, + thumbnailUrl = null, publicationYear = null, status = null, rating = null, @@ -18,6 +19,7 @@ export class Manga { this.description = description; this.authors = authors; this.imageUrl = imageUrl; + this.thumbnailUrl = thumbnailUrl; this.publicationYear = publicationYear; this.status = status; this.rating = rating; diff --git a/assets/vue/app/domain/manga/infrastructure/api/apiMangaRepository.js b/assets/vue/app/domain/manga/infrastructure/api/apiMangaRepository.js index f75af8d..35b75b2 100644 --- a/assets/vue/app/domain/manga/infrastructure/api/apiMangaRepository.js +++ b/assets/vue/app/domain/manga/infrastructure/api/apiMangaRepository.js @@ -24,7 +24,7 @@ export class ApiMangaRepository { async getMangaById(id) { try { - const response = await fetch(`/api/mangas/${id}`); + const response = await fetch(`/api/mangas/by-id/${id}`); if (!response.ok) { throw new Error('Failed to fetch manga details'); } @@ -64,7 +64,7 @@ export class ApiMangaRepository { async getMangaBySlug(slug) { try { - const response = await fetch(`/api/mangas/${slug}`); + const response = await fetch(`/api/mangas/by-slug/${slug}`); if (!response.ok) { throw new Error('Failed to fetch manga details'); } @@ -87,4 +87,4 @@ export class ApiMangaRepository { throw error; } } -} \ No newline at end of file +} diff --git a/assets/vue/app/domain/manga/presentation/pages/HomePage.vue b/assets/vue/app/domain/manga/presentation/pages/HomePage.vue index 331d9bd..03204d9 100644 --- a/assets/vue/app/domain/manga/presentation/pages/HomePage.vue +++ b/assets/vue/app/domain/manga/presentation/pages/HomePage.vue @@ -17,7 +17,7 @@ import { storeToRefs } from 'pinia'; import { useMangaStore } from '../../application/store/mangaStore'; import MangaGrid from '../components/MangaGrid.vue'; import Toolbar from '../../../../shared/components/ui/Toolbar.vue'; -import { +import { ArrowPathIcon, MagnifyingGlassIcon, Cog6ToothIcon, @@ -29,35 +29,22 @@ import { const router = useRouter(); const mangaStore = useMangaStore(); -const { - collection, - loading, - error, - isBackgroundLoading +const { + collection, + loading, + error, + isBackgroundLoading } = storeToRefs(mangaStore); onMounted(() => { - console.log('HomePage mounted'); - console.log('Store state before loadCollection:', { - collection: collection.value, - loading: loading.value, - error: error.value - }); - mangaStore.loadCollection(); - - console.log('loadCollection called'); }); -const handleAddMangaClick = (query = '') => { - router.push(`/add${query ? `?q=${encodeURIComponent(query)}` : ''}`); -}; - const toolbarConfig = { leftSection: [ - { - icon: ArrowPathIcon, - label: 'Refresh', + { + icon: ArrowPathIcon, + label: 'Refresh', onClick: () => mangaStore.refreshCollectionInBackground(), active: isBackgroundLoading }, @@ -70,4 +57,4 @@ const toolbarConfig = { { icon: FunnelIcon, onClick: () => {} } ] }; - \ No newline at end of file + diff --git a/assets/vue/app/domain/manga/presentation/pages/MangaDetails.vue b/assets/vue/app/domain/manga/presentation/pages/MangaDetails.vue index 302ef15..530552a 100644 --- a/assets/vue/app/domain/manga/presentation/pages/MangaDetails.vue +++ b/assets/vue/app/domain/manga/presentation/pages/MangaDetails.vue @@ -159,7 +159,7 @@