Bruno Predot

Ajout du du model Movie.

@@ -4,4 +4,6 @@ @@ -4,4 +4,6 @@
4 - Modification app.vue afin d'initialiser l'app avec vuetify et NuxtPage pour démarrer sur la page index. 4 - Modification app.vue afin d'initialiser l'app avec vuetify et NuxtPage pour démarrer sur la page index.
5 - Création du composant MoviesList. 5 - Création du composant MoviesList.
6 - Création du composant SearchBar. 6 - Création du composant SearchBar.
7 -- Création du composant SkeletonMoviesLoader. 7 +- Création du composant SkeletonMoviesLoader.
  8 +- Installation et paramétrage de pinia-orm.
  9 +- Ajout du du model Movie.
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 import SearchBar from "~/components/SearchBar.vue"; 3 import SearchBar from "~/components/SearchBar.vue";
4 import { ref } from "vue"; 4 import { ref } from "vue";
5 import { useTMDB } from "~/composables/tMDB"; 5 import { useTMDB } from "~/composables/tMDB";
  6 +import { Movie } from "~/models/movie";
6 //#endregion 7 //#endregion
7 8
8 //#region --Declaration--. 9 //#region --Declaration--.
@@ -33,13 +34,14 @@ const fetchMovies = async (page: number) => { @@ -33,13 +34,14 @@ const fetchMovies = async (page: number) => {
33 try { 34 try {
34 isLoadingMore.value = true; 35 isLoadingMore.value = true;
35 const data = await fetchPopularMovies(page); 36 const data = await fetchPopularMovies(page);
36 - console.log("data in fetchMovies", data);  
37 37
38 if (page === 1) { 38 if (page === 1) {
39 movies.value = data.results; 39 movies.value = data.results;
40 } else { 40 } else {
41 movies.value = [...movies.value, ...data.results]; 41 movies.value = [...movies.value, ...data.results];
42 } 42 }
  43 + // Save in Movie model.
  44 + useRepo(Movie).save(data.results);
43 45
44 totalPages.value = data.total_pages; 46 totalPages.value = data.total_pages;
45 currentPage.value = page; 47 currentPage.value = page;
  1 +import { Model } from "pinia-orm";
  2 +
  3 +export class Movie extends Model {
  4 + /**
  5 + *
  6 + * @return {string}
  7 + */
  8 + static get entity() {
  9 + return "Movie";
  10 + }
  11 +
  12 + /**
  13 + *
  14 + * @return {string}
  15 + */
  16 + static get primaryKey() {
  17 + return "id";
  18 + }
  19 +
  20 + static fields() {
  21 + return {
  22 + // Attributs.
  23 + id: this.number(null),
  24 + adult: this.boolean(false),
  25 + backdrop_pat: this.string(null),
  26 + genre_ids: this.attr([]),
  27 + original_language: this.string(null),
  28 + original_title: this.string(null),
  29 + overview: this.string(null),
  30 + popularity: this.number(null),
  31 + poster_path: this.string(null),
  32 + release_date: this.string(null),
  33 + title: this.string(null),
  34 + video: this.boolean(false),
  35 + vote_average: this.number(null),
  36 + vote_count: this.number(null),
  37 + // Relations.
  38 + };
  39 + }
  40 +
  41 + static piniaOptions = {
  42 + persist: true,
  43 + };
  44 +
  45 +}