Add a route to get the list of inbox entries
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::connections::db_connection::db;
|
||||
use crate::controllers::server_controller::ServerConstraints;
|
||||
use crate::models::files::FileID;
|
||||
use crate::models::inbox::{Inbox, InboxID, NewInboxEntry};
|
||||
use crate::models::inbox::{InboxEntry, InboxID, NewInboxEntry};
|
||||
use crate::models::movements::MovementID;
|
||||
use crate::models::users::UserID;
|
||||
use crate::schema::inbox;
|
||||
@@ -55,7 +55,7 @@ impl UpdateInboxEntryQuery {
|
||||
}
|
||||
|
||||
/// Create a new inbox entry
|
||||
pub async fn create(user_id: UserID, query: &UpdateInboxEntryQuery) -> anyhow::Result<Inbox> {
|
||||
pub async fn create(user_id: UserID, query: &UpdateInboxEntryQuery) -> anyhow::Result<InboxEntry> {
|
||||
let new_entry = NewInboxEntry {
|
||||
time: query.time as i64,
|
||||
label: query.label.as_deref(),
|
||||
@@ -67,7 +67,7 @@ pub async fn create(user_id: UserID, query: &UpdateInboxEntryQuery) -> anyhow::R
|
||||
movement_id: None,
|
||||
};
|
||||
|
||||
let res: Inbox = diesel::insert_into(inbox::table)
|
||||
let res: InboxEntry = diesel::insert_into(inbox::table)
|
||||
.values(&new_entry)
|
||||
.get_result(&mut db()?)?;
|
||||
|
||||
@@ -91,3 +91,10 @@ pub async fn update(id: InboxID, q: &UpdateInboxEntryQuery) -> anyhow::Result<()
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Get the full list of inbox entries of a user
|
||||
pub async fn get_list_user(user_id: UserID) -> anyhow::Result<Vec<InboxEntry>> {
|
||||
Ok(inbox::table
|
||||
.filter(inbox::dsl::user_id.eq(user_id.0))
|
||||
.get_results(&mut db()?)?)
|
||||
}
|
||||
|
Reference in New Issue
Block a user