add: products ui
This commit is contained in:
parent
8f76578f1b
commit
fd529d3847
31 changed files with 1041 additions and 49 deletions
|
@ -43,3 +43,109 @@ pub async fn wallet_request(
|
|||
data.1.render("economy/wallet.html", &context).unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
/// `/products`
|
||||
pub async fn products_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 list = 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, &Some(user)).await)),
|
||||
};
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0.0, lang, &Some(user)).await;
|
||||
|
||||
context.insert("list", &list);
|
||||
context.insert("page", &props.page);
|
||||
|
||||
// return
|
||||
Ok(Html(
|
||||
data.1.render("economy/products.html", &context).unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
/// `/product/{id}/edit`
|
||||
pub async fn edit_product_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
) -> 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 product = match data.0.get_product_by_id(id).await {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
if user.id != product.owner {
|
||||
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("product", &product);
|
||||
|
||||
// return
|
||||
Ok(Html(data.1.render("economy/edit.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/product/{id}`
|
||||
pub async fn product_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
Path(id): Path<usize>,
|
||||
) -> 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 product = match data.0.get_product_by_id(id).await {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
let owner = match data.0.get_user_by_id(product.owner).await {
|
||||
Ok(x) => x,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0.0, lang, &Some(user)).await;
|
||||
|
||||
context.insert("product", &product);
|
||||
context.insert("owner", &owner);
|
||||
|
||||
// return
|
||||
Ok(Html(
|
||||
data.1.render("economy/product.html", &context).unwrap(),
|
||||
))
|
||||
}
|
||||
|
|
|
@ -85,6 +85,7 @@ pub fn routes() -> Router {
|
|||
.route("/@{username}/replies", get(profile::replies_request))
|
||||
.route("/@{username}/following", get(profile::following_request))
|
||||
.route("/@{username}/followers", get(profile::followers_request))
|
||||
.route("/@{username}/shop", get(profile::shop_request))
|
||||
// communities
|
||||
.route("/communities", get(communities::list_request))
|
||||
.route("/communities/search", get(communities::search_request))
|
||||
|
@ -162,6 +163,9 @@ pub fn routes() -> Router {
|
|||
.route("/mail/letter/{id}", get(mail::letter_request))
|
||||
// economy
|
||||
.route("/wallet", get(economy::wallet_request))
|
||||
.route("/products", get(economy::products_request))
|
||||
.route("/product/{id}/edit", get(economy::edit_product_request))
|
||||
.route("/product/{id}", get(economy::product_request))
|
||||
}
|
||||
|
||||
pub fn lw_routes() -> Router {
|
||||
|
|
|
@ -307,20 +307,20 @@ pub async fn posts_request(
|
|||
)
|
||||
.await
|
||||
{
|
||||
Ok(p) => Some(data.0.posts_muted_phrase_filter(
|
||||
Ok(p) => data.0.posts_muted_phrase_filter(
|
||||
&p,
|
||||
if let Some(ref ua) = user {
|
||||
Some(&ua.settings.muted)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
)),
|
||||
),
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
},
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user).await)),
|
||||
}
|
||||
} else {
|
||||
None
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let communities = match data.0.get_memberships_by_owner(other_user.id).await {
|
||||
|
@ -614,6 +614,95 @@ pub async fn media_request(
|
|||
Ok(Html(data.1.render("profile/media.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/@{username}/shop`
|
||||
pub async fn shop_request(
|
||||
jar: CookieJar,
|
||||
Path(username): Path<String>,
|
||||
Query(props): Query<PaginatedQuery>,
|
||||
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 other_user = match data.0.get_user_by_username(&username).await {
|
||||
Ok(ua) => ua,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
if !other_user.settings.enable_shop {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &Some(user)).await,
|
||||
));
|
||||
}
|
||||
|
||||
check_user_blocked_or_private!(Some(user.clone()), other_user, data, jar);
|
||||
|
||||
// fetch data
|
||||
let list = match data
|
||||
.0
|
||||
.get_products_by_user(other_user.id, 12, props.page)
|
||||
.await
|
||||
{
|
||||
Ok(x) => x,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
let communities = match data.0.get_memberships_by_owner(other_user.id).await {
|
||||
Ok(m) => match data.0.fill_communities(m).await {
|
||||
Ok(m) => m,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
},
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
// init context
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0.0, lang, &Some(user.clone())).await;
|
||||
|
||||
let is_self = user.id == other_user.id;
|
||||
|
||||
let is_following = data
|
||||
.0
|
||||
.get_userfollow_by_initiator_receiver(user.id, other_user.id)
|
||||
.await
|
||||
.is_ok();
|
||||
|
||||
let is_following_you = data
|
||||
.0
|
||||
.get_userfollow_by_receiver_initiator(user.id, other_user.id)
|
||||
.await
|
||||
.is_ok();
|
||||
|
||||
let is_blocking = data
|
||||
.0
|
||||
.get_userblock_by_initiator_receiver(user.id, other_user.id)
|
||||
.await
|
||||
.is_ok();
|
||||
|
||||
context.insert("list", &list);
|
||||
context.insert("page", &props.page);
|
||||
profile_context(
|
||||
&mut context,
|
||||
&Some(user),
|
||||
&other_user,
|
||||
&communities,
|
||||
is_self,
|
||||
is_following,
|
||||
is_following_you,
|
||||
is_blocking,
|
||||
);
|
||||
|
||||
// return
|
||||
Ok(Html(data.1.render("profile/shop.html", &context).unwrap()))
|
||||
}
|
||||
|
||||
/// `/@{username}/outbox`
|
||||
pub async fn outbox_request(
|
||||
jar: CookieJar,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue