From 532bd9e48d6b89c849b19d7855f256143ac35b5a Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 4 Jul 2020 17:06:06 +0200 Subject: [PATCH] Add YouTube posts support --- src/api_data/post_api.rs | 5 ++++- src/data/post.rs | 4 ++-- src/helpers/posts_helper.rs | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/api_data/post_api.rs b/src/api_data/post_api.rs index e39b71a..9e24173 100644 --- a/src/api_data/post_api.rs +++ b/src/api_data/post_api.rs @@ -109,7 +109,10 @@ impl PostAPI { PostKind::POST_KIND_SURVEY => post.data_survey = Some(SurveyAPI::new(&survey_helper::get_info(p.id)?, user.clone())?), - PostKind::POST_KIND_YOUTUBE => {} + PostKind::POST_KIND_YOUTUBE(id) => { + post.file_path = Some(id.clone()); + post.file_type = Some("youtube".to_string()); + } } Ok(post) diff --git a/src/data/post.rs b/src/data/post.rs index f44c1b6..32dca15 100644 --- a/src/data/post.rs +++ b/src/data/post.rs @@ -61,7 +61,7 @@ pub enum PostKind { POST_KIND_COUNTDOWN(u64), // End time POST_KIND_SURVEY, - POST_KIND_YOUTUBE, + POST_KIND_YOUTUBE(String), } impl PostKind { @@ -74,7 +74,7 @@ impl PostKind { PostKind::POST_KIND_MOVIE(_) => "movie", PostKind::POST_KIND_COUNTDOWN(_) => "countdown", PostKind::POST_KIND_SURVEY => "survey", - PostKind::POST_KIND_YOUTUBE => "youtube", + PostKind::POST_KIND_YOUTUBE(_) => "youtube", }.to_string() } } diff --git a/src/helpers/posts_helper.rs b/src/helpers/posts_helper.rs index e1d5146..85727f4 100644 --- a/src/helpers/posts_helper.rs +++ b/src/helpers/posts_helper.rs @@ -5,7 +5,7 @@ use crate::constants::database_tables_names::POSTS_TABLE; use crate::data::error::{ExecError, ResultBoxError}; use crate::data::post::{Post, 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}; +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; use crate::helpers::{database, friends_helper}; use crate::utils::date_utils::time; @@ -176,6 +176,8 @@ fn db_to_post(res: &database::RowResult) -> ResultBoxError { "sondage" => post.kind = POST_KIND_SURVEY, + "youtube" => post.kind = POST_KIND_YOUTUBE(res.get_str("path")?), + _ => {} }