1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Can create movie posts

This commit is contained in:
Pierre HUBERT 2020-07-08 14:01:40 +02:00
parent 45c70cb40e
commit aafd4c5e7c
4 changed files with 30 additions and 1 deletions

View File

@ -141,6 +141,7 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
PostKind::POST_KIND_IMAGE(PostFile::new_from_created_file(&path)?)
}
// YouTube posts
"youtube" => {
let youtube = r.post_string("youtube_id")?;
@ -151,6 +152,13 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
PostKind::POST_KIND_YOUTUBE(youtube)
}
// Movies posts
"movie" => {
let movie_id = r.post_movie_id("movieID")?;
PostKind::POST_KIND_MOVIE(movie_id)
}
// TODO : add support for next types
_ => {

View File

@ -18,7 +18,7 @@ use crate::data::group::GroupAccessLevel;
use crate::data::group_id::GroupID;
use crate::data::post::{Post, PostAccessLevel};
use crate::data::user::UserID;
use crate::helpers::{account_helper, api_helper, conversations_helper, friends_helper, groups_helper, posts_helper, user_helper, virtual_directory_helper};
use crate::helpers::{account_helper, api_helper, conversations_helper, friends_helper, groups_helper, movies_helper, posts_helper, user_helper, virtual_directory_helper};
use crate::helpers::virtual_directory_helper::VirtualDirType;
use crate::utils::string_utils::{check_url, remove_html_nodes};
use crate::utils::user_data_utils::{generate_new_user_data_file_name, prepare_file_creation, user_data_path};
@ -561,4 +561,15 @@ impl HttpRequestHandler {
Ok(post)
}
/// Get the ID of a movie included in the request
pub fn post_movie_id(&mut self, name: &str) -> ResultBoxError<u64> {
let movie_id = self.post_u64(name)?;
if !movies_helper::does_user_has(self.user_id_ref()?, movie_id)? {
self.forbidden("You are not authorized to use this movie!".to_string())?;
}
Ok(movie_id)
}
}

View File

@ -23,6 +23,11 @@ pub fn get_info(movie_id: u64) -> ResultBoxError<Movie> {
.query_row(db_to_movie)
}
/// Check out whether a user own a movie or not
pub fn does_user_has(user_id: &UserID, movie_id: u64) -> ResultBoxError<bool> {
Ok(get_info(movie_id).map(|m| &m.user_id == user_id).unwrap_or(false))
}
/// Turn a database entry into a movie object
fn db_to_movie(row: &database::RowResult) -> ResultBoxError<Movie> {
Ok(Movie {

View File

@ -90,6 +90,11 @@ pub fn create(p: &Post) -> ResultBoxError<u64> {
.add_str("type", "youtube");
}
// Movie post
POST_KIND_MOVIE(id) => {
insert_query = insert_query.add_u64("idvideo", *id);
}
_ => unimplemented!()
/*
POST_KIND_WEBLINK(_) => {},