From 148249552446b05cd4e312f225dfa2b26fecffb3 Mon Sep 17 00:00:00 2001 From: jleroy Date: Thu, 13 Mar 2025 12:08:14 +0100 Subject: [PATCH] patch test Signal use --- backend/controllers/videoController.js | 22 +++++ backend/routes/apiRoutes.js | 4 + src/app/_models/video.ts | 13 +++ src/app/_services/video.service.ts | 22 +++++ src/app/public/pages/home/home.component.html | 90 +++---------------- src/app/public/pages/home/home.component.ts | 28 +++++- 6 files changed, 99 insertions(+), 80 deletions(-) create mode 100644 backend/controllers/videoController.js create mode 100644 src/app/_models/video.ts create mode 100644 src/app/_services/video.service.ts diff --git a/backend/controllers/videoController.js b/backend/controllers/videoController.js new file mode 100644 index 0000000..e5715b4 --- /dev/null +++ b/backend/controllers/videoController.js @@ -0,0 +1,22 @@ +import pool from "../config/db.js"; + +export const getVideo = async (req, res) => { + let conn; + try { + conn = await pool.getConnection(); + const data = await conn.query(`SELECT * FROM video ORDER BY created_at DESC`); + return res.status(200).json({ + data + }); + } catch (error) { + console.error('Erreur lors de la récupération de l\'utilisateur :', error); + return res.status(500).json({ + message: 'Erreur lors de la récupération de l\'utilisateur.', + status: false + }); + } finally { + if (conn) { + await conn.release(); + } + } +}; diff --git a/backend/routes/apiRoutes.js b/backend/routes/apiRoutes.js index 79573e7..4bb2ae8 100644 --- a/backend/routes/apiRoutes.js +++ b/backend/routes/apiRoutes.js @@ -11,6 +11,7 @@ import {verifyToken} from "../middleware/tokenJWTMiddleware.js"; import multer from "multer"; import { v4 as uuidv4 } from 'uuid'; import path from "node:path"; +import {getVideo} from "../controllers/videoController.js"; router.get('', apiController); @@ -51,4 +52,7 @@ router.post('/auth/logout', logout); router.get('/auth/user', verifyToken, getprofile); router.get('/auth/check-auth', verifyToken, checkAuth); +// Récupérer vidéo +router.get('/video', getVideo) + export default router; diff --git a/src/app/_models/video.ts b/src/app/_models/video.ts new file mode 100644 index 0000000..33e8e26 --- /dev/null +++ b/src/app/_models/video.ts @@ -0,0 +1,13 @@ +export interface Videos { + data: Video[]; +} +export interface Video { + id: number; + user_id: number; + name: string; + description: string; + link_miniature: string; + link_video: string; + created_at: Date; + updated_at: Date; +} diff --git a/src/app/_services/video.service.ts b/src/app/_services/video.service.ts new file mode 100644 index 0000000..5a31570 --- /dev/null +++ b/src/app/_services/video.service.ts @@ -0,0 +1,22 @@ +import { Injectable } from '@angular/core'; +import {HttpClient, HttpHeaders} from '@angular/common/http'; +import {Observable} from 'rxjs'; +import {Videos} from '../_models/video'; +import {environment} from '../../environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class VideoService { + + constructor(private http: HttpClient) { } + + getVideo(): Observable { + const headers = new HttpHeaders({ + 'Authorization': environment.apikey, + 'Content-Type': 'application/json' + }); + return this.http.get(environment.apiurl + '/video', { headers }); + } + +} diff --git a/src/app/public/pages/home/home.component.html b/src/app/public/pages/home/home.component.html index 69572f6..b628c05 100644 --- a/src/app/public/pages/home/home.component.html +++ b/src/app/public/pages/home/home.component.html @@ -1,85 +1,19 @@
-
- - ecommerce - -
-

CATEGORY

-

The Catalyzer

-

$16.00

+ @for (video of videos; track video.name) { + -
-
- - ecommerce - -
-

CATEGORY

-

Shooting Stars

-
-
-
- - ecommerce - -
-

CATEGORY

-

Neptune

-

$12.00

-
-
-
- - ecommerce - -
-

CATEGORY

-

The 400 Blows

-

$18.40

-
-
-
- - ecommerce - -
-

CATEGORY

-

The Catalyzer

-

$16.00

-
-
-
- - ecommerce - -
-

CATEGORY

-

Shooting Stars

-

$21.15

-
-
-
- - ecommerce - -
-

CATEGORY

-

Neptune

-

$12.00

-
-
-
- - ecommerce - -
-

CATEGORY

-

The 400 Blows

-

$18.40

-
-
+ }
diff --git a/src/app/public/pages/home/home.component.ts b/src/app/public/pages/home/home.component.ts index 487c621..a583279 100644 --- a/src/app/public/pages/home/home.component.ts +++ b/src/app/public/pages/home/home.component.ts @@ -1,19 +1,43 @@ import {Component, OnInit} from '@angular/core'; import {Title} from '@angular/platform-browser'; +import {VideoService} from '../../../_services/video.service'; +import {Video} from '../../../_models/video'; +import {DatePipe} from '@angular/common'; @Component({ selector: 'app-home', - imports: [], + imports: [ + DatePipe + ], templateUrl: './home.component.html', styleUrl: './home.component.css' }) export class HomeComponent implements OnInit { - constructor(private title: Title) { + videos: Video[] = [] + + constructor(private title: Title, private videoService: VideoService) { } ngOnInit(): void { this.title.setTitle('Accueil - YouVideo'); + this.videoService.getVideo().subscribe(v => { + this.videos = v.data; + }) + } + + generatorLink() { + const baseId = 'qiSOyusTaeo'; + const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; + const length = 11; + + let randomPart = ''; + for (let i = 0; i < length; i++) { + const randomIndex = Math.floor(Math.random() * characters.length); + randomPart += characters.charAt(randomIndex); + } + + return `https://youtube.com/watch?v=${randomPart}`; } }