fix: replace rank with priority

This commit is contained in:
khorshuheng 2024-08-14 14:17:21 +08:00
parent fc56654e61
commit 59e5a13ee4
11 changed files with 36 additions and 37 deletions

View file

@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT\n category_id AS id,\n name,\n description,\n icon,\n bg_color,\n category_type AS \"category_type: AFTemplateCategoryTypeColumn\",\n rank\n FROM af_template_category\n WHERE category_id = $1\n ",
"query": "\n SELECT\n category_id AS id,\n name,\n description,\n icon,\n bg_color,\n category_type AS \"category_type: AFTemplateCategoryTypeColumn\",\n priority\n FROM af_template_category\n WHERE category_id = $1\n ",
"describe": {
"columns": [
{
@ -35,7 +35,7 @@
},
{
"ordinal": 6,
"name": "rank",
"name": "priority",
"type_info": "Int4"
}
],
@ -54,5 +54,5 @@
false
]
},
"hash": "4f8bb1345f524f5a11ae74357265d8e308eebb562117bb3f36c3b25f9e1c5e1b"
"hash": "6aca3fde126cb1761c0a5ce1fbfa793bdbac4aed137cdf60eb3f277f36d7bf7a"
}

View file

@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "\n UPDATE af_template_category\n SET\n name = $2,\n description = $3,\n icon = $4,\n bg_color = $5,\n category_type = $6,\n rank = $7\n WHERE category_id = $1\n RETURNING\n category_id AS id,\n name,\n description,\n icon,\n bg_color,\n category_type AS \"category_type: AFTemplateCategoryTypeColumn\",\n rank\n ",
"query": "\n UPDATE af_template_category\n SET\n name = $2,\n description = $3,\n icon = $4,\n bg_color = $5,\n category_type = $6,\n priority = $7\n WHERE category_id = $1\n RETURNING\n category_id AS id,\n name,\n description,\n icon,\n bg_color,\n category_type AS \"category_type: AFTemplateCategoryTypeColumn\",\n priority\n ",
"describe": {
"columns": [
{
@ -35,7 +35,7 @@
},
{
"ordinal": 6,
"name": "rank",
"name": "priority",
"type_info": "Int4"
}
],
@ -60,5 +60,5 @@
false
]
},
"hash": "e011a91040db0ffdaf46c859e58b14ad6503b2f4eab33d3b32d677c9731aae79"
"hash": "ae6558fb998c524e9a1fa4f0e0b36d95b38310ff841036b5d8d9b7ae98cd70fb"
}

View file

@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "\n INSERT INTO af_template_category (name, description, icon, bg_color, category_type, rank)\n VALUES ($1, $2, $3, $4, $5, $6)\n RETURNING\n category_id AS id,\n name,\n description,\n icon,\n bg_color,\n category_type AS \"category_type: AFTemplateCategoryTypeColumn\",\n rank\n ",
"query": "\n INSERT INTO af_template_category (name, description, icon, bg_color, category_type, priority)\n VALUES ($1, $2, $3, $4, $5, $6)\n RETURNING\n category_id AS id,\n name,\n description,\n icon,\n bg_color,\n category_type AS \"category_type: AFTemplateCategoryTypeColumn\",\n priority\n ",
"describe": {
"columns": [
{
@ -35,7 +35,7 @@
},
{
"ordinal": 6,
"name": "rank",
"name": "priority",
"type_info": "Int4"
}
],
@ -59,5 +59,5 @@
false
]
},
"hash": "b9d4e564e23df7ab391c78848b6a9d51e30496c58e70b26f14dfe55b6a0d2e69"
"hash": "cb2375ad0094baefed417645b781f40dcabfbfe4a4738c99bb4efff649e6a0e6"
}

View file

@ -42,7 +42,7 @@ impl Client {
bg_color: &str,
description: &str,
category_type: TemplateCategoryType,
rank: i32,
priority: i32,
) -> Result<TemplateCategory, AppResponseError> {
let url = category_resources_url(&self.base_url);
let resp = self
@ -53,7 +53,7 @@ impl Client {
icon: icon.to_string(),
bg_color: bg_color.to_string(),
description: description.to_string(),
rank,
priority,
category_type,
})
.send()
@ -118,7 +118,7 @@ impl Client {
bg_color: &str,
description: &str,
category_type: TemplateCategoryType,
rank: i32,
priority: i32,
) -> Result<TemplateCategory, AppResponseError> {
let url = category_resource_url(&self.base_url, category_id);
let resp = self
@ -130,7 +130,7 @@ impl Client {
bg_color: bg_color.to_string(),
description: description.to_string(),
category_type,
rank,
priority,
})
.send()
.await?;

View file

@ -1017,7 +1017,7 @@ pub struct TemplateCategory {
pub bg_color: String,
pub description: String,
pub category_type: TemplateCategoryType,
pub rank: i32,
pub priority: i32,
}
#[derive(Serialize, Deserialize, Debug)]
@ -1027,7 +1027,7 @@ pub struct CreateTemplateCategoryParams {
pub bg_color: String,
pub description: String,
pub category_type: TemplateCategoryType,
pub rank: i32,
pub priority: i32,
}
#[derive(Serialize, Deserialize, Debug)]
@ -1043,7 +1043,7 @@ pub struct UpdateTemplateCategoryParams {
pub bg_color: String,
pub description: String,
pub category_type: TemplateCategoryType,
pub rank: i32,
pub priority: i32,
}
#[derive(Serialize, Deserialize, Debug)]

View file

@ -284,7 +284,7 @@ pub struct AFTemplateCategoryRow {
pub bg_color: String,
pub description: String,
pub category_type: AFTemplateCategoryTypeColumn,
pub rank: i32,
pub priority: i32,
}
impl From<AFTemplateCategoryRow> for TemplateCategory {
@ -296,7 +296,7 @@ impl From<AFTemplateCategoryRow> for TemplateCategory {
bg_color: value.bg_color,
description: value.description,
category_type: value.category_type.into(),
rank: value.rank,
priority: value.priority,
}
}
}

View file

@ -14,13 +14,13 @@ pub async fn insert_new_template_category<'a, E: Executor<'a, Database = Postgre
icon: &str,
bg_color: &str,
category_type: TemplateCategoryType,
rank: i32,
priority: i32,
) -> Result<TemplateCategory, AppError> {
let category_type_column: AFTemplateCategoryTypeColumn = category_type.into();
let new_template_category = sqlx::query_as!(
TemplateCategory,
r#"
INSERT INTO af_template_category (name, description, icon, bg_color, category_type, rank)
INSERT INTO af_template_category (name, description, icon, bg_color, category_type, priority)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING
category_id AS id,
@ -29,14 +29,14 @@ pub async fn insert_new_template_category<'a, E: Executor<'a, Database = Postgre
icon,
bg_color,
category_type AS "category_type: AFTemplateCategoryTypeColumn",
rank
priority
"#,
name,
description,
icon,
bg_color,
category_type_column as AFTemplateCategoryTypeColumn,
rank,
priority,
)
.fetch_one(executor)
.await?;
@ -52,7 +52,7 @@ pub async fn update_template_category_by_id<'a, E: Executor<'a, Database = Postg
icon: &str,
bg_color: &str,
category_type: TemplateCategoryType,
rank: i32,
priority: i32,
) -> Result<TemplateCategory, AppError> {
let category_type_column: AFTemplateCategoryTypeColumn = category_type.into();
let new_template_category = sqlx::query_as!(
@ -65,7 +65,7 @@ pub async fn update_template_category_by_id<'a, E: Executor<'a, Database = Postg
icon = $4,
bg_color = $5,
category_type = $6,
rank = $7
priority = $7
WHERE category_id = $1
RETURNING
category_id AS id,
@ -74,7 +74,7 @@ pub async fn update_template_category_by_id<'a, E: Executor<'a, Database = Postg
icon,
bg_color,
category_type AS "category_type: AFTemplateCategoryTypeColumn",
rank
priority
"#,
id,
name,
@ -82,7 +82,7 @@ pub async fn update_template_category_by_id<'a, E: Executor<'a, Database = Postg
icon,
bg_color,
category_type_column as AFTemplateCategoryTypeColumn,
rank,
priority,
)
.fetch_one(executor)
.await?;
@ -103,7 +103,7 @@ pub async fn select_template_categories<'a, E: Executor<'a, Database = Postgres>
icon,
bg_color,
category_type,
rank
priority
FROM af_template_category
WHERE TRUE
"#,
@ -118,7 +118,7 @@ pub async fn select_template_categories<'a, E: Executor<'a, Database = Postgres>
query_builder.push_bind(name_contains);
query_builder.push(" , '%')");
};
query_builder.push(" ORDER BY rank ASC");
query_builder.push(" ORDER BY priority DESC");
let query = query_builder.build_query_as::<AFTemplateCategoryRow>();
let category_rows: Vec<AFTemplateCategoryRow> = query.fetch_all(executor).await?;
@ -141,7 +141,7 @@ pub async fn select_template_category_by_id<'a, E: Executor<'a, Database = Postg
icon,
bg_color,
category_type AS "category_type: AFTemplateCategoryTypeColumn",
rank
priority
FROM af_template_category
WHERE category_id = $1
"#,

View file

@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS af_template_category (
description TEXT NOT NULL,
bg_color TEXT NOT NULL,
category_type INT NOT NULL,
rank INT NOT NULL,
priority INT NOT NULL,
PRIMARY KEY (category_id)
);

View file

@ -11,6 +11,5 @@ CREATE TABLE IF NOT EXISTS af_template_creator_account_link (
link_type TEXT NOT NULL,
url TEXT NOT NULL,
UNIQUE(creator_id, link_type)
PRIMARY KEY (creator_id, link_type)
);
CREATE INDEX IF NOT EXISTS idx_creator_id_on_af_template_creator_account_link ON af_template_creator_account_link(creator_id);

View file

@ -56,7 +56,7 @@ async fn post_template_category_handler(
&data.icon,
&data.bg_color,
data.category_type,
data.rank,
data.priority,
)
.await?;
Ok(Json(AppResponse::Ok().with_data(new_template_category)))
@ -91,7 +91,7 @@ async fn update_template_category_handler(
&data.icon,
&data.bg_color,
data.category_type,
data.rank,
data.priority,
)
.await?;
Ok(Json(AppResponse::Ok().with_data(updated_template_category)))

View file

@ -74,7 +74,7 @@ async fn test_template_category_crud() {
new_template_category.category_type,
TemplateCategoryType::Feature
);
assert_eq!(new_template_category.rank, 1);
assert_eq!(new_template_category.priority, 1);
let updated_category_name = Uuid::new_v4().to_string();
let updated_template_category = authorized_client
.update_template_category(
@ -96,7 +96,7 @@ async fn test_template_category_crud() {
updated_template_category.category_type,
TemplateCategoryType::UseCase
);
assert_eq!(updated_template_category.rank, 2);
assert_eq!(updated_template_category.priority, 2);
let guest_client = localhost_client();
let template_category = guest_client
@ -111,7 +111,7 @@ async fn test_template_category_crud() {
template_category.category_type,
TemplateCategoryType::UseCase
);
assert_eq!(template_category.rank, 2);
assert_eq!(template_category.priority, 2);
let second_category_name = Uuid::new_v4().to_string();
authorized_client