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

Return information about a single movie

This commit is contained in:
Pierre HUBERT 2020-01-03 10:24:05 +01:00
parent 87daf8acbe
commit f18a0952d6
3 changed files with 30 additions and 3 deletions

View File

@ -26,7 +26,7 @@ export class MoviesController {
* *
* @param m The movie to convert * @param m The movie to convert
*/ */
private static MovieToAPI(m: Movie): any { public static MovieToAPI(m: Movie): any {
return { return {
id: m.id, id: m.id,
uri: m.uri, uri: m.uri,

View File

@ -1,7 +1,9 @@
import { RequestHandler } from "../entities/RequestHandler"; import { RequestHandler } from "../entities/RequestHandler";
import { UserHelper } from "../helpers/UserHelper"; import { UserHelper } from "../helpers/UserHelper";
import { PostsHelper } from "../helpers/PostsHelper"; 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 * Posts controller
@ -60,7 +62,13 @@ export class PostsController {
file_size: !p.hasFile ? null : p.file.size, file_size: !p.hasFile ? null : p.file.size,
file_type: !p.hasFile ? null : p.file.type, file_type: !p.hasFile ? null : p.file.type,
file_path: !p.hasFile ? null : p.file.path, 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; return data;

View File

@ -27,6 +27,25 @@ export class MoviesHelper {
})).map((row) => this.DBToMovie(row)); })).map((row) => this.DBToMovie(row));
} }
/**
* Get information about a single movie
*
* @param movieID The movie to get
*/
public static async GetInfo(movieID: number) : Promise<Movie> {
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 * Turn a database entry into a movie object
* *