From 82b1f5e473e7a135017e9dc4b3cc5e3134dd2ce1 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 8 Jul 2020 14:08:54 +0200 Subject: [PATCH] Can create weblink posts --- src/controllers/posts_controller.rs | 17 ++++++++++++++++- src/helpers/posts_helper.rs | 11 +++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/controllers/posts_controller.rs b/src/controllers/posts_controller.rs index 172b5c2..4f75570 100644 --- a/src/controllers/posts_controller.rs +++ b/src/controllers/posts_controller.rs @@ -9,7 +9,7 @@ use crate::controllers::routes::RequestResult; use crate::data::error::{ExecError, ResultBoxError}; use crate::data::group::GroupAccessLevel; use crate::data::http_request_handler::HttpRequestHandler; -use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel}; +use crate::data::post::{Post, PostAccessLevel, PostFile, PostKind, PostPageKind, PostVisibilityLevel, PostWebLink}; use crate::helpers::{groups_helper, posts_helper, user_helper}; use crate::utils::date_utils::time; use crate::utils::string_utils::{check_string_before_insert, check_youtube_id}; @@ -159,6 +159,21 @@ pub fn create_post(r: &mut HttpRequestHandler) -> RequestResult { PostKind::POST_KIND_MOVIE(movie_id) } + // Weblink posts + "weblink" => { + let url = r.post_url_opt("url", true)? + .ok_or(ExecError::new("Missing url!"))?; + + // For now, for safety, we do not fetch page content + // But this might change in the future + PostKind::POST_KIND_WEBLINK(PostWebLink { + url, + title: None, + description: None, + image: None, + }) + } + // TODO : add support for next types _ => { diff --git a/src/helpers/posts_helper.rs b/src/helpers/posts_helper.rs index a8799d7..da400cc 100644 --- a/src/helpers/posts_helper.rs +++ b/src/helpers/posts_helper.rs @@ -95,10 +95,17 @@ pub fn create(p: &Post) -> ResultBoxError { insert_query = insert_query.add_u64("idvideo", *id); } + // Weblink + POST_KIND_WEBLINK(weblink) => { + insert_query = insert_query + .add_str("url_page", &weblink.url) + .add_opt_str("titre_page", weblink.title.as_ref()) + .add_opt_str("description_page", weblink.description.as_ref()) + .add_opt_str("image_page", weblink.image.as_ref()); + } + _ => unimplemented!() /* - POST_KIND_WEBLINK(_) => {}, - POST_KIND_MOVIE(_) => {}, POST_KIND_COUNTDOWN(_) => {}, POST_KIND_SURVEY => {}, */