diff --git a/src/area/admin.rs b/src/area/admin.rs
index 7a92d4b..8f7e039 100644
--- a/src/area/admin.rs
+++ b/src/area/admin.rs
@@ -81,7 +81,9 @@ pub async fn patch(
let area = pool
.get()
.await?
- .interact(move |conn| area::service::patch_tags(&area.id.to_string(), args.tags.clone(), conn))
+ .interact(move |conn| {
+ area::service::patch_tags(&area.id.to_string(), args.tags.clone(), conn)
+ })
.await??;
let log_message = format!(
"{} updated area https://api.btcmap.org/v3/areas/{}",
@@ -112,7 +114,7 @@ pub async fn delete(
let area = pool
.get()
.await?
- .interact(move |conn| area::service::soft_delete(area.id, conn))
+ .interact(move |conn| area::service::soft_delete(&area.id.to_string(), conn))
.await??;
let log_message = format!(
"{} deleted area https://api.btcmap.org/v3/areas/{}",
diff --git a/src/area/rpc.rs b/src/area/rpc.rs
index 955a35b..e96f29d 100644
--- a/src/area/rpc.rs
+++ b/src/area/rpc.rs
@@ -145,7 +145,7 @@ pub async fn remove_tag(
#[derive(Deserialize)]
pub struct RemoveAreaArgs {
pub token: String,
- pub area_id: i64,
+ pub area_id_or_alias: String,
}
pub async fn remove(
@@ -161,7 +161,7 @@ pub async fn remove(
let area = pool
.get()
.await?
- .interact(move |conn| area::service::soft_delete(params.area_id, conn))
+ .interact(move |conn| area::service::soft_delete(¶ms.area_id_or_alias, conn))
.await??;
let log_message = format!(
"{} removed area {} https://api.btcmap.org/v3/areas/{}",
diff --git a/src/area/service.rs b/src/area/service.rs
index 89a2d8c..7723485 100644
--- a/src/area/service.rs
+++ b/src/area/service.rs
@@ -88,9 +88,9 @@ pub fn remove_tag(area_id_or_alias: &str, tag_name: &str, conn: &mut Connection)
Ok(Area::remove_tag(area.id, tag_name, conn)?)
}
-pub fn soft_delete(id: i64, conn: &mut Connection) -> Result {
+pub fn soft_delete(area_id_or_alias: &str, conn: &mut Connection) -> Result {
let sp = conn.savepoint()?;
- let area = Area::select_by_id(id, &sp)?.unwrap();
+ let area = Area::select_by_id_or_alias(area_id_or_alias, &sp)?.unwrap();
let area_elements = element::service::find_in_area(&area, &sp)?;
let area = Area::set_deleted_at(area.id, Some(OffsetDateTime::now_utc()), &sp)?;
element::service::update_areas_tag(&area_elements, &sp)?;
@@ -189,7 +189,7 @@ mod test {
fn soft_delete() -> Result<()> {
let mut conn = mock_conn();
let area = Area::insert(Map::new(), &conn)?;
- super::soft_delete(area.id, &mut conn)?;
+ super::soft_delete(&area.id.to_string(), &mut conn)?;
let db_area = Area::select_by_id(area.id, &conn)?.unwrap();
assert!(db_area.deleted_at.is_some());
Ok(())
@@ -210,7 +210,7 @@ mod test {
tags.insert("url_alias".into(), url_alias.clone());
tags.insert("geo_json".into(), phuket_geo_json());
let area = Area::insert(tags, &mut conn)?;
- super::soft_delete(area.id, &mut conn)?;
+ super::soft_delete(&area.id.to_string(), &mut conn)?;
let db_area = Area::select_by_id(area.id, &conn)?.unwrap();
assert!(db_area.deleted_at.is_some());
assert!(db_area.tags.get("areas").is_none());