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 *