test works query builder now.

This commit is contained in:
Michael Chung committed 2023-11-25 02:40:46 -05:00
1 parent becf58a357
commit fdbf028743
2 files changed
+19 -5

No files matched your search

@@ -68,10 +68,11 @@ pub struct WeightsJoinUserRecord {
}
pub async fn list_weights_by_creator_username(
mysql_pool: &mut PoolConnection<MySql>,
mysql_pool: &MySqlPool,
creator_username: &str,
can_see_deleted: bool
) -> AnyhowResult<Vec<WeightsJoinUserRecord>> {
let mut connection = mysql_pool.acquire().await?;
let raw_weights: Vec<RawWeightJoinUser> = get_raw_weights_by_creator_username(&mut connection, creator_username, can_see_deleted).await?;
@@ -84,8 +85,8 @@ pub async fn list_weights_by_creator_username(
Ok(filtered_weights)
}
pub async fn get_raw_weights_by_creator_username(
connection: &mut MySqlConnection,
async fn get_raw_weights_by_creator_username(
connection: &mut MySqlConnection,
creator_username: &str,
can_see_deleted: bool
) -> AnyhowResult<Vec<RawWeightJoinUser>> {
@@ -187,7 +188,7 @@ pub async fn get_raw_weights_by_creator_username(
}
}
pub async fn map_to_weights(dataset:Vec<RawWeightJoinUser>) -> Vec<WeightsJoinUserRecord> {
async fn map_to_weights(dataset:Vec<RawWeightJoinUser>) -> Vec<WeightsJoinUserRecord> {
let weights: Vec<WeightsJoinUserRecord> = dataset
.into_iter()
.map(|dataset: RawWeightJoinUser| {
@@ -2,7 +2,7 @@
mod tests {
use std::result;
use sqlx::MySqlPool;
use sqlx::{MySqlPool, Acquire};
use rand::Rng;
use tokio;
@@ -24,6 +24,7 @@ mod tests {
use crate::queries::model_weights::get_weight::get_weight_by_token;
use crate::queries::model_weights::delete_weights::{ delete_weights_as_user, delete_weights_as_mod, undelete_weights_as_mod , undelete_weights_as_user};
use crate::queries::model_weights::list_weights_by_user::list_weights_by_creator_username;
async fn setup() -> sqlx::Pool<sqlx::MySql> {
println!("Dropped database model_weights");
@@ -281,6 +282,18 @@ mod tests {
#[tokio::test]
async fn list_all_weights_by_user() -> AnyhowResult<()> {
let pool = setup().await;
let creator_username = "hanashi".to_string();
let can_see_deleted = true;
let weights_by_username = list_weights_by_creator_username(&pool, &creator_username, can_see_deleted).await?;
assert_eq!(weights_by_username.len(), 5);
Ok(())
}
async fn list_weights_query_build() -> AnyhowResult<()> {
Ok(())
}
}