More ID -> URL renaming
This commit is contained in:
parent
2f7c14d0aa
commit
0075ebfbdb
14 changed files with 244 additions and 253 deletions
|
@ -6,7 +6,7 @@ use chrono::{Utc};
|
|||
use url::Url;
|
||||
|
||||
use kitchen_fridge::{client::Client, traits::CalDavSource};
|
||||
use kitchen_fridge::calendar::{CalendarId, SupportedComponents};
|
||||
use kitchen_fridge::calendar::SupportedComponents;
|
||||
use kitchen_fridge::Item;
|
||||
use kitchen_fridge::Task;
|
||||
use kitchen_fridge::task::CompletionStatus;
|
||||
|
@ -81,27 +81,27 @@ async fn add_items_and_sync_again(provider: &mut CalDavProvider)
|
|||
pause();
|
||||
|
||||
// Create a new calendar...
|
||||
let new_calendar_id: CalendarId = EXAMPLE_CREATED_CALENDAR_URL.parse().unwrap();
|
||||
let new_calendar_url: Url = EXAMPLE_CREATED_CALENDAR_URL.parse().unwrap();
|
||||
let new_calendar_name = "A brave new calendar".to_string();
|
||||
if let Err(_err) = provider.local_mut()
|
||||
.create_calendar(new_calendar_id.clone(), new_calendar_name.clone(), SupportedComponents::TODO, None)
|
||||
.create_calendar(new_calendar_url.clone(), new_calendar_name.clone(), SupportedComponents::TODO, None)
|
||||
.await {
|
||||
println!("Unable to add calendar, maybe it exists already. We're not adding it after all.");
|
||||
}
|
||||
|
||||
// ...and add a task in it
|
||||
let new_name = "This is a new task in a new calendar";
|
||||
let new_task = Task::new(String::from(new_name), true, &new_calendar_id);
|
||||
provider.local().get_calendar(&new_calendar_id).await.unwrap()
|
||||
let new_task = Task::new(String::from(new_name), true, &new_calendar_url);
|
||||
provider.local().get_calendar(&new_calendar_url).await.unwrap()
|
||||
.lock().unwrap().add_item(Item::Task(new_task)).await.unwrap();
|
||||
|
||||
|
||||
// Also create a task in a previously existing calendar
|
||||
let changed_calendar_id: CalendarId = EXAMPLE_EXISTING_CALENDAR_URL.parse().unwrap();
|
||||
let changed_calendar_url: Url = EXAMPLE_EXISTING_CALENDAR_URL.parse().unwrap();
|
||||
let new_task_name = "This is a new task we're adding as an example, with ÜTF-8 characters";
|
||||
let new_task = Task::new(String::from(new_task_name), false, &changed_calendar_id);
|
||||
let new_task = Task::new(String::from(new_task_name), false, &changed_calendar_url);
|
||||
let new_url = new_task.url().clone();
|
||||
provider.local().get_calendar(&changed_calendar_id).await.unwrap()
|
||||
provider.local().get_calendar(&changed_calendar_url).await.unwrap()
|
||||
.lock().unwrap().add_item(Item::Task(new_task)).await.unwrap();
|
||||
|
||||
|
||||
|
@ -112,20 +112,20 @@ async fn add_items_and_sync_again(provider: &mut CalDavProvider)
|
|||
}
|
||||
provider.local().save_to_folder().unwrap();
|
||||
|
||||
complete_item_and_sync_again(provider, &changed_calendar_id, &new_url).await;
|
||||
complete_item_and_sync_again(provider, &changed_calendar_url, &new_url).await;
|
||||
}
|
||||
|
||||
async fn complete_item_and_sync_again(
|
||||
provider: &mut CalDavProvider,
|
||||
changed_calendar_id: &CalendarId,
|
||||
changed_calendar_url: &Url,
|
||||
url_to_complete: &Url)
|
||||
{
|
||||
println!("\nNow, we'll mark this last task as completed, and run the sync again.");
|
||||
pause();
|
||||
|
||||
let completion_status = CompletionStatus::Completed(Some(Utc::now()));
|
||||
provider.local().get_calendar(changed_calendar_id).await.unwrap()
|
||||
.lock().unwrap().get_item_by_id_mut(url_to_complete).await.unwrap()
|
||||
provider.local().get_calendar(changed_calendar_url).await.unwrap()
|
||||
.lock().unwrap().get_item_by_url_mut(url_to_complete).await.unwrap()
|
||||
.unwrap_task_mut()
|
||||
.set_completion_status(completion_status);
|
||||
|
||||
|
@ -136,19 +136,19 @@ async fn complete_item_and_sync_again(
|
|||
}
|
||||
provider.local().save_to_folder().unwrap();
|
||||
|
||||
remove_items_and_sync_again(provider, changed_calendar_id, url_to_complete).await;
|
||||
remove_items_and_sync_again(provider, changed_calendar_url, url_to_complete).await;
|
||||
}
|
||||
|
||||
async fn remove_items_and_sync_again(
|
||||
provider: &mut CalDavProvider,
|
||||
changed_calendar_id: &CalendarId,
|
||||
changed_calendar_url: &Url,
|
||||
id_to_remove: &Url)
|
||||
{
|
||||
println!("\nNow, we'll delete this last task, and run the sync again.");
|
||||
pause();
|
||||
|
||||
// Remove the task we had created
|
||||
provider.local().get_calendar(changed_calendar_id).await.unwrap()
|
||||
provider.local().get_calendar(changed_calendar_url).await.unwrap()
|
||||
.lock().unwrap()
|
||||
.mark_for_deletion(id_to_remove).await.unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue