mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 17:58:55 +00:00
Ok just mapped this by hand, super dissapointed that I can't use the the proper way to do it for some unknown reason.
This commit is contained in:
1 parent
8b2765ba65
commit
2a623bd8eb
5 files changed
+112
-48
No files matched your search
@@ -1,8 +1,6 @@
|
||||
use sqlx::MySqlPool;
|
||||
use errors::AnyhowResult;
|
||||
|
||||
|
||||
|
||||
pub async fn delete_weights_as_user(
|
||||
weight_token: &str,
|
||||
mysql_pool: &MySqlPool
|
||||
|
||||
@@ -5,7 +5,7 @@ use sqlx::pool::PoolConnection;
|
||||
use anyhow::anyhow;
|
||||
use log::{ error };
|
||||
|
||||
use enums::by_table::model_weights::weights_types::WeightsType;
|
||||
use enums::by_table::model_weights::weights_types::{WeightsType, self};
|
||||
use enums::by_table::model_weights::weights_category::WeightsCategory;
|
||||
|
||||
use enums::common::visibility::Visibility;
|
||||
@@ -78,12 +78,35 @@ pub async fn get_weights_by_token_with_connection(
|
||||
}
|
||||
};
|
||||
|
||||
// unwrap the result
|
||||
|
||||
let weights_category = WeightsCategory::from_str(record.weights_category.as_ref());
|
||||
let weights_category = match weights_category {
|
||||
Ok(weights_category) => weights_category,
|
||||
Err(err) => {
|
||||
error!("Error fetching weights by token: {:?}", err);
|
||||
return Err(anyhow!("Error fetching weights by token: {:?}", err));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
let weights_types = WeightsType::from_str(record.weights_type.as_ref());
|
||||
|
||||
let weights_types = match weights_types {
|
||||
Ok(weights_types) => weights_types,
|
||||
Err(err) => {
|
||||
error!("Error fetching weights by token: {:?}", err);
|
||||
return Err(anyhow!("Error fetching weights by token: {:?}", err));
|
||||
}
|
||||
};
|
||||
|
||||
Ok(
|
||||
Some(RetrivedModelWeight {
|
||||
token: record.token,
|
||||
title: record.title,
|
||||
weights_type: record.weights_type,
|
||||
weights_category: record.weights_category,
|
||||
weights_type: weights_types,
|
||||
weights_category: weights_category,
|
||||
maybe_thumbnail_token: record.maybe_thumbnail_token,
|
||||
description_markdown: record.description_markdown,
|
||||
description_rendered_html: record.description_rendered_html,
|
||||
@@ -123,8 +146,8 @@ async fn select_include_deleted(
|
||||
SELECT
|
||||
wt.token as `token: tokens::tokens::model_weights::ModelWeightToken`,
|
||||
wt.title,
|
||||
wt.weights_type as `weights_type: enums::by_table::model_weights::weights_types::WeightsType`,
|
||||
wt.weights_category as `weights_category: enums::by_table::model_weights::weights_category::WeightsCategory`,
|
||||
wt.weights_type,
|
||||
wt.weights_category,
|
||||
wt.maybe_thumbnail_token,
|
||||
wt.description_markdown,
|
||||
wt.description_rendered_html,
|
||||
@@ -162,6 +185,8 @@ async fn select_without_deleted(
|
||||
weight_token: &ModelWeightToken,
|
||||
mysql_connection: &mut PoolConnection<MySql>
|
||||
) -> Result<RawWeight, sqlx::Error> {
|
||||
//as `weights_type: enums::by_table::model_weights::weights_types::WeightsType`,
|
||||
//as `weights_category: enums::by_table::model_weights::weights_category::WeightsCategory`
|
||||
sqlx
|
||||
::query_as!(
|
||||
RawWeight,
|
||||
@@ -169,8 +194,8 @@ async fn select_without_deleted(
|
||||
SELECT
|
||||
wt.token as `token: tokens::tokens::model_weights::ModelWeightToken`,
|
||||
wt.title,
|
||||
wt.weights_type as `weights_type: enums::by_table::model_weights::weights_types::WeightsType`,
|
||||
wt.weights_category as `weights_category: enums::by_table::model_weights::weights_category::WeightsCategory`,
|
||||
wt.weights_type,
|
||||
wt.weights_category,
|
||||
wt.maybe_thumbnail_token,
|
||||
wt.description_markdown,
|
||||
wt.description_rendered_html,
|
||||
@@ -211,8 +236,8 @@ async fn select_without_deleted(
|
||||
pub struct RawWeight {
|
||||
pub token: ModelWeightToken,
|
||||
pub title: String,
|
||||
pub weights_type: WeightsType,
|
||||
pub weights_category: WeightsCategory,
|
||||
pub weights_type: String,
|
||||
pub weights_category: String,
|
||||
pub maybe_thumbnail_token: Option<String>,
|
||||
pub description_markdown: String,
|
||||
pub description_rendered_html: String,
|
||||
|
||||
@@ -12,38 +12,45 @@ use enums::by_table::model_weights::{
|
||||
weights_types::WeightsType,
|
||||
weights_category::WeightsCategory,
|
||||
};
|
||||
use tokens::tokens::users::UserToken;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct WeightsRecord {
|
||||
pub weights_token: ModelWeightToken,
|
||||
pub struct WeightsJoinUserRecord {
|
||||
pub token: ModelWeightToken,
|
||||
pub title: String,
|
||||
|
||||
pub creator_user_token: UserToken,
|
||||
pub creator_username: String,
|
||||
pub creator_ip_address: String,
|
||||
|
||||
pub weights_type: WeightsType,
|
||||
pub weights_category: WeightsCategory,
|
||||
|
||||
pub maybe_thumbnail_token: Option<String>,
|
||||
pub description_markdown: String,
|
||||
pub description_rendered_html: String,
|
||||
|
||||
pub cached_user_ratings_negative_count: i32,
|
||||
pub cached_user_ratings_positive_count: i32,
|
||||
pub cached_user_ratings_total_count: i32,
|
||||
|
||||
pub creator_user_token: UserToken,
|
||||
pub creator_ip_address: String,
|
||||
pub creator_set_visibility: Visibility,
|
||||
pub maybe_last_update_user_token: Option<UserToken>,
|
||||
pub original_download_url: Option<String>,
|
||||
pub original_filename: Option<String>,
|
||||
pub file_size_bytes: i32,
|
||||
pub file_checksum_sha2: String,
|
||||
pub private_bucket_hash: String,
|
||||
pub maybe_private_bucket_prefix: Option<String>,
|
||||
pub maybe_private_bucket_extension: Option<String>,
|
||||
pub cached_user_ratings_negative_count: u32,
|
||||
pub cached_user_ratings_positive_count: u32,
|
||||
pub cached_user_ratings_total_count: u32,
|
||||
pub maybe_cached_user_ratings_ratio: Option<f32>,
|
||||
pub cached_user_ratings_total_count: i32,
|
||||
|
||||
pub cached_user_ratings_last_updated_at: DateTime<Utc>,
|
||||
pub version: i32,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub user_deleted_at: Option<DateTime<Utc>>,
|
||||
pub mod_deleted_at: Option<DateTime<Utc>>
|
||||
}
|
||||
|
||||
pub async fn list_weights_by_username(
|
||||
mysql_pool: &MySqlPool,
|
||||
username: &str,
|
||||
can_see_deleted: bool,
|
||||
) -> AnyhowResult<Vec<WeightsRecord>> {
|
||||
) -> AnyhowResult<Vec<WeightsJoinUserRecord>> {
|
||||
let mut connection = mysql_pool.acquire().await?;
|
||||
list_weights_by_username_with_connection(&mut connection, username, can_see_deleted).await
|
||||
}
|
||||
@@ -52,13 +59,13 @@ pub async fn list_weights_by_username_with_connection(
|
||||
mysql_connection: &mut PoolConnection<MySql>,
|
||||
creator_username: &str,
|
||||
can_see_deleted: bool,
|
||||
) -> AnyhowResult<Vec<WeightsRecord>> {
|
||||
) -> AnyhowResult<Vec<WeightsJoinUserRecord>> {
|
||||
|
||||
let datasets =
|
||||
list_datasets_by_creator_username(mysql_connection, creator_username, can_see_deleted)
|
||||
.await;
|
||||
|
||||
let datasets : Vec<WeightsRecord> = match datasets {
|
||||
let datasets : Vec<WeightsJoinUserRecord> = match datasets {
|
||||
Ok(datasets) => datasets,
|
||||
Err(err) => {
|
||||
match err {
|
||||
@@ -74,24 +81,24 @@ pub async fn list_weights_by_username_with_connection(
|
||||
};
|
||||
|
||||
Ok(datasets.into_iter()
|
||||
.map(|dataset| {
|
||||
WeightsRecord {
|
||||
weights_token: ModelWeightToken(dataset.token),
|
||||
title: dataset.title,
|
||||
creator_user_token: dataset.creator_user_token,
|
||||
creator_username: dataset.creator_username,
|
||||
creator_ip_address: dataset.creator_ip_address,
|
||||
weights_type: dataset.weights_type,
|
||||
weights_category: dataset.weights_category,
|
||||
description_markdown: dataset.description_markdown,
|
||||
description_rendered_html: dataset.description_rendered_html,
|
||||
cached_user_ratings_negative_count: dataset.cached_user_ratings_negative_count,
|
||||
cached_user_ratings_positive_count: dataset.cached_user_ratings_positive_count,
|
||||
cached_user_ratings_total_count: dataset.cached_user_ratings_total_count,
|
||||
maybe_cached_user_ratings_ratio: dataset.maybe_cached_user_ratings_ratio,
|
||||
cached_user_ratings_total_count: dataset.cached_user_ratings_total_count,
|
||||
created_at: dataset.created_at,
|
||||
updated_at: dataset.updated_at,
|
||||
.map(|dataset: WeightsJoinUserRecord| {
|
||||
WeightsJoinUserRecord {
|
||||
// weights_token: ModelWeightToken(dataset.token),
|
||||
// title: dataset.title,
|
||||
// creator_user_token: dataset.creator_user_token,
|
||||
// creator_username: dataset.creator_username,
|
||||
// creator_ip_address: dataset.creator_ip_address,
|
||||
// weights_type: dataset.weights_type,
|
||||
// weights_category: dataset.weights_category,
|
||||
// description_markdown: dataset.description_markdown,
|
||||
// description_rendered_html: dataset.description_rendered_html,
|
||||
// cached_user_ratings_negative_count: dataset.cached_user_ratings_negative_count,
|
||||
// cached_user_ratings_positive_count: dataset.cached_user_ratings_positive_count,
|
||||
// cached_user_ratings_total_count: dataset.cached_user_ratings_total_count,
|
||||
// maybe_cached_user_ratings_ratio: dataset.maybe_cached_user_ratings_ratio,
|
||||
// cached_user_ratings_total_count: dataset.cached_user_ratings_total_count,
|
||||
// created_at: dataset.created_at,
|
||||
// updated_at: dataset.updated_at,
|
||||
}
|
||||
})
|
||||
.filter(|dataset| {
|
||||
@@ -101,7 +108,7 @@ pub async fn list_weights_by_username_with_connection(
|
||||
}
|
||||
|
||||
|
||||
async fn list_datasets_by_creator_username(
|
||||
async fn list_weights_by_creator_username(
|
||||
mysql_connection: &mut PoolConnection<MySql>,
|
||||
creator_username: &str,
|
||||
can_see_deleted: bool,
|
||||
@@ -168,6 +175,39 @@ async fn list_datasets_by_creator_username(
|
||||
Ok(maybe_datasets)
|
||||
}
|
||||
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct RawWeightJoinUser {
|
||||
pub token: ModelWeightToken,
|
||||
pub title: String,
|
||||
pub weights_type: WeightsType,
|
||||
pub weights_category: WeightsCategory,
|
||||
pub maybe_thumbnail_token: Option<String>,
|
||||
pub description_markdown: String,
|
||||
pub description_rendered_html: String,
|
||||
pub creator_user_token: UserToken,
|
||||
pub creator_ip_address: String,
|
||||
pub creator_set_visibility: Visibility,
|
||||
pub maybe_last_update_user_token: Option<UserToken>,
|
||||
pub original_download_url: Option<String>,
|
||||
pub original_filename: Option<String>,
|
||||
pub file_size_bytes: i32,
|
||||
pub file_checksum_sha2: String,
|
||||
pub private_bucket_hash: String,
|
||||
pub maybe_private_bucket_prefix: Option<String>,
|
||||
pub maybe_private_bucket_extension: Option<String>,
|
||||
pub cached_user_ratings_negative_count: u32,
|
||||
pub cached_user_ratings_positive_count: u32,
|
||||
pub cached_user_ratings_total_count: u32,
|
||||
pub maybe_cached_user_ratings_ratio: Option<f32>,
|
||||
pub cached_user_ratings_last_updated_at: DateTime<Utc>,
|
||||
pub version: i32,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub user_deleted_at: Option<DateTime<Utc>>,
|
||||
pub mod_deleted_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
|
||||
Whitespace-only changes.
@@ -3,4 +3,5 @@ pub mod delete_weights;
|
||||
pub mod get_weight;
|
||||
pub mod update_weight;
|
||||
// pub mod list_weights_by_user;
|
||||
// pub mod list_weights_query_builder;
|
||||
pub mod tests;
|
||||
Reference in new issue
Block a user