Skip to content

Commit

Permalink
Fix issue with deleta area call
Browse files Browse the repository at this point in the history
  • Loading branch information
bubelov committed Aug 27, 2024
1 parent 0bd2ea1 commit 3044e57
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/area/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/{}",
Expand Down Expand Up @@ -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/{}",
Expand Down
4 changes: 2 additions & 2 deletions src/area/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(&params.area_id_or_alias, conn))
.await??;
let log_message = format!(
"{} removed area {} https://api.btcmap.org/v3/areas/{}",
Expand Down
8 changes: 4 additions & 4 deletions src/area/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Area> {
pub fn soft_delete(area_id_or_alias: &str, conn: &mut Connection) -> Result<Area> {
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)?;
Expand Down Expand Up @@ -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(())
Expand All @@ -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());
Expand Down

0 comments on commit 3044e57

Please sign in to comment.