Rename Event -> Scheduling for readability
This commit is contained in:
parent
e6288cfde1
commit
f2eadbae2b
3 changed files with 28 additions and 25 deletions
|
@ -4,12 +4,13 @@
|
|||
use {
|
||||
crate::api_client::ApiClient,
|
||||
crate::commands::import,
|
||||
crate::event::{Event, Meal},
|
||||
crate::recipe,
|
||||
crate::scheduling::{Meal, Scheduling},
|
||||
crate::{constants, helpers},
|
||||
anyhow::{bail, Result},
|
||||
chrono::naive::NaiveDate,
|
||||
futures::future::try_join_all,
|
||||
icalendar::Event,
|
||||
reqwest::StatusCode,
|
||||
std::collections::{HashMap, HashSet},
|
||||
std::fmt::Write,
|
||||
|
@ -41,22 +42,22 @@ pub async fn with(
|
|||
// so we have to resort to fetch all of them to match them
|
||||
let recipes = get_all_recipes(&api_client).await?;
|
||||
|
||||
let events = records
|
||||
let schedulings = records
|
||||
.iter()
|
||||
.flat_map(|r| {
|
||||
let lunch = recipes.get(&r.lunch);
|
||||
let dinner = recipes.get(&r.dinner);
|
||||
|
||||
let events = [
|
||||
lunch.map(|recipe| Event::new(r.day, Meal::Lunch, recipe.clone())),
|
||||
dinner.map(|recipe| Event::new(r.day, Meal::Dinner, recipe.clone())),
|
||||
let to_schedule = [
|
||||
lunch.map(|recipe| Scheduling::new(r.day, Meal::Lunch, recipe.clone())),
|
||||
dinner.map(|recipe| Scheduling::new(r.day, Meal::Dinner, recipe.clone())),
|
||||
];
|
||||
|
||||
events
|
||||
to_schedule
|
||||
})
|
||||
.flatten();
|
||||
|
||||
publish_events(&api_client, calendar, events, yearly_recurring_events).await?;
|
||||
publish_events(&api_client, calendar, schedulings, yearly_recurring_events).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -112,14 +113,14 @@ async fn get_all_recipes(api_client: &ApiClient) -> Result<HashMap<String, Rc<re
|
|||
))
|
||||
}
|
||||
|
||||
async fn publish_events<'a, EventsIter>(
|
||||
async fn publish_events<'a, SchedulingsIter>(
|
||||
api_client: &ApiClient,
|
||||
calendar: &str,
|
||||
events: EventsIter,
|
||||
schedulings: SchedulingsIter,
|
||||
yearly_recurring_events: bool,
|
||||
) -> Result<()>
|
||||
where
|
||||
EventsIter: Iterator<Item = Event>,
|
||||
SchedulingsIter: Iterator<Item = Scheduling>,
|
||||
{
|
||||
let calendar_url = api_client.caldav_base_url().join(&format!(
|
||||
"calendars/{}/{}/",
|
||||
|
@ -128,21 +129,23 @@ where
|
|||
))?;
|
||||
|
||||
let calendar_url = &calendar_url;
|
||||
let update_requests = events.map(|ev| async move {
|
||||
let url = calendar_url.join(&format!("{}.ics", ev.uid)).unwrap();
|
||||
let update_requests = schedulings.map(|scheduling| async move {
|
||||
let url = calendar_url
|
||||
.join(&format!("{}.ics", scheduling.uid))
|
||||
.unwrap();
|
||||
let alarm_text_repr = format!(
|
||||
"BEGIN:VALARM\nACTION:DISPLAY\nTRIGGER:-PT15M\nDESCRIPTION:{}\nEND:VALARM",
|
||||
&helpers::ical_escape_text(&ev.recipe.name)
|
||||
&helpers::ical_escape_text(&scheduling.recipe.name)
|
||||
);
|
||||
|
||||
let info_message = format!(
|
||||
"Saving event at {} for '{}'",
|
||||
&ev.ends_at.date(),
|
||||
&ev.recipe.name
|
||||
&scheduling.ends_at.date(),
|
||||
&scheduling.recipe.name
|
||||
);
|
||||
|
||||
let end_time = ev.ends_at;
|
||||
let mut event: icalendar::Event = ev.into();
|
||||
let end_time = scheduling.ends_at;
|
||||
let mut event: Event = scheduling.into();
|
||||
|
||||
if yearly_recurring_events {
|
||||
use chrono::Datelike;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue