Simplify web API (put ids in url)
This commit is contained in:
parent
0c43935bef
commit
6e017e41a3
14 changed files with 403 additions and 588 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use axum::{
|
||||
debug_handler,
|
||||
extract::{Extension, Query, State},
|
||||
extract::{Extension, Path, Query, State},
|
||||
http::{HeaderMap, StatusCode},
|
||||
response::{IntoResponse, Result},
|
||||
};
|
||||
|
|
@ -25,14 +25,14 @@ pub async fn set_lang(
|
|||
State(connection): State<db::Connection>,
|
||||
Extension(context): Extension<Context>,
|
||||
headers: HeaderMap,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::SetLang>,
|
||||
ExtractRon(lang): ExtractRon<String>,
|
||||
) -> Result<(CookieJar, StatusCode)> {
|
||||
let mut jar = CookieJar::from_headers(&headers);
|
||||
if let Some(user) = context.user {
|
||||
connection.set_user_lang(user.id, &ron.lang).await?;
|
||||
connection.set_user_lang(user.id, &lang).await?;
|
||||
} else {
|
||||
// Only set the cookie if the user is not connected.
|
||||
let cookie = Cookie::build((consts::COOKIE_LANG_NAME, ron.lang))
|
||||
let cookie = Cookie::build((consts::COOKIE_LANG_NAME, lang))
|
||||
.same_site(SameSite::Lax)
|
||||
.path("/");
|
||||
jar = jar.add(cookie);
|
||||
|
|
@ -43,11 +43,9 @@ pub async fn set_lang(
|
|||
#[debug_handler]
|
||||
pub async fn get_translation(
|
||||
Extension(context): Extension<Context>,
|
||||
translation_id: Query<ron_api::Id>,
|
||||
Path(id): Path<i64>,
|
||||
) -> Result<impl IntoResponse> {
|
||||
Ok(ron_response_ok(ron_api::Value {
|
||||
value: context.tr.t_from_id(translation_id.id),
|
||||
}))
|
||||
Ok(ron_response_ok(context.tr.t_from_id(id)))
|
||||
}
|
||||
|
||||
/*** 404 ***/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue