From dd8df8f4a759e946e96dba886a78082059b8504b Mon Sep 17 00:00:00 2001 From: Guamss Date: Fri, 5 Dec 2025 16:56:36 +0100 Subject: [PATCH] =?UTF-8?q?d=C3=A9but=20d'une=20page=20d'accueil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Authenticate.vue | 5 ++++- src/components/Home.vue | 30 +++++++++++++++--------------- src/const.ts | 4 ++++ src/models/book.ts | 3 ++- src/routes.ts | 9 ++------- src/services/book.service.ts | 21 +++++++++++++++++++++ 6 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 src/const.ts create mode 100644 src/services/book.service.ts diff --git a/src/components/Authenticate.vue b/src/components/Authenticate.vue index 317af9f..81efd82 100644 --- a/src/components/Authenticate.vue +++ b/src/components/Authenticate.vue @@ -1,6 +1,7 @@ - + diff --git a/src/const.ts b/src/const.ts new file mode 100644 index 0000000..be6231c --- /dev/null +++ b/src/const.ts @@ -0,0 +1,4 @@ +export const PLAN_TO_READ = 'PLAN' +export const READING = 'READING' +export const COMPLETED = 'COMPLETED' +export const DROPPED = 'DROPPED' \ No newline at end of file diff --git a/src/models/book.ts b/src/models/book.ts index f64b998..05bf2de 100644 --- a/src/models/book.ts +++ b/src/models/book.ts @@ -1,9 +1,10 @@ + export class Book { id: number = 0 note: number = 0 title: string = "" author: string = "" - state: string = "PLAN" + state: 'PLAN' | 'READING' | 'COMPLETED' | 'DROPPED' = 'PLAN' added_at: Date = new Date() updated_at: Date = new Date() } \ No newline at end of file diff --git a/src/routes.ts b/src/routes.ts index ef20f52..7c1632e 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -4,13 +4,12 @@ import Home from './components/Home.vue' const routes = [ { - path: '/home', + path: '/', component: Home, name: "Home", - meta: { requiresAuth: true } }, { - path: '/', + path: '/authenticate', component: Authenticate, name: "Authenticate", meta: { guestOnly: true } @@ -25,10 +24,6 @@ export const router = createRouter({ router.beforeEach((to, from) => { const authenticated = sessionStorage.getItem('access'); - if (to.meta.requiresAuth && !authenticated) { - return { name: 'Authenticate' }; - } - if (to.meta.guestOnly && authenticated) { return { name: 'Home' }; } diff --git a/src/services/book.service.ts b/src/services/book.service.ts new file mode 100644 index 0000000..e03cb37 --- /dev/null +++ b/src/services/book.service.ts @@ -0,0 +1,21 @@ +import type { Book } from "@/models/book"; +import axios from "axios"; + +export const MBL_API_URL = "http://localhost:8000"; + +export class BookService { + constructor() { + axios.defaults.baseURL = `${MBL_API_URL}/api/books`; + } + + async findBooks() { + return await axios + .get("") + .then((res) => { + return res.data as Book[]; + }) + .catch((error) => { + throw error; + }); + } +}