Bruno Predot

Ajout du du model Movie.

... ... @@ -5,3 +5,5 @@
- Création du composant MoviesList.
- Création du composant SearchBar.
- Création du composant SkeletonMoviesLoader.
- Installation et paramétrage de pinia-orm.
- Ajout du du model Movie.
\ No newline at end of file
... ...
... ... @@ -3,6 +3,7 @@
import SearchBar from "~/components/SearchBar.vue";
import { ref } from "vue";
import { useTMDB } from "~/composables/tMDB";
import { Movie } from "~/models/movie";
//#endregion
//#region --Declaration--.
... ... @@ -33,13 +34,14 @@ const fetchMovies = async (page: number) => {
try {
isLoadingMore.value = true;
const data = await fetchPopularMovies(page);
console.log("data in fetchMovies", data);
if (page === 1) {
movies.value = data.results;
} else {
movies.value = [...movies.value, ...data.results];
}
// Save in Movie model.
useRepo(Movie).save(data.results);
totalPages.value = data.total_pages;
currentPage.value = page;
... ...
import { Model } from "pinia-orm";
export class Movie extends Model {
/**
*
* @return {string}
*/
static get entity() {
return "Movie";
}
/**
*
* @return {string}
*/
static get primaryKey() {
return "id";
}
static fields() {
return {
// Attributs.
id: this.number(null),
adult: this.boolean(false),
backdrop_pat: this.string(null),
genre_ids: this.attr([]),
original_language: this.string(null),
original_title: this.string(null),
overview: this.string(null),
popularity: this.number(null),
poster_path: this.string(null),
release_date: this.string(null),
title: this.string(null),
video: this.boolean(false),
vote_average: this.number(null),
vote_count: this.number(null),
// Relations.
};
}
static piniaOptions = {
persist: true,
};
}
\ No newline at end of file
... ...