1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 13:29:21 +00:00

Can create weblink posts

This commit is contained in:
Pierre HUBERT 2020-07-08 14:08:54 +02:00
parent aafd4c5e7c
commit 82b1f5e473
2 changed files with 25 additions and 3 deletions

View File

@ -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
_ => {

View File

@ -95,10 +95,17 @@ pub fn create(p: &Post) -> ResultBoxError<u64> {
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 => {},
*/