mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Can get the list of movies of the user
This commit is contained in:
parent
bb47968626
commit
31c9e758ae
40
src/controllers/MoviesController.ts
Normal file
40
src/controllers/MoviesController.ts
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ import { VirtualDirectoryController } from "./VirtualDirectoryController";
|
||||
import { WebAppControllers } from "./WebAppController";
|
||||
import { CallsController } from "./CallsController";
|
||||
import { FriendsController } from "./FriendsController";
|
||||
import { MoviesController } from "./MoviesController";
|
||||
|
||||
/**
|
||||
* Controllers routes
|
||||
@ -190,6 +191,11 @@ export const Routes : Route[] = [
|
||||
|
||||
|
||||
|
||||
// Movies controller
|
||||
{path: "/movies/get_list", cb: (h) => MoviesController.GetList(h)},
|
||||
|
||||
|
||||
|
||||
// Virtual directory controller
|
||||
{path: "/user/findbyfolder", cb: (h) => VirtualDirectoryController.FindUser(h)},
|
||||
|
||||
|
35
src/entities/Movies.ts
Normal file
35
src/entities/Movies.ts
Normal 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);
|
||||
}
|
||||
}
|
45
src/helpers/MoviesHelper.ts
Normal file
45
src/helpers/MoviesHelper.ts
Normal 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)
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user