Browse Source

remove change_item

pbs
jake 4 years ago
parent
commit
fb6eaeffd2
  1. 5
      src/entity/gateway/entitygateway.rs
  2. 9
      src/entity/gateway/inmemory.rs
  3. 8
      src/entity/gateway/postgres/postgres.rs

5
src/entity/gateway/entitygateway.rs

@ -65,11 +65,6 @@ pub trait EntityGateway: Send + Sync + Clone {
unimplemented!();
}
// TODO: remove
async fn change_item(&mut self, _id: &ItemEntityId, _item: &ItemDetail) -> Result<(), GatewayError> {
unimplemented!();
}
async fn change_item_location(&mut self, _item_id: &ItemEntityId, _item_location: ItemLocation) -> Result<(), GatewayError> {
unimplemented!();
}

9
src/entity/gateway/inmemory.rs

@ -223,15 +223,6 @@ impl EntityGateway for InMemoryGateway {
Ok(new_item)
}
async fn change_item(&mut self, id: &ItemEntityId, item: &ItemDetail) -> Result<(), GatewayError> {
let mut items = self.items.lock().unwrap();
if let Some((_, ref mut old_item)) = items.iter_mut().find(|(existing_id, _)| **existing_id == *id) {
old_item.item = item.clone();
}
Ok(())
}
async fn change_item_location(&mut self, item_id: &ItemEntityId, item_location: ItemLocation) -> Result<(), GatewayError> {
self.items.lock().unwrap().get_mut(&item_id)
.map(|item_entity| {

8
src/entity/gateway/postgres/postgres.rs

@ -331,14 +331,6 @@ impl EntityGateway for PostgresGateway {
*/
}
async fn change_item(&mut self, id: &ItemEntityId, item: &ItemDetail) -> Result<(), GatewayError> {
sqlx::query("update item set item = $1 where id = $2")
.bind(sqlx::types::Json(PgItemDetail::from(item.clone())))
.bind(id.0)
.execute(&self.pool).await?;
Ok(())
}
async fn change_item_location(&mut self, item_id: &ItemEntityId, item_location: ItemLocation) -> Result<(), GatewayError> {
sqlx::query("insert into item_location (item, location) values ($1, $2)")
.bind(item_id.0)

Loading…
Cancel
Save