1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 13:29:22 +00:00

Can get the list of movies of the user

This commit is contained in:
Pierre HUBERT 2020-01-03 08:39:59 +01:00
parent bb47968626
commit 31c9e758ae
4 changed files with 126 additions and 0 deletions

View File

@ -0,0 +1,40 @@
import { RequestHandler } from "../entities/RequestHandler";
import { MoviesHelper } from "../helpers/MoviesHelper";
import { Movie } from "../entities/Movies";
/**
* Movies controller
*
* @author Pierre HUBERT
*/
export class MoviesController {
/**
* Get the list of movies of the user
*
* @param h Request handler
*/
public static async GetList(h: RequestHandler) {
const list = await MoviesHelper.GetListUser(h.getUserId());
h.send(list.map((m) => this.MovieToAPI(m)));
}
/**
* Turn a movie into an API entry
*
* @param m The movie to convert
*/
private static MovieToAPI(m: Movie): any {
return {
id: m.id,
uri: m.uri,
url: m.url,
userID: m.userID,
name: m.name,
file_type: m.fileType,
size: m.size
}
}
}

View File

@ -10,6 +10,7 @@ import { VirtualDirectoryController } from "./VirtualDirectoryController";
import { WebAppControllers } from "./WebAppController"; import { WebAppControllers } from "./WebAppController";
import { CallsController } from "./CallsController"; import { CallsController } from "./CallsController";
import { FriendsController } from "./FriendsController"; import { FriendsController } from "./FriendsController";
import { MoviesController } from "./MoviesController";
/** /**
* Controllers routes * Controllers routes
@ -190,6 +191,11 @@ export const Routes : Route[] = [
// Movies controller
{path: "/movies/get_list", cb: (h) => MoviesController.GetList(h)},
// Virtual directory controller // Virtual directory controller
{path: "/user/findbyfolder", cb: (h) => VirtualDirectoryController.FindUser(h)}, {path: "/user/findbyfolder", cb: (h) => VirtualDirectoryController.FindUser(h)},

35
src/entities/Movies.ts Normal file
View File

@ -0,0 +1,35 @@
import { pathUserData } from "../utils/UserDataUtils";
/**
* Movie entity
*
* @author Pierre HUBERT
*/
export interface MovieBuilder {
id: number,
userID: number,
name: string,
uri: string,
fileType: string,
size: number
}
export class Movie implements MovieBuilder {
id: number; userID: number;
name: string;
uri: string;
fileType: string;
size: number;
public constructor(info: MovieBuilder) {
for (const key in info) {
if (info.hasOwnProperty(key))
this[key] = info[key];
}
}
get url() : string {
return pathUserData(this.uri);
}
}

View File

@ -0,0 +1,45 @@
import { RequestHandler } from "../entities/RequestHandler";
import { Movie } from "../entities/Movies";
import { DatabaseHelper } from "./DatabaseHelper";
/**
* Legacy movies helper
*
* @author Pierre HUBERT
*/
const MOVIES_TABLE = "galerie_video";
export class MoviesHelper {
/**
* Get the list of movies of the user
*
* @param userID The ID of the target user
*/
public static async GetListUser(userID: number) : Promise<Array<Movie>> {
return (await DatabaseHelper.Query({
table: MOVIES_TABLE,
where: {
ID_user: userID
},
order: "ID DESC"
})).map((row) => this.DBToMovie(row));
}
/**
* Turn a database entry into a movie object
*
* @param row Database entry
*/
private static DBToMovie(row: any) : Movie {
return new Movie({
id: row.ID,
uri: row.URL,
userID: row.ID_user,
name: row.nom_video,
fileType: row.file_type,
size: Number(row.size)
});
}
}