mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 07:02:24 +00:00
Initial commit
This commit is contained in:
2256
crates/api/Cargo.lock
generated
Normal file
2256
crates/api/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
crates/api/Cargo.toml
Normal file
12
crates/api/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "rustical_api"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4.4.0"
|
||||
anyhow = { version = "1.0.75", features = ["backtrace"] }
|
||||
rustical_store = { path = "../store/" }
|
||||
serde = "1.0.188"
|
||||
serde_json = "1.0.105"
|
||||
tokio = { version = "1.32.0", features = ["sync"] }
|
||||
30
crates/api/src/lib.rs
Normal file
30
crates/api/src/lib.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use actix_web::{
|
||||
http::Method,
|
||||
web::{self, Data, Path},
|
||||
Responder,
|
||||
};
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub fn configure_api<C: CalendarStore>(cfg: &mut web::ServiceConfig, store: Data<RwLock<C>>) {
|
||||
cfg.app_data(store)
|
||||
.route("ping", web::method(Method::GET).to(get_ping::<C>))
|
||||
.route(
|
||||
"/{cid}/events",
|
||||
web::method(Method::GET).to(get_events::<C>),
|
||||
);
|
||||
}
|
||||
|
||||
pub async fn get_events<C: CalendarStore>(
|
||||
store: Data<RwLock<C>>,
|
||||
path: Path<String>,
|
||||
) -> impl Responder {
|
||||
let cid = path.into_inner();
|
||||
let events = store.read().await.get_events(&cid).await.unwrap();
|
||||
serde_json::to_string_pretty(&events)
|
||||
}
|
||||
|
||||
pub async fn get_ping<C: CalendarStore>(store: Data<RwLock<C>>) -> impl Responder {
|
||||
let cals = store.read().await.get_calendars().await.unwrap();
|
||||
serde_json::to_string_pretty(&cals)
|
||||
}
|
||||
Reference in New Issue
Block a user