Bruno Predot

Ajout model + interface MovieComment.

  1 +import type { MovieInterface } from "~/interfaces/movie";
  2 +
  3 +export interface MovieCommentInterface {
  4 + username: string;
  5 + message: string;
  6 + rating: number;
  7 + movie_id: unknown;
  8 + movie: MovieInterface;
  9 +}
  1 +import { Model } from "pinia-orm";
  2 +import { Movie } from "~/models/movie";
  3 +
  4 +export class MovieComment extends Model {
  5 + /**
  6 + *
  7 + * @return {string}
  8 + */
  9 + static get entity() {
  10 + return "MovieComment";
  11 + }
  12 +
  13 + /**
  14 + *
  15 + * @return {string}
  16 + */
  17 + static get primaryKey() {
  18 + return "id";
  19 + }
  20 +
  21 + static fields() {
  22 + return {
  23 + // Attributs.
  24 + id: this.number(null),
  25 + username: this.string(''),
  26 + message: this.string(''),
  27 + rating: this.string(''),
  28 + // Relations.
  29 + movie_id: this.attr(null),
  30 + movie: this.belongsTo(Movie, "movie_id", "id"),
  31 + };
  32 + }
  33 +
  34 + static piniaOptions = {
  35 + persist: true,
  36 + };
  37 +}
@@ -105,6 +105,7 @@ async function fetchCredits(id: number | string) { @@ -105,6 +105,7 @@ async function fetchCredits(id: number | string) {
105 } 105 }
106 106
107 function handleSubmitEvent(event: Comment) { 107 function handleSubmitEvent(event: Comment) {
  108 + //todo : faire la gestion des commentaire avec un nouveau model + liaison.
108 console.log('submitted', event) 109 console.log('submitted', event)
109 } 110 }
110 111
@@ -183,6 +184,7 @@ onMounted(() => { @@ -183,6 +184,7 @@ onMounted(() => {
183 </div> 184 </div>
184 </div> 185 </div>
185 <!-- Comments form. --> 186 <!-- Comments form. -->
  187 + <h3 class="text-xl font-bold mt-8 mb-4">Ajouter un commentaire</h3>
186 <form-movie-comment-form @event:submit="handleSubmitEvent" /> 188 <form-movie-comment-form @event:submit="handleSubmitEvent" />
187 </section> 189 </section>
188 </div> 190 </div>