107 lines
2.9 KiB
Rust
107 lines
2.9 KiB
Rust
use super::render_error;
|
|
use crate::{
|
|
assets::initial_context, get_lang, get_user_from_token, State, routes::pages::PaginatedQuery,
|
|
};
|
|
use axum::{
|
|
extract::Query,
|
|
response::{Html, IntoResponse},
|
|
Extension,
|
|
};
|
|
use crate::cookie::CookieJar;
|
|
use tetratto_core::model::Error;
|
|
|
|
/// `/settings/seller`
|
|
pub async fn seller_settings_request(
|
|
jar: CookieJar,
|
|
Extension(data): Extension<State>,
|
|
Query(props): Query<PaginatedQuery>,
|
|
) -> impl IntoResponse {
|
|
let data = data.read().await;
|
|
let user = match get_user_from_token!(jar, data.0) {
|
|
Some(ua) => ua,
|
|
None => {
|
|
return Err(Html(
|
|
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
|
));
|
|
}
|
|
};
|
|
|
|
let products = match data.0.get_products_by_user(user.id, 12, props.page).await {
|
|
Ok(x) => x,
|
|
Err(e) => return Err(Html(render_error(e, &jar, &data, &None).await)),
|
|
};
|
|
|
|
let lang = get_lang!(jar, data.0);
|
|
let mut context = initial_context(&data.0.0.0, lang, &Some(user)).await;
|
|
|
|
context.insert("list", &products);
|
|
context.insert("page", &props.page);
|
|
|
|
// return
|
|
Ok(Html(
|
|
data.1.render("marketplace/seller.html", &context).unwrap(),
|
|
))
|
|
}
|
|
|
|
pub async fn connection_return_request(
|
|
jar: CookieJar,
|
|
Extension(data): Extension<State>,
|
|
) -> impl IntoResponse {
|
|
let data = data.read().await;
|
|
let mut user = match get_user_from_token!(jar, data.0) {
|
|
Some(ua) => ua,
|
|
None => {
|
|
return Err(Html(
|
|
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
|
));
|
|
}
|
|
};
|
|
|
|
// update user
|
|
user.seller_data.completed_onboarding = true;
|
|
if let Err(e) = data
|
|
.0
|
|
.update_user_seller_data(user.id, user.seller_data.clone())
|
|
.await
|
|
{
|
|
return Err(Html(render_error(e, &jar, &data, &None).await));
|
|
}
|
|
|
|
// ...
|
|
let lang = get_lang!(jar, data.0);
|
|
let mut context = initial_context(&data.0.0.0, lang, &Some(user)).await;
|
|
context.insert("connection_type", "return");
|
|
|
|
// return
|
|
Ok(Html(
|
|
data.1
|
|
.render("auth/seller_connection.html", &context)
|
|
.unwrap(),
|
|
))
|
|
}
|
|
|
|
pub async fn connection_reload_request(
|
|
jar: CookieJar,
|
|
Extension(data): Extension<State>,
|
|
) -> impl IntoResponse {
|
|
let data = data.read().await;
|
|
let user = match get_user_from_token!(jar, data.0) {
|
|
Some(ua) => ua,
|
|
None => {
|
|
return Err(Html(
|
|
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
|
));
|
|
}
|
|
};
|
|
|
|
let lang = get_lang!(jar, data.0);
|
|
let mut context = initial_context(&data.0.0.0, lang, &Some(user)).await;
|
|
context.insert("connection_type", "reload");
|
|
|
|
// return
|
|
Ok(Html(
|
|
data.1
|
|
.render("auth/seller_connection.html", &context)
|
|
.unwrap(),
|
|
))
|
|
}
|