add: journal entry context
This commit is contained in:
parent
e87ad74d43
commit
1a6b48078a
5 changed files with 57 additions and 3 deletions
|
@ -4,7 +4,7 @@ use tetratto_core::model::{ApiReturn, Error, journal::JournalEntry};
|
|||
|
||||
use crate::{
|
||||
State, get_user_from_token,
|
||||
routes::api::v1::{CreateJournalEntry, UpdateJournalEntryContent},
|
||||
routes::api::v1::{CreateJournalEntry, UpdateJournalEntryContent, UpdateJournalEntryContext},
|
||||
};
|
||||
|
||||
pub async fn create_request(
|
||||
|
@ -73,3 +73,25 @@ pub async fn update_content_request(
|
|||
Err(e) => return Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn update_context_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
Json(req): Json<UpdateJournalEntryContext>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.update_entry_context(id, user, req.context).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Entry updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => return Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue