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:
parent
45c70cb40e
commit
aafd4c5e7c
@ -141,6 +141,7 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
PostKind::POST_KIND_IMAGE(PostFile::new_from_created_file(&path)?)
|
PostKind::POST_KIND_IMAGE(PostFile::new_from_created_file(&path)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// YouTube posts
|
||||||
"youtube" => {
|
"youtube" => {
|
||||||
let youtube = r.post_string("youtube_id")?;
|
let youtube = r.post_string("youtube_id")?;
|
||||||
|
|
||||||
@ -151,6 +152,13 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult {
|
|||||||
PostKind::POST_KIND_YOUTUBE(youtube)
|
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
|
// TODO : add support for next types
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -18,7 +18,7 @@ use crate::data::group::GroupAccessLevel;
|
|||||||
use crate::data::group_id::GroupID;
|
use crate::data::group_id::GroupID;
|
||||||
use crate::data::post::{Post, PostAccessLevel};
|
use crate::data::post::{Post, PostAccessLevel};
|
||||||
use crate::data::user::UserID;
|
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::helpers::virtual_directory_helper::VirtualDirType;
|
||||||
use crate::utils::string_utils::{check_url, remove_html_nodes};
|
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};
|
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)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
@ -23,6 +23,11 @@ pub fn get_info(movie_id: u64) -> ResultBoxError<Movie> {
|
|||||||
.query_row(db_to_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
|
/// Turn a database entry into a movie object
|
||||||
fn db_to_movie(row: &database::RowResult) -> ResultBoxError<Movie> {
|
fn db_to_movie(row: &database::RowResult) -> ResultBoxError<Movie> {
|
||||||
Ok(Movie {
|
Ok(Movie {
|
||||||
|
@ -90,6 +90,11 @@ pub fn create(p: &Post) -> ResultBoxError<u64> {
|
|||||||
.add_str("type", "youtube");
|
.add_str("type", "youtube");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Movie post
|
||||||
|
POST_KIND_MOVIE(id) => {
|
||||||
|
insert_query = insert_query.add_u64("idvideo", *id);
|
||||||
|
}
|
||||||
|
|
||||||
_ => unimplemented!()
|
_ => unimplemented!()
|
||||||
/*
|
/*
|
||||||
POST_KIND_WEBLINK(_) => {},
|
POST_KIND_WEBLINK(_) => {},
|
||||||
|
Loading…
Reference in New Issue
Block a user