add_item now returns a Result
This commit is contained in:
parent
fd0568dbcc
commit
9355629136
5 changed files with 36 additions and 23 deletions
|
@ -72,8 +72,9 @@ impl PartialCalendar for CachedCalendar {
|
|||
self.supported_components
|
||||
}
|
||||
|
||||
async fn add_item(&mut self, item: Item) {
|
||||
async fn add_item(&mut self, item: Item) -> Result<(), Box<dyn Error>> {
|
||||
self.items.insert(item.id().clone(), item);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_item(&mut self, item_id: &ItemId) -> Result<(), Box<dyn Error>> {
|
||||
|
|
|
@ -92,8 +92,8 @@ impl PartialCalendar for RemoteCalendar {
|
|||
|
||||
|
||||
/// Add an item into this calendar
|
||||
async fn add_item(&mut self, _item: Item) {
|
||||
log::error!("Not implemented");
|
||||
async fn add_item(&mut self, _item: Item) -> Result<(), Box<dyn Error>> {
|
||||
Err("Not implemented".into())
|
||||
}
|
||||
|
||||
/// Remove an item from this calendar
|
||||
|
|
|
@ -166,7 +166,11 @@ where
|
|||
log::error!("Inconsistency: new item {} has vanished from the remote end", id_add);
|
||||
continue;
|
||||
},
|
||||
Some(new_item) => cal_local.add_item(new_item.clone()).await,
|
||||
Some(new_item) => {
|
||||
if let Err(err) = cal_local.add_item(new_item.clone()).await {
|
||||
log::error!("Not able to add item {} to local calendar: {}", id_add, err);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,7 +184,9 @@ where
|
|||
if let Err(err) = cal_local.delete_item(&id_change).await {
|
||||
log::error!("Unable to delete item {} from local calendar: {}", id_change, err);
|
||||
}
|
||||
cal_local.add_item(item.clone());
|
||||
if let Err(err) = cal_local.add_item(item.clone()).await {
|
||||
log::error!("Unable to add item {} to local calendar: {}", id_change, err);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +198,11 @@ where
|
|||
log::error!("Inconsistency: created item {} has been marked for upload but is locally missing", id_add);
|
||||
continue;
|
||||
},
|
||||
Some(item) => cal_remote.add_item(item.clone()),
|
||||
Some(item) => {
|
||||
if let Err(err) = cal_remote.add_item(item.clone()).await {
|
||||
log::error!("Unable to add item {} to remote calendar: {}", id_add, err);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -206,7 +216,9 @@ where
|
|||
if let Err(err) = cal_remote.delete_item(&id_change).await {
|
||||
log::error!("Unable to delete item {} from remote calendar: {}", id_change, err);
|
||||
}
|
||||
cal_remote.add_item(item.clone());
|
||||
if let Err(err) = cal_remote.add_item(item.clone()).await {
|
||||
log::error!("Unable to add item {} to remote calendar: {}", id_change, err);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ pub trait PartialCalendar {
|
|||
async fn get_item_by_id<'a>(&'a self, id: &ItemId) -> Option<&'a Item>;
|
||||
|
||||
/// Add an item into this calendar
|
||||
async fn add_item(&mut self, item: Item);
|
||||
async fn add_item(&mut self, item: Item) -> Result<(), Box<dyn Error>>;
|
||||
|
||||
/// Remove an item from this calendar
|
||||
async fn delete_item(&mut self, item_id: &ItemId) -> Result<(), Box<dyn Error>>;
|
||||
|
|
|
@ -84,19 +84,19 @@ async fn populate_test_provider() -> Provider<Cache, CachedCalendar, Cache, Cach
|
|||
// Step 1
|
||||
// Build the calendar as it was at the time of the sync
|
||||
let mut calendar = CachedCalendar::new("a list".into(), cal_id.clone(), my_tasks::calendar::SupportedComponents::TODO);
|
||||
calendar.add_item(task_a).await;
|
||||
calendar.add_item(task_b).await;
|
||||
calendar.add_item(task_c).await;
|
||||
calendar.add_item(task_d).await;
|
||||
calendar.add_item(task_e).await;
|
||||
calendar.add_item(task_f).await;
|
||||
calendar.add_item(task_g).await;
|
||||
calendar.add_item(task_h).await;
|
||||
calendar.add_item(task_i).await;
|
||||
calendar.add_item(task_j).await;
|
||||
calendar.add_item(task_k).await;
|
||||
calendar.add_item(task_l).await;
|
||||
calendar.add_item(task_m).await;
|
||||
calendar.add_item(task_a).await.unwrap();
|
||||
calendar.add_item(task_b).await.unwrap();
|
||||
calendar.add_item(task_c).await.unwrap();
|
||||
calendar.add_item(task_d).await.unwrap();
|
||||
calendar.add_item(task_e).await.unwrap();
|
||||
calendar.add_item(task_f).await.unwrap();
|
||||
calendar.add_item(task_g).await.unwrap();
|
||||
calendar.add_item(task_h).await.unwrap();
|
||||
calendar.add_item(task_i).await.unwrap();
|
||||
calendar.add_item(task_j).await.unwrap();
|
||||
calendar.add_item(task_k).await.unwrap();
|
||||
calendar.add_item(task_l).await.unwrap();
|
||||
calendar.add_item(task_m).await.unwrap();
|
||||
|
||||
server.add_calendar(Arc::new(Mutex::new(calendar.clone())));
|
||||
local.add_calendar(Arc::new(Mutex::new(calendar.clone())));
|
||||
|
@ -128,7 +128,7 @@ async fn populate_test_provider() -> Provider<Cache, CachedCalendar, Cache, Cach
|
|||
cal_server.delete_item(&task_l_id).await.unwrap();
|
||||
|
||||
let task_n = Item::Task(Task::new("task N (new from server)".into(), ItemId::random(), SyncStatus::random_synced()));
|
||||
cal_server.add_item(task_n).await;
|
||||
cal_server.add_item(task_n).await.unwrap();
|
||||
|
||||
|
||||
// Step 3
|
||||
|
@ -157,7 +157,7 @@ async fn populate_test_provider() -> Provider<Cache, CachedCalendar, Cache, Cach
|
|||
cal_local.mark_for_deletion(&task_l_id).await.unwrap();
|
||||
|
||||
let task_o = Item::Task(Task::new("task O (new from local)".into(), ItemId::random(), SyncStatus::NotSynced));
|
||||
cal_local.add_item(task_o).await;
|
||||
cal_local.add_item(task_o).await.unwrap();
|
||||
|
||||
Provider::new(server, local)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue