mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 16:35:17 +00:00
Add support for movie posts
This commit is contained in:
@ -30,4 +30,5 @@ pub mod res_change_group_logo;
|
||||
pub mod group_member_api;
|
||||
pub mod friend_api;
|
||||
pub mod friendship_status_api;
|
||||
pub mod post_api;
|
||||
pub mod post_api;
|
||||
pub mod movie_api;
|
34
src/api_data/movie_api.rs
Normal file
34
src/api_data/movie_api.rs
Normal file
@ -0,0 +1,34 @@
|
||||
//! # Movie API information
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::data::movie::Movie;
|
||||
use crate::utils::user_data_utils::user_data_url;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
pub struct MovieAPI {
|
||||
id: u64,
|
||||
uri: String,
|
||||
url: String,
|
||||
userID: u64,
|
||||
name: String,
|
||||
file_type: String,
|
||||
size: usize,
|
||||
}
|
||||
|
||||
impl MovieAPI {
|
||||
/// Construct a new instance of movie
|
||||
pub fn new(m: &Movie) -> MovieAPI {
|
||||
MovieAPI {
|
||||
id: m.id,
|
||||
uri: m.uri.clone(),
|
||||
url: user_data_url(m.uri.as_str()),
|
||||
userID: m.user_id.id(),
|
||||
name: m.name.clone(),
|
||||
file_type: m.file_type.clone(),
|
||||
size: m.size,
|
||||
}
|
||||
}
|
||||
}
|
@ -3,8 +3,11 @@
|
||||
//! @author Pierre Hubert
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::api_data::movie_api::MovieAPI;
|
||||
use crate::data::error::ResultBoxError;
|
||||
use crate::data::post::{Post, PostKind};
|
||||
use crate::data::user::UserID;
|
||||
use crate::helpers::movies_helper;
|
||||
use crate::utils::user_data_utils::user_data_url;
|
||||
|
||||
#[derive(Serialize)]
|
||||
@ -30,11 +33,15 @@ pub struct PostAPI {
|
||||
link_title: Option<String>,
|
||||
link_description: Option<String>,
|
||||
link_image: Option<String>,
|
||||
|
||||
// Movie specific
|
||||
video_id: Option<u64>,
|
||||
video_info: Option<MovieAPI>,
|
||||
}
|
||||
|
||||
impl PostAPI {
|
||||
/// Turn a `Post` entry into an API entry
|
||||
pub fn new(p: &Post) -> PostAPI {
|
||||
pub fn new(p: &Post) -> ResultBoxError<PostAPI> {
|
||||
let mut post = PostAPI {
|
||||
ID: p.id,
|
||||
userID: p.user_id.id(),
|
||||
@ -56,6 +63,10 @@ impl PostAPI {
|
||||
link_title: None,
|
||||
link_description: None,
|
||||
link_image: None,
|
||||
|
||||
// Movie specific
|
||||
video_id: None,
|
||||
video_info: None,
|
||||
};
|
||||
|
||||
match &p.kind {
|
||||
@ -75,17 +86,21 @@ impl PostAPI {
|
||||
post.link_image = link.image.clone();
|
||||
}
|
||||
|
||||
PostKind::POST_KIND_MOVIE => {}
|
||||
PostKind::POST_KIND_MOVIE(movie_id) => {
|
||||
post.video_id = Some(*movie_id);
|
||||
post.video_info = Some(MovieAPI::new(&movies_helper::get_info(*movie_id)?))
|
||||
}
|
||||
|
||||
PostKind::POST_KIND_COUNTDOWN => {}
|
||||
PostKind::POST_KIND_SURVEY => {}
|
||||
PostKind::POST_KIND_YOUTUBE => {}
|
||||
}
|
||||
|
||||
post
|
||||
Ok(post)
|
||||
}
|
||||
|
||||
/// Turn a list of posts into an API entry
|
||||
pub fn for_list(l: &Vec<Post>) -> Vec<PostAPI> {
|
||||
pub fn for_list(l: &Vec<Post>) -> ResultBoxError<Vec<PostAPI>> {
|
||||
l.iter().map(Self::new).collect()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user