diff --git a/src/area/model.rs b/src/area/model.rs index f6304be..e0933c2 100644 --- a/src/area/model.rs +++ b/src/area/model.rs @@ -181,7 +181,7 @@ impl Area { r#" SELECT {MAPPER_PROJECTION} FROM {TABLE_NAME} - WHERE {COL_ID} = :{COL_ID} + WHERE {COL_ID} = :{COL_ID}; "# ); conn.query_row(&sql, named_params! { ":id": id }, mapper()) @@ -189,15 +189,26 @@ impl Area { .map_err(Into::into) } - pub fn select_by_alias(alias: &str, conn: &Connection) -> Result> { + pub async fn select_by_alias_async( + alias: impl Into, + pool: &Pool, + ) -> Result> { + let alias = alias.into(); + pool.get() + .await? + .interact(|conn| Area::select_by_alias(alias, conn)) + .await? + } + + pub fn select_by_alias(alias: impl Into, conn: &Connection) -> Result> { let sql = format!( r#" SELECT {MAPPER_PROJECTION} FROM {TABLE_NAME} - WHERE {COL_ALIAS} = :alias + WHERE {COL_ALIAS} = :{COL_ALIAS}; "# ); - conn.query_row(&sql, named_params! { ":alias": alias }, mapper()) + conn.query_row(&sql, named_params! { ":alias": alias.into() }, mapper()) .optional() .map_err(Into::into) } diff --git a/src/area/v2.rs b/src/area/v2.rs index a1e8567..66ac19e 100644 --- a/src/area/v2.rs +++ b/src/area/v2.rs @@ -88,12 +88,7 @@ pub async fn get_by_url_alias( url_alias: Path, pool: Data, ) -> Result, Error> { - let cloned_url_alias = url_alias.clone(); - let area = pool - .get() - .await? - .interact(move |conn| Area::select_by_alias(&cloned_url_alias, conn)) - .await??; + let area = Area::select_by_alias_async(url_alias.to_string(), &pool).await?; area.ok_or(Error::NotFound(format!( "Area with url_alias = {url_alias} doesn't exist" )))