All day event
This commit is contained in:
24
Cargo.lock
generated
24
Cargo.lock
generated
@ -125,18 +125,6 @@ version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
|
||||
|
||||
[[package]]
|
||||
name = "caldendar-api"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"chrono",
|
||||
"icalendar",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.37"
|
||||
@ -537,6 +525,18 @@ version = "5.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
|
||||
[[package]]
|
||||
name = "recurring-event-api"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"chrono",
|
||||
"icalendar",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.26"
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "caldendar-api"
|
||||
name = "recurring-event-api"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
|
33
src/main.rs
33
src/main.rs
@ -8,6 +8,8 @@ use icalendar::{Calendar, Class, Component, Event, EventLike};
|
||||
use serde::Deserialize;
|
||||
use std::ops::Sub;
|
||||
|
||||
const TEXT_CALENDAR: &'static str = "text/calendar";
|
||||
|
||||
#[derive(Deserialize)]
|
||||
enum Recurring {
|
||||
Daily,
|
||||
@ -81,8 +83,6 @@ async fn get_calendar(Query(query): Query<EventQuery>) -> impl IntoResponse {
|
||||
))
|
||||
}
|
||||
|
||||
const TEXT_CALENDAR: &'static str = "text/calendar";
|
||||
|
||||
async fn get_ics(Query(query): Query<EventQuery>) -> impl IntoResponse {
|
||||
let start = query.start_date_time;
|
||||
let end = query
|
||||
@ -97,13 +97,15 @@ async fn get_ics(Query(query): Query<EventQuery>) -> impl IntoResponse {
|
||||
query.avoid_weekends.unwrap_or(false),
|
||||
)
|
||||
.into_iter()
|
||||
.for_each(|date| {
|
||||
calendar.push(
|
||||
Event::new()
|
||||
.summary(&query.title)
|
||||
.starts(date)
|
||||
.class(Class::Confidential),
|
||||
);
|
||||
.for_each(|date_time| {
|
||||
let mut event = Event::new();
|
||||
if query.all_day {
|
||||
event.all_day(date_time.date());
|
||||
} else {
|
||||
event.starts(date_time);
|
||||
};
|
||||
event.summary(&query.title).class(Class::Private);
|
||||
calendar.push(event);
|
||||
});
|
||||
|
||||
Response::builder()
|
||||
@ -127,16 +129,15 @@ fn get_dates(
|
||||
Recurring::Weeky => todo!(),
|
||||
Recurring::BiWeekly => todo!(),
|
||||
Recurring::Monthly => {
|
||||
let new_date = baseline.checked_add_months(Months::new(1)).unwrap();
|
||||
baseline = new_date;
|
||||
baseline = baseline.checked_add_months(Months::new(1)).unwrap();
|
||||
if let true = avoid_weekends {
|
||||
match new_date.weekday() {
|
||||
Weekday::Sat => new_date.sub(TimeDelta::days(1)),
|
||||
Weekday::Sun => new_date.sub(TimeDelta::days(2)),
|
||||
_ => new_date,
|
||||
match baseline.weekday() {
|
||||
Weekday::Sat => baseline.sub(TimeDelta::days(1)),
|
||||
Weekday::Sun => baseline.sub(TimeDelta::days(2)),
|
||||
_ => baseline,
|
||||
}
|
||||
} else {
|
||||
new_date
|
||||
baseline
|
||||
}
|
||||
}
|
||||
Recurring::Quarterly => todo!(),
|
||||
|
Reference in New Issue
Block a user