début d'une page d'accueil

This commit is contained in:
Guamss 2025-12-05 16:56:36 +01:00
parent 122e77b67c
commit dd8df8f4a7
6 changed files with 48 additions and 24 deletions

View File

@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { AuthenticationService } from '@/services/authentication.service'; import { AuthenticationService } from '@/services/authentication.service';
import { ref } from 'vue'; import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { useToast } from 'vue-toast-notification'; import { useToast } from 'vue-toast-notification';
const username = ref<string>('') const username = ref<string>('')
@ -11,16 +12,18 @@ const passwordErrorDetail = ref<string>('')
const generalErrorDetail = ref<string>('') const generalErrorDetail = ref<string>('')
const toastService = useToast(); const toastService = useToast();
const router = useRouter()
const authenticationService = new AuthenticationService() const authenticationService = new AuthenticationService()
async function submit() { async function submit() {
try { try {
await authenticationService.authenticate(username.value, password.value) await authenticationService.authenticate(username.value, password.value)
toastService.success(`Heureux de vous revoir ${username}!`, { toastService.success(`Heureux de vous revoir ${username.value}!`, {
position: 'top-right', position: 'top-right',
pauseOnHover: true, pauseOnHover: true,
dismissible: true, dismissible: true,
}) })
router.push('/');
} catch (error: any) { } catch (error: any) {
usernameErrorDetail.value = '' usernameErrorDetail.value = ''
passwordErrorDetail.value = '' passwordErrorDetail.value = ''

View File

@ -1,23 +1,23 @@
<script setup lang="ts"> <script setup lang="ts">
import {type Ref, ref} from "vue"; import type { Book } from "@/models/book";
import { BookService } from "@/services/book.service";
import { onMounted, ref } from "vue";
const count: Ref<number> = ref(0); const books = ref<Book[]>([])
function increment(): void { const bookService = new BookService();
count.value++;
} onMounted(async () => {
books.value = await bookService.findBooks()
});
</script> </script>
<template> <template>
<main> <pre></pre>
</main> <div v-for="book in books">
{{ book.title }}
</div>
</template> </template>
<style scoped> <style scoped></style>
main {
display: flex;
flex-direction: column;
gap: 1rem;
align-items: center;
}
</style>

4
src/const.ts Normal file
View File

@ -0,0 +1,4 @@
export const PLAN_TO_READ = 'PLAN'
export const READING = 'READING'
export const COMPLETED = 'COMPLETED'
export const DROPPED = 'DROPPED'

View File

@ -1,9 +1,10 @@
export class Book { export class Book {
id: number = 0 id: number = 0
note: number = 0 note: number = 0
title: string = "" title: string = ""
author: string = "" author: string = ""
state: string = "PLAN" state: 'PLAN' | 'READING' | 'COMPLETED' | 'DROPPED' = 'PLAN'
added_at: Date = new Date() added_at: Date = new Date()
updated_at: Date = new Date() updated_at: Date = new Date()
} }

View File

@ -4,13 +4,12 @@ import Home from './components/Home.vue'
const routes = [ const routes = [
{ {
path: '/home', path: '/',
component: Home, component: Home,
name: "Home", name: "Home",
meta: { requiresAuth: true }
}, },
{ {
path: '/', path: '/authenticate',
component: Authenticate, component: Authenticate,
name: "Authenticate", name: "Authenticate",
meta: { guestOnly: true } meta: { guestOnly: true }
@ -25,10 +24,6 @@ export const router = createRouter({
router.beforeEach((to, from) => { router.beforeEach((to, from) => {
const authenticated = sessionStorage.getItem('access'); const authenticated = sessionStorage.getItem('access');
if (to.meta.requiresAuth && !authenticated) {
return { name: 'Authenticate' };
}
if (to.meta.guestOnly && authenticated) { if (to.meta.guestOnly && authenticated) {
return { name: 'Home' }; return { name: 'Home' };
} }

View File

@ -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;
});
}
}