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