1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-21 00:45:18 +00:00

Deprecate old movies system

This commit is contained in:
2021-02-13 11:12:17 +01:00
parent a6c32d763f
commit 3a22c89b87
16 changed files with 9 additions and 207 deletions

View File

@ -12,7 +12,7 @@ use crate::data::new_account::NewAccount;
use crate::data::security_settings::SecuritySettings;
use crate::data::user::{AccountImageVisibility, User, UserID, UserPageStatus};
use crate::data::user_token::UserAccessToken;
use crate::helpers::{comments_helper, conversations_helper, custom_emojies_helper, database, events_helper, friends_helper, groups_helper, likes_helper, movies_helper, notifications_helper, posts_helper, survey_helper, user_helper};
use crate::helpers::{comments_helper, conversations_helper, custom_emojies_helper, database, events_helper, friends_helper, groups_helper, likes_helper, notifications_helper, posts_helper, survey_helper, user_helper};
use crate::helpers::database::{DeleteQuery, InsertQuery, QueryInfo};
use crate::helpers::events_helper::Event;
use crate::helpers::likes_helper::LikeType;
@ -287,7 +287,6 @@ pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
comments: comments_helper::export_all_user(user_id)?,
likes: likes_helper::export_all_user(user_id)?,
survey_responses: survey_helper::export_all_user_responses(user_id)?,
movies: movies_helper::get_list_user(user_id)?,
all_conversation_messages: conversations_helper::export_all_user_messages(user_id)?,
conversations: conversations_helper::get_list_user(user_id)?,
conversation_messages: Default::default(),
@ -324,9 +323,6 @@ pub fn delete(user_id: &UserID) -> ResultBoxError {
// Delete all the likes created by the user
likes_helper::delete_all_user(user_id)?;
// Delete all user movies
movies_helper::delete_all_user(user_id)?;
// Delete all conversation messages
conversations_helper::delete_all_user_messages(user_id)?;

View File

@ -11,7 +11,6 @@ pub mod groups_helper;
pub mod posts_helper;
pub mod conversations_helper;
pub mod virtual_directory_helper;
pub mod movies_helper;
pub mod survey_helper;
pub mod comments_helper;
pub mod notifications_helper;

View File

@ -1,71 +0,0 @@
//! # Movies helper
//!
//! @author Pierre Hubert
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, posts_helper};
use crate::utils::user_data_utils::user_data_path;
/// Get the list of movies of the current
pub fn get_list_user(user_id: &UserID) -> ResultBoxError<Vec<Movie>> {
database::QueryInfo::new(MOVIES_TABLE)
.cond_user_id("ID_user", user_id)
.set_order("ID DESC")
.exec(db_to_movie)
}
/// Get all movies
pub fn get_all() -> ResultBoxError<Vec<Movie>> {
database::QueryInfo::new(MOVIES_TABLE)
.exec(db_to_movie)
}
/// Get information about a single movie
pub fn get_info(movie_id: u64) -> ResultBoxError<Movie> {
database::QueryInfo::new(MOVIES_TABLE)
.cond_u64("ID", movie_id)
.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))
}
/// Remove permanently a movie from the database
pub fn delete(movie: &Movie) -> ResultBoxError {
posts_helper::delete_all_with_movie(movie)?;
let movie_path = user_data_path(movie.uri.as_ref());
if movie_path.exists() {
std::fs::remove_file(movie_path)?;
}
database::DeleteQuery::new(MOVIES_TABLE)
.cond_u64("ID", movie.id)
.exec()
}
/// Delete all the movies of a user
pub fn delete_all_user(user_id: &UserID) -> ResultBoxError {
for movie in &get_list_user(user_id)? {
delete(movie)?;
}
Ok(())
}
/// Turn a database entry into a movie object
fn db_to_movie(row: &database::RowResult) -> ResultBoxError<Movie> {
Ok(Movie {
id: row.get_u64("ID")?,
user_id: row.get_user_id("ID_user")?,
name: row.get_str("nom_video")?,
uri: row.get_str("URL")?,
file_type: row.get_str("file_type")?,
size: row.get_usize("size")?,
})
}

View File

@ -10,7 +10,7 @@ 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::post::PostKind::{POST_KIND_COUNTDOWN, POST_KIND_IMAGE, POST_KIND_PDF, POST_KIND_SURVEY, POST_KIND_WEBLINK, POST_KIND_YOUTUBE};
use crate::data::user::UserID;
use crate::helpers::{comments_helper, database, friends_helper, groups_helper, likes_helper, notifications_helper, survey_helper, user_helper};
use crate::helpers::likes_helper::LikeType;
@ -45,7 +45,6 @@ impl PostKind {
POST_KIND_IMAGE(_) => "image",
POST_KIND_WEBLINK(_) => "webpage_link",
POST_KIND_PDF(_) => "pdf",
POST_KIND_MOVIE(_) => "video",
POST_KIND_COUNTDOWN(_) => "count_down",
POST_KIND_SURVEY => "sondage",
POST_KIND_YOUTUBE(_) => "youtube",
@ -93,11 +92,6 @@ 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);
}
// Weblink
POST_KIND_WEBLINK(weblink) => {
insert_query = insert_query
@ -540,8 +534,6 @@ fn db_to_post(res: &database::RowResult) -> ResultBoxError<Post> {
"pdf" => post.kind = POST_KIND_PDF(file?),
"video" => post.kind = POST_KIND_MOVIE(res.get_u64("idvideo")?),
"count_down" => post.kind = POST_KIND_COUNTDOWN(res.get_u64("time_end").unwrap_or(0)),
"sondage" => post.kind = POST_KIND_SURVEY,