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()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,9 @@ use axum::{
|
|||
routing::{delete, get, post},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use tetratto_core::model::journal::{JournalPageReadAccess, JournalPageWriteAccess};
|
||||
use tetratto_core::model::journal::{
|
||||
JournalEntryContext, JournalPageReadAccess, JournalPageWriteAccess,
|
||||
};
|
||||
|
||||
pub fn routes() -> Router {
|
||||
Router::new()
|
||||
|
@ -36,6 +38,10 @@ pub fn routes() -> Router {
|
|||
"/entries/{id}/content",
|
||||
post(journal::entries::update_content_request),
|
||||
)
|
||||
.route(
|
||||
"/entries/{id}/context",
|
||||
post(journal::entries::update_context_request),
|
||||
)
|
||||
// auth
|
||||
// global
|
||||
.route("/auth/register", post(auth::register_request))
|
||||
|
@ -102,3 +108,8 @@ pub struct CreateJournalEntry {
|
|||
pub struct UpdateJournalEntryContent {
|
||||
pub content: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateJournalEntryContext {
|
||||
pub context: JournalEntryContext,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue