mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-30 01:06:27 +00:00
Can delete all the posts associated to a movie
This commit is contained in:
parent
ead879bc21
commit
2cc8e7da04
@ -4,7 +4,6 @@
|
||||
|
||||
use crate::api_data::movie_api::MovieAPI;
|
||||
use crate::controllers::routes::RequestResult;
|
||||
use crate::data::error::ExecError;
|
||||
use crate::data::http_request_handler::HttpRequestHandler;
|
||||
use crate::helpers::movies_helper;
|
||||
|
||||
@ -17,6 +16,9 @@ pub fn get_list(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
|
||||
/// Remove a movie
|
||||
pub fn delete(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
// TODO : implement method
|
||||
r.internal_error(ExecError::boxed_new("Unimplemented method!"))
|
||||
let movie_id = r.post_movie_id("movieID")?;
|
||||
|
||||
movies_helper::delete(&movies_helper::get_info(movie_id)?)?;
|
||||
|
||||
r.success("Movie deleted.")
|
||||
}
|
@ -6,7 +6,7 @@ use crate::constants::database_tables_names::MOVIES_TABLE;
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::data::movie::Movie;
|
||||
use crate::data::user::UserID;
|
||||
use crate::helpers::database;
|
||||
use crate::helpers::{database, posts_helper};
|
||||
|
||||
/// Get the list of movies of the current
|
||||
pub fn get_list_user(user_id: &UserID) -> ResultBoxError<Vec<Movie>> {
|
||||
@ -28,6 +28,15 @@ 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))
|
||||
}
|
||||
|
||||
/// Remove permanently a movie from the database
|
||||
pub fn delete(movie: &Movie) -> ResultBoxError {
|
||||
posts_helper::delete_all_with_movie(movie)?;
|
||||
|
||||
// TODO : continue implementation
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Turn a database entry into a movie object
|
||||
fn db_to_movie(row: &database::RowResult) -> ResultBoxError<Movie> {
|
||||
Ok(Movie {
|
||||
|
@ -8,6 +8,7 @@ use crate::constants::database_tables_names::POSTS_TABLE;
|
||||
use crate::data::error::{ExecError, ResultBoxError};
|
||||
use crate::data::group_id::GroupID;
|
||||
use crate::data::group_member::GroupMembershipLevel;
|
||||
use crate::data::movie::Movie;
|
||||
use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel, PostWebLink};
|
||||
use crate::data::post::PostKind::{POST_KIND_COUNTDOWN, POST_KIND_IMAGE, POST_KIND_MOVIE, POST_KIND_PDF, POST_KIND_SURVEY, POST_KIND_WEBLINK, POST_KIND_YOUTUBE};
|
||||
use crate::data::user::UserID;
|
||||
@ -440,6 +441,22 @@ pub fn delete(p: &Post) -> ResultBoxError {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get all the posts that use of movie
|
||||
pub fn get_posts_for_movie(m: &Movie) -> ResultBoxError<Vec<Post>> {
|
||||
database::QueryInfo::new(POSTS_TABLE)
|
||||
.cond_u64("idvideo", m.id)
|
||||
.exec(db_to_post)
|
||||
}
|
||||
|
||||
/// Delete all the posts associated with a movie
|
||||
pub fn delete_all_with_movie(m: &Movie) -> ResultBoxError {
|
||||
for post in get_posts_for_movie(m)? {
|
||||
delete(&post)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Turn a post into a database entry
|
||||
fn db_to_post(res: &database::RowResult) -> ResultBoxError<Post> {
|
||||
let user_id = if res.get_u64("ID_amis")? == 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user