add: journals + notes
This commit is contained in:
parent
c08a26ae8d
commit
c1568ad866
26 changed files with 1431 additions and 265 deletions
|
@ -6,7 +6,7 @@ use axum::{
|
|||
use axum_extra::extract::CookieJar;
|
||||
use crate::{
|
||||
get_user_from_token,
|
||||
routes::api::v1::{UpdateJournalView, CreateJournal, UpdateJournalTitle},
|
||||
routes::api::v1::{UpdateJournalPrivacy, CreateJournal, UpdateJournalTitle},
|
||||
State,
|
||||
};
|
||||
use tetratto_core::model::{
|
||||
|
@ -81,7 +81,7 @@ pub async fn create_request(
|
|||
Ok(x) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Journal created".to_string(),
|
||||
payload: Some(x),
|
||||
payload: Some(x.id.to_string()),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ pub async fn update_title_request(
|
|||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
Extension(data): Extension<State>,
|
||||
Json(props): Json<UpdateJournalTitle>,
|
||||
Json(mut props): Json<UpdateJournalTitle>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserManageJournals) {
|
||||
|
@ -99,6 +99,18 @@ pub async fn update_title_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
props.title = props.title.replace(" ", "_");
|
||||
|
||||
// make sure this title isn't already in use
|
||||
if data
|
||||
.get_journal_by_owner_title(user.id, &props.title)
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
return Json(Error::TitleInUse.into());
|
||||
}
|
||||
|
||||
// ...
|
||||
match data.update_journal_title(id, &user, &props.title).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
|
@ -113,7 +125,7 @@ pub async fn update_privacy_request(
|
|||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
Extension(data): Extension<State>,
|
||||
Json(props): Json<UpdateJournalView>,
|
||||
Json(props): Json<UpdateJournalPrivacy>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserManageJournals) {
|
||||
|
@ -121,7 +133,7 @@ pub async fn update_privacy_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data.update_journal_privacy(id, &user, props.view).await {
|
||||
match data.update_journal_privacy(id, &user, props.privacy).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Journal updated".to_string(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue