add: change default avatar

This commit is contained in:
trisua 2025-07-14 22:05:59 -04:00
parent 8dfd307919
commit 959a125992
6 changed files with 92 additions and 13 deletions

View file

@ -6,4 +6,11 @@
xmlns="http://www.w3.org/2000/svg"
>
<rect width="460" height="460" fill="#E793B9" />
<ellipse cx="125" cy="205" rx="23" ry="24" fill="#FFBFDD" />
<circle cx="334" cy="205" r="24" fill="#FFBFDD" />
<path
d="M281.204 235.5C284.405 235.5 287.05 238.115 286.488 241.266C285.823 244.997 284.514 248.655 282.585 252.147C279.67 257.424 275.398 262.22 270.012 266.259C264.626 270.298 258.233 273.503 251.196 275.689C244.159 277.875 236.617 279 229 279C221.383 279 213.841 277.875 206.804 275.689C199.767 273.503 193.374 270.298 187.988 266.259C182.602 262.22 178.33 257.424 175.415 252.147C173.486 248.655 172.177 244.997 171.512 241.266C170.95 238.115 173.595 235.5 176.796 235.5V235.5C179.998 235.5 182.533 238.125 183.23 241.25C183.809 243.841 184.779 246.381 186.125 248.819C188.458 253.042 191.876 256.879 196.185 260.111C200.495 263.343 205.61 265.907 211.241 267.656C216.871 269.405 222.906 270.305 229 270.305C235.094 270.305 241.129 269.405 246.759 267.656C252.39 265.907 257.505 263.343 261.815 260.111C266.124 256.879 269.542 253.042 271.875 248.819C273.221 246.381 274.191 243.841 274.77 241.25C275.467 238.125 278.002 235.5 281.204 235.5V235.5Z"
fill="#FFBFDD"
fill-opacity="0.984314"
/>
</svg>

Before

Width:  |  Height:  |  Size: 181 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Before After
Before After

View file

@ -1,13 +1,20 @@
use crate::{
get_user_from_token,
image::{save_webp_buffer, JsonMultipart},
routes::api::v1::{
routes::{
api::v1::{
communities::posts::MAXIMUM_FILE_SIZE, CreateProduct, UpdateProductDescription,
UpdateProductName, UpdateProductPrice,
},
pages::PaginatedQuery,
},
State,
};
use axum::{extract::Path, response::IntoResponse, Extension, Json};
use axum::{
extract::{Path, Query},
response::IntoResponse,
Extension, Json,
};
use axum_extra::extract::CookieJar;
use tetratto_core::model::{
oauth,
@ -31,14 +38,18 @@ pub async fn get_request(
}
}
pub async fn list_request(jar: CookieJar, Extension(data): Extension<State>) -> impl IntoResponse {
pub async fn list_request(
jar: CookieJar,
Extension(data): Extension<State>,
Query(props): Query<PaginatedQuery>,
) -> impl IntoResponse {
let data = &(data.read().await).0;
let user = match get_user_from_token!(jar, data, oauth::AppScope::UserReadProducts) {
Some(ua) => ua,
None => return Json(Error::NotAllowed.into()),
};
match data.get_products_by_user(user.id).await {
match data.get_products_by_user(user.id, 12, props.page).await {
Ok(x) => Json(ApiReturn {
ok: true,
message: "Success".to_string(),

View file

@ -1,6 +1,9 @@
use super::render_error;
use crate::{assets::initial_context, get_lang, get_user_from_token, State};
use crate::{
assets::initial_context, get_lang, get_user_from_token, State, routes::pages::PaginatedQuery,
};
use axum::{
extract::Query,
response::{Html, IntoResponse},
Extension,
};
@ -11,6 +14,7 @@ use tetratto_core::model::Error;
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) {
@ -22,14 +26,16 @@ pub async fn seller_settings_request(
}
};
let products = match data.0.get_products_by_user(user.id).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(

View file

@ -75,6 +75,26 @@ impl DataManager {
Ok(res.unwrap())
}
pub async fn get_table_row_count_where(&self, table: &str, r#where: &str) -> Result<i32> {
let conn = match self.0.connect().await {
Ok(c) => c,
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
};
let res = query_row!(
&conn,
&format!("SELECT COUNT(*)::int FROM {} {}", table, r#where),
params![],
|x| Ok(x.get::<usize, i32>(0))
);
if let Err(e) = res {
return Err(Error::DatabaseError(e.to_string()));
}
Ok(res.unwrap())
}
}
#[macro_export]

View file

@ -30,7 +30,38 @@ impl DataManager {
///
/// # Arguments
/// * `id` - the ID of the user to fetch products for
pub async fn get_products_by_user(&self, id: usize) -> Result<Vec<Product>> {
/// * `batch`
/// * `page`
pub async fn get_products_by_user(
&self,
id: usize,
batch: usize,
page: usize,
) -> Result<Vec<Product>> {
let conn = match self.0.connect().await {
Ok(c) => c,
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
};
let res = query_rows!(
&conn,
"SELECT * FROM products WHERE owner = $1 ORDER BY created DESC LIMIT {} OFFSET {}",
&[&(id as i64), &(batch as i64), &((page * batch) as i64)],
|x| { Self::get_product_from_row(x) }
);
if res.is_err() {
return Err(Error::GeneralNotFound("product".to_string()));
}
Ok(res.unwrap())
}
/// Get all products by user.
///
/// # Arguments
/// * `id` - the ID of the user to fetch products for
pub async fn get_products_by_user_all(&self, id: usize) -> Result<Vec<Product>> {
let conn = match self.0.connect().await {
Ok(c) => c,
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
@ -68,9 +99,11 @@ impl DataManager {
let owner = self.get_user_by_id(data.owner).await?;
if !owner.permissions.check(FinePermission::SUPPORTER) {
let products = self.get_products_by_user(data.owner).await?;
let products = self
.get_table_row_count_where("products", &format!("owner = {}", owner.id))
.await? as usize;
if products.len() >= Self::MAXIMUM_FREE_PRODUCTS {
if products >= Self::MAXIMUM_FREE_PRODUCTS {
return Err(Error::MiscError(
"You already have the maximum number of products you can have".to_string(),
));

View file

@ -165,9 +165,11 @@ impl DataManager {
let owner = self.get_user_by_id(data.owner).await?;
if !owner.permissions.check(FinePermission::SUPPORTER) {
let stacks = self.get_stacks_by_user(data.owner).await?;
let stacks = self
.get_table_row_count_where("stacks", &format!("owner = {}", owner.id))
.await? as usize;
if stacks.len() >= Self::MAXIMUM_FREE_STACKS {
if stacks >= Self::MAXIMUM_FREE_STACKS {
return Err(Error::MiscError(
"You already have the maximum number of stacks you can have".to_string(),
));