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

Add post with weblink support

This commit is contained in:
Pierre HUBERT 2020-07-03 10:18:26 +02:00
parent a359b6656f
commit 689cf07ee4
3 changed files with 45 additions and 11 deletions

View File

@ -24,6 +24,12 @@ pub struct PostAPI {
file_type: Option<String>,
file_path: Option<String>,
file_path_url: Option<String>,
// Weblink specific
link_url: Option<String>,
link_title: Option<String>,
link_description: Option<String>,
link_image: Option<String>,
}
impl PostAPI {
@ -44,17 +50,31 @@ impl PostAPI {
file_type: None,
file_path: None,
file_path_url: None,
// Weblink specific
link_url: None,
link_title: None,
link_description: None,
link_image: None,
};
match &p.kind {
PostKind::POST_KIND_TEXT => { /* do nothing */ }
PostKind::POST_KIND_IMAGE(file) => {
post.file_size = Option::from(file.size);
post.file_type = file.file_type.clone();
post.file_path = Some(file.path.clone());
post.file_path_url = Some(user_data_url(file.path.as_ref()))
}
PostKind::POST_KIND_WEBLINK => {}
PostKind::POST_KIND_WEBLINK(link) => {
post.link_url = Some(link.url.clone());
post.link_description = link.description.clone();
post.link_title = link.title.clone();
post.link_image = link.image.clone();
}
PostKind::POST_KIND_PDF => {}
PostKind::POST_KIND_MOVIE => {}
PostKind::POST_KIND_COUNTDOWN => {}

View File

@ -37,11 +37,24 @@ pub enum PostPageKind {
PAGE_KIND_GROUP(GroupID),
}
pub struct PostFile {
pub path: String,
pub size: usize,
pub file_type: Option<String>,
}
pub struct PostWebLink {
pub url: String,
pub title: Option<String>,
pub description: Option<String>,
pub image: Option<String>,
}
#[allow(non_camel_case_types)]
pub enum PostKind {
POST_KIND_TEXT,
POST_KIND_IMAGE(PostFile),
POST_KIND_WEBLINK,
POST_KIND_WEBLINK(PostWebLink),
POST_KIND_PDF,
POST_KIND_MOVIE,
POST_KIND_COUNTDOWN,
@ -54,7 +67,7 @@ impl PostKind {
match self {
PostKind::POST_KIND_TEXT => "text",
PostKind::POST_KIND_IMAGE(_) => "image",
PostKind::POST_KIND_WEBLINK => "weblink",
PostKind::POST_KIND_WEBLINK(_) => "weblink",
PostKind::POST_KIND_PDF => "pdf",
PostKind::POST_KIND_MOVIE => "movie",
PostKind::POST_KIND_COUNTDOWN => "countdown",
@ -64,12 +77,6 @@ impl PostKind {
}
}
pub struct PostFile {
pub path: String,
pub size: usize,
pub file_type: Option<String>,
}
pub struct Post {
pub id: u64,
pub user_id: UserID,

View File

@ -4,8 +4,8 @@
use crate::constants::database_tables_names::POSTS_TABLE;
use crate::data::error::{ExecError, ResultBoxError};
use crate::data::post::{Post, PostFile, PostKind, PostPageKind, PostVisibilityLevel};
use crate::data::post::PostKind::POST_KIND_IMAGE;
use crate::data::post::{Post, PostFile, PostKind, PostPageKind, PostVisibilityLevel, PostWebLink};
use crate::data::post::PostKind::{POST_KIND_IMAGE, POST_KIND_WEBLINK};
use crate::data::user::UserID;
use crate::helpers::{database, friends_helper};
use crate::utils::date_utils::time;
@ -161,6 +161,13 @@ fn db_to_post(res: &database::RowResult) -> ResultBoxError<Post> {
match res.get_str("type")?.as_str() {
"image" => post.kind = POST_KIND_IMAGE(file?),
"webpage_link" => post.kind = POST_KIND_WEBLINK(PostWebLink {
url: res.get_str("url_page")?,
title: res.get_optional_str("titre_page")?,
description: res.get_optional_str("description_page")?,
image: res.get_optional_str("image_page")?,
}),
_ => {}
}