mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-21 00:45:18 +00:00
Can create post images
This commit is contained in:
@ -555,6 +555,11 @@ impl InsertQuery {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_usize(mut self, key: &str, value: usize) -> InsertQuery {
|
||||
self.values.insert(key.to_string(), Value::from(value));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_u32(mut self, key: &str, value: u32) -> InsertQuery {
|
||||
self.values.insert(key.to_string(), Value::from(value));
|
||||
self
|
||||
|
@ -64,7 +64,7 @@ pub fn create(p: &Post) -> ResultBoxError<u64> {
|
||||
};
|
||||
|
||||
// Start insert query
|
||||
let insert_query = database::InsertQuery::new(POSTS_TABLE)
|
||||
let mut insert_query = database::InsertQuery::new(POSTS_TABLE)
|
||||
.add_user_id("ID_personne", user_id)
|
||||
.add_u64("ID_amis", friend_id.map(|f| f.id()).unwrap_or(0))
|
||||
.add_u64("group_id", group_id.map(|f| f.id()).unwrap_or(0))
|
||||
@ -74,6 +74,26 @@ pub fn create(p: &Post) -> ResultBoxError<u64> {
|
||||
.add_str("type", &p.kind.to_db())
|
||||
.add_opt_str("texte", p.content.as_ref());
|
||||
|
||||
match &p.kind {
|
||||
PostKind::POST_KIND_TEXT => {/* nothing to do */},
|
||||
|
||||
// Posts with associated file
|
||||
POST_KIND_IMAGE(file) | POST_KIND_PDF(file) => {
|
||||
insert_query = insert_query.add_str("path", &file.path)
|
||||
.add_usize("size", file.size)
|
||||
.add_opt_str("file_type", file.file_type.as_ref());
|
||||
}
|
||||
|
||||
|
||||
_ => unimplemented!()
|
||||
/*
|
||||
POST_KIND_WEBLINK(_) => {},
|
||||
POST_KIND_MOVIE(_) => {},
|
||||
POST_KIND_COUNTDOWN(_) => {},
|
||||
POST_KIND_SURVEY => {},
|
||||
POST_KIND_YOUTUBE(_) => {},*/
|
||||
}
|
||||
|
||||
// Execute insertion
|
||||
let post_id = insert_query.insert()?
|
||||
.ok_or(ExecError::new("Insert post query did not return a result!"))?;
|
||||
|
Reference in New Issue
Block a user