chore: use UUID value instead of ref for func arg as UUID implements Copy
This commit is contained in:
parent
f6e78a941f
commit
fc56654e61
|
|
@ -18,7 +18,7 @@ fn category_resources_url(base_url: &str) -> String {
|
|||
format!("{}/category", template_api_prefix(base_url))
|
||||
}
|
||||
|
||||
fn category_resource_url(base_url: &str, category_id: &Uuid) -> String {
|
||||
fn category_resource_url(base_url: &str, category_id: Uuid) -> String {
|
||||
format!("{}/{}", category_resources_url(base_url), category_id)
|
||||
}
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ fn template_creator_resources_url(base_url: &str) -> String {
|
|||
format!("{}/creator", template_api_prefix(base_url))
|
||||
}
|
||||
|
||||
fn template_creator_resource_url(base_url: &str, creator_id: &Uuid) -> String {
|
||||
fn template_creator_resource_url(base_url: &str, creator_id: Uuid) -> String {
|
||||
format!(
|
||||
"{}/{}",
|
||||
template_creator_resources_url(base_url),
|
||||
|
|
@ -86,7 +86,7 @@ impl Client {
|
|||
|
||||
pub async fn get_template_category(
|
||||
&self,
|
||||
category_id: &Uuid,
|
||||
category_id: Uuid,
|
||||
) -> Result<TemplateCategory, AppResponseError> {
|
||||
let url = category_resource_url(&self.base_url, category_id);
|
||||
let resp = self
|
||||
|
|
@ -99,7 +99,7 @@ impl Client {
|
|||
.into_data()
|
||||
}
|
||||
|
||||
pub async fn delete_template_category(&self, category_id: &Uuid) -> Result<(), AppResponseError> {
|
||||
pub async fn delete_template_category(&self, category_id: Uuid) -> Result<(), AppResponseError> {
|
||||
let url = category_resource_url(&self.base_url, category_id);
|
||||
let resp = self
|
||||
.http_client_with_auth(Method::DELETE, &url)
|
||||
|
|
@ -112,7 +112,7 @@ impl Client {
|
|||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn update_template_category(
|
||||
&self,
|
||||
category_id: &Uuid,
|
||||
category_id: Uuid,
|
||||
name: &str,
|
||||
icon: &str,
|
||||
bg_color: &str,
|
||||
|
|
@ -183,7 +183,7 @@ impl Client {
|
|||
|
||||
pub async fn get_template_creator(
|
||||
&self,
|
||||
creator_id: &Uuid,
|
||||
creator_id: Uuid,
|
||||
) -> Result<TemplateCreator, AppResponseError> {
|
||||
let url = template_creator_resource_url(&self.base_url, creator_id);
|
||||
let resp = self
|
||||
|
|
@ -196,7 +196,7 @@ impl Client {
|
|||
.into_data()
|
||||
}
|
||||
|
||||
pub async fn delete_template_creator(&self, creator_id: &Uuid) -> Result<(), AppResponseError> {
|
||||
pub async fn delete_template_creator(&self, creator_id: Uuid) -> Result<(), AppResponseError> {
|
||||
let url = template_creator_resource_url(&self.base_url, creator_id);
|
||||
let resp = self
|
||||
.http_client_with_auth(Method::DELETE, &url)
|
||||
|
|
@ -208,7 +208,7 @@ impl Client {
|
|||
|
||||
pub async fn update_template_creator(
|
||||
&self,
|
||||
creator_id: &Uuid,
|
||||
creator_id: Uuid,
|
||||
name: &str,
|
||||
avatar_url: &str,
|
||||
account_links: Vec<AccountLink>,
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ pub async fn insert_new_template_category<'a, E: Executor<'a, Database = Postgre
|
|||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn update_template_category_by_id<'a, E: Executor<'a, Database = Postgres>>(
|
||||
executor: E,
|
||||
id: &Uuid,
|
||||
id: Uuid,
|
||||
name: &str,
|
||||
description: &str,
|
||||
icon: &str,
|
||||
|
|
@ -129,7 +129,7 @@ pub async fn select_template_categories<'a, E: Executor<'a, Database = Postgres>
|
|||
|
||||
pub async fn select_template_category_by_id<'a, E: Executor<'a, Database = Postgres>>(
|
||||
executor: E,
|
||||
category_id: &Uuid,
|
||||
category_id: Uuid,
|
||||
) -> Result<TemplateCategory, AppError> {
|
||||
let category = sqlx::query_as!(
|
||||
TemplateCategory,
|
||||
|
|
@ -154,7 +154,7 @@ pub async fn select_template_category_by_id<'a, E: Executor<'a, Database = Postg
|
|||
|
||||
pub async fn delete_template_category_by_id<'a, E: Executor<'a, Database = Postgres>>(
|
||||
executor: E,
|
||||
category_id: &Uuid,
|
||||
category_id: Uuid,
|
||||
) -> Result<(), AppError> {
|
||||
let rows_affected = sqlx::query!(
|
||||
r#"
|
||||
|
|
@ -228,7 +228,7 @@ pub async fn insert_template_creator<'a, E: Executor<'a, Database = Postgres>>(
|
|||
|
||||
pub async fn update_template_creator_by_id<'a, E: Executor<'a, Database = Postgres>>(
|
||||
executor: E,
|
||||
creator_id: &Uuid,
|
||||
creator_id: Uuid,
|
||||
name: &str,
|
||||
avatar_url: &str,
|
||||
account_links: &[AccountLink],
|
||||
|
|
@ -282,7 +282,7 @@ pub async fn update_template_creator_by_id<'a, E: Executor<'a, Database = Postgr
|
|||
|
||||
pub async fn delete_template_creator_account_links<'a, E: Executor<'a, Database = Postgres>>(
|
||||
executor: E,
|
||||
creator_id: &Uuid,
|
||||
creator_id: Uuid,
|
||||
) -> Result<(), AppError> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
|
|
@ -324,7 +324,7 @@ pub async fn select_template_creators_by_name<'a, E: Executor<'a, Database = Pos
|
|||
|
||||
pub async fn select_template_creator_by_id<'a, E: Executor<'a, Database = Postgres>>(
|
||||
executor: E,
|
||||
creator_id: &Uuid,
|
||||
creator_id: Uuid,
|
||||
) -> Result<TemplateCreator, AppError> {
|
||||
let creator_row = sqlx::query_as!(
|
||||
AFTemplateCreatorRow,
|
||||
|
|
@ -350,7 +350,7 @@ pub async fn select_template_creator_by_id<'a, E: Executor<'a, Database = Postgr
|
|||
|
||||
pub async fn delete_template_creator_by_id<'a, E: Executor<'a, Database = Postgres>>(
|
||||
executor: E,
|
||||
creator_id: &Uuid,
|
||||
creator_id: Uuid,
|
||||
) -> Result<(), AppError> {
|
||||
let rows_affected = sqlx::query!(
|
||||
r#"
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ async fn update_template_category_handler(
|
|||
let category_id = category_id.into_inner();
|
||||
let updated_template_category = update_template_category(
|
||||
&state.pg_pool,
|
||||
&category_id,
|
||||
category_id,
|
||||
&data.name,
|
||||
&data.description,
|
||||
&data.icon,
|
||||
|
|
@ -102,7 +102,7 @@ async fn get_template_category_handler(
|
|||
state: Data<AppState>,
|
||||
) -> Result<JsonAppResponse<TemplateCategory>> {
|
||||
let category_id = category_id.into_inner();
|
||||
let category = get_template_category(&state.pg_pool, &category_id).await?;
|
||||
let category = get_template_category(&state.pg_pool, category_id).await?;
|
||||
Ok(Json(AppResponse::Ok().with_data(category)))
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ async fn delete_template_category_handler(
|
|||
state: Data<AppState>,
|
||||
) -> Result<JsonAppResponse<()>> {
|
||||
let category_id = category_id.into_inner();
|
||||
delete_template_category(&state.pg_pool, &category_id).await?;
|
||||
delete_template_category(&state.pg_pool, category_id).await?;
|
||||
Ok(Json(AppResponse::Ok()))
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +147,7 @@ async fn update_template_creator_handler(
|
|||
let creator_id = creator_id.into_inner();
|
||||
let updated_creator = update_template_creator(
|
||||
&state.pg_pool,
|
||||
&creator_id,
|
||||
creator_id,
|
||||
&data.name,
|
||||
&data.avatar_url,
|
||||
&data.account_links,
|
||||
|
|
@ -161,7 +161,7 @@ async fn get_template_creator_handler(
|
|||
state: Data<AppState>,
|
||||
) -> Result<JsonAppResponse<TemplateCreator>> {
|
||||
let creator_id = creator_id.into_inner();
|
||||
let template_creator = get_template_creator(&state.pg_pool, &creator_id).await?;
|
||||
let template_creator = get_template_creator(&state.pg_pool, creator_id).await?;
|
||||
Ok(Json(AppResponse::Ok().with_data(template_creator)))
|
||||
}
|
||||
|
||||
|
|
@ -170,6 +170,6 @@ async fn delete_template_creator_handler(
|
|||
state: Data<AppState>,
|
||||
) -> Result<JsonAppResponse<TemplateCreator>> {
|
||||
let creator_id = creator_id.into_inner();
|
||||
delete_template_creator(&state.pg_pool, &creator_id).await?;
|
||||
delete_template_creator(&state.pg_pool, creator_id).await?;
|
||||
Ok(Json(AppResponse::Ok()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ pub async fn create_new_template_category(
|
|||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn update_template_category(
|
||||
pg_pool: &PgPool,
|
||||
category_id: &Uuid,
|
||||
category_id: Uuid,
|
||||
name: &str,
|
||||
description: &str,
|
||||
icon: &str,
|
||||
|
|
@ -70,7 +70,7 @@ pub async fn get_template_categories(
|
|||
|
||||
pub async fn get_template_category(
|
||||
pg_pool: &PgPool,
|
||||
category_id: &Uuid,
|
||||
category_id: Uuid,
|
||||
) -> Result<TemplateCategory, AppResponseError> {
|
||||
let category = select_template_category_by_id(pg_pool, category_id).await?;
|
||||
Ok(category)
|
||||
|
|
@ -78,7 +78,7 @@ pub async fn get_template_category(
|
|||
|
||||
pub async fn delete_template_category(
|
||||
pg_pool: &PgPool,
|
||||
category_id: &Uuid,
|
||||
category_id: Uuid,
|
||||
) -> Result<(), AppResponseError> {
|
||||
delete_template_category_by_id(pg_pool, category_id).await?;
|
||||
Ok(())
|
||||
|
|
@ -97,7 +97,7 @@ pub async fn create_new_template_creator(
|
|||
|
||||
pub async fn update_template_creator(
|
||||
pg_pool: &PgPool,
|
||||
creator_id: &Uuid,
|
||||
creator_id: Uuid,
|
||||
name: &str,
|
||||
avatar_url: &str,
|
||||
account_links: &[AccountLink],
|
||||
|
|
@ -128,7 +128,7 @@ pub async fn get_template_creators(
|
|||
|
||||
pub async fn get_template_creator(
|
||||
pg_pool: &PgPool,
|
||||
creator_id: &Uuid,
|
||||
creator_id: Uuid,
|
||||
) -> Result<TemplateCreator, AppResponseError> {
|
||||
let creator = select_template_creator_by_id(pg_pool, creator_id).await?;
|
||||
Ok(creator)
|
||||
|
|
@ -136,7 +136,7 @@ pub async fn get_template_creator(
|
|||
|
||||
pub async fn delete_template_creator(
|
||||
pg_pool: &PgPool,
|
||||
creator_id: &Uuid,
|
||||
creator_id: Uuid,
|
||||
) -> Result<(), AppResponseError> {
|
||||
delete_template_creator_by_id(pg_pool, creator_id).await?;
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ async fn test_template_category_crud() {
|
|||
let updated_category_name = Uuid::new_v4().to_string();
|
||||
let updated_template_category = authorized_client
|
||||
.update_template_category(
|
||||
&new_template_category.id,
|
||||
new_template_category.id,
|
||||
updated_category_name.as_str(),
|
||||
"new_icon",
|
||||
"new_bg_color",
|
||||
|
|
@ -100,7 +100,7 @@ async fn test_template_category_crud() {
|
|||
|
||||
let guest_client = localhost_client();
|
||||
let template_category = guest_client
|
||||
.get_template_category(&new_template_category.id)
|
||||
.get_template_category(new_template_category.id)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(template_category.name, updated_category_name);
|
||||
|
|
@ -154,16 +154,16 @@ async fn test_template_category_crud() {
|
|||
.iter()
|
||||
.any(|r| r.name == second_category_name));
|
||||
let result = guest_client
|
||||
.delete_template_category(&new_template_category.id)
|
||||
.delete_template_category(new_template_category.id)
|
||||
.await;
|
||||
assert!(result.is_err());
|
||||
assert_eq!(result.unwrap_err().code, ErrorCode::NotLoggedIn);
|
||||
authorized_client
|
||||
.delete_template_category(&new_template_category.id)
|
||||
.delete_template_category(new_template_category.id)
|
||||
.await
|
||||
.unwrap();
|
||||
let result = guest_client
|
||||
.get_template_category(&new_template_category.id)
|
||||
.get_template_category(new_template_category.id)
|
||||
.await;
|
||||
assert!(result.is_err());
|
||||
assert_eq!(result.unwrap_err().code, ErrorCode::RecordNotFound);
|
||||
|
|
@ -197,7 +197,7 @@ async fn test_template_creator_crud() {
|
|||
}];
|
||||
let updated_creator = authorized_client
|
||||
.update_template_creator(
|
||||
&new_creator.id,
|
||||
new_creator.id,
|
||||
"new_name",
|
||||
"new_avatar_url",
|
||||
updated_account_links,
|
||||
|
|
@ -211,7 +211,7 @@ async fn test_template_creator_crud() {
|
|||
assert_eq!(updated_creator.account_links[0].url, "twitter_url");
|
||||
|
||||
let creator = guest_client
|
||||
.get_template_creator(&new_creator.id)
|
||||
.get_template_creator(new_creator.id)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(creator.name, "new_name");
|
||||
|
|
@ -220,14 +220,14 @@ async fn test_template_creator_crud() {
|
|||
assert_eq!(creator.account_links[0].link_type, "twitter");
|
||||
assert_eq!(creator.account_links[0].url, "twitter_url");
|
||||
|
||||
let result = guest_client.delete_template_creator(&new_creator.id).await;
|
||||
let result = guest_client.delete_template_creator(new_creator.id).await;
|
||||
assert!(result.is_err());
|
||||
assert_eq!(result.unwrap_err().code, ErrorCode::NotLoggedIn);
|
||||
authorized_client
|
||||
.delete_template_creator(&new_creator.id)
|
||||
.delete_template_creator(new_creator.id)
|
||||
.await
|
||||
.unwrap();
|
||||
let result = guest_client.get_template_creator(&new_creator.id).await;
|
||||
let result = guest_client.get_template_creator(new_creator.id).await;
|
||||
assert!(result.is_err());
|
||||
assert_eq!(result.unwrap_err().code, ErrorCode::RecordNotFound);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue