From f18a0952d68e9bca1d003c36a13145c0093b4fc6 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 3 Jan 2020 10:24:05 +0100 Subject: [PATCH] Return information about a single movie --- src/controllers/MoviesController.ts | 2 +- src/controllers/PostsController.ts | 12 ++++++++++-- src/helpers/MoviesHelper.ts | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/controllers/MoviesController.ts b/src/controllers/MoviesController.ts index fc045f4..b27bb6f 100644 --- a/src/controllers/MoviesController.ts +++ b/src/controllers/MoviesController.ts @@ -26,7 +26,7 @@ export class MoviesController { * * @param m The movie to convert */ - private static MovieToAPI(m: Movie): any { + public static MovieToAPI(m: Movie): any { return { id: m.id, uri: m.uri, diff --git a/src/controllers/PostsController.ts b/src/controllers/PostsController.ts index 6297ae9..ae3ff2e 100644 --- a/src/controllers/PostsController.ts +++ b/src/controllers/PostsController.ts @@ -1,7 +1,9 @@ import { RequestHandler } from "../entities/RequestHandler"; import { UserHelper } from "../helpers/UserHelper"; import { PostsHelper } from "../helpers/PostsHelper"; -import { Post, PostVisibilityLevel } from "../entities/Post"; +import { Post, PostVisibilityLevel, PostKind } from "../entities/Post"; +import { MoviesController } from "./MoviesController"; +import { MoviesHelper } from "../helpers/MoviesHelper"; /** * Posts controller @@ -60,7 +62,13 @@ export class PostsController { file_size: !p.hasFile ? null : p.file.size, file_type: !p.hasFile ? null : p.file.type, file_path: !p.hasFile ? null : p.file.path, - file_url: !p.hasFile ? null : p.file.url + file_url: !p.hasFile ? null : p.file.url, + + + // Movie specific + video_id: p.kind == PostKind.POST_KIND_MOVIE ? p.movieID : null, + video_info: p.kind == PostKind.POST_KIND_MOVIE ? + MoviesController.MovieToAPI(await MoviesHelper.GetInfo(p.movieID)) : null }; return data; diff --git a/src/helpers/MoviesHelper.ts b/src/helpers/MoviesHelper.ts index 7e23e48..ac738fc 100644 --- a/src/helpers/MoviesHelper.ts +++ b/src/helpers/MoviesHelper.ts @@ -27,6 +27,25 @@ export class MoviesHelper { })).map((row) => this.DBToMovie(row)); } + /** + * Get information about a single movie + * + * @param movieID The movie to get + */ + public static async GetInfo(movieID: number) : Promise { + const row = await DatabaseHelper.QueryRow({ + table: MOVIES_TABLE, + where: { + ID: movieID + } + }); + + if(row == null) + throw Error("Movie " + movieID + " could not be found!"); + + return this.DBToMovie(row); + } + /** * Turn a database entry into a movie object *