mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 21:42:34 +00:00
obvious thing: not every event belongs to every calendar
This commit is contained in:
@@ -19,7 +19,7 @@ pub async fn delete_event<A: CheckAuthentication, C: CalendarStore>(
|
|||||||
.store
|
.store
|
||||||
.write()
|
.write()
|
||||||
.await
|
.await
|
||||||
.delete_event(&uid)
|
.delete_event(&cid, &uid)
|
||||||
.await
|
.await
|
||||||
.map_err(|_e| Error::InternalError)?;
|
.map_err(|_e| Error::InternalError)?;
|
||||||
|
|
||||||
@@ -32,12 +32,15 @@ pub async fn get_event<A: CheckAuthentication, C: CalendarStore>(
|
|||||||
_auth: AuthInfoExtractor<A>,
|
_auth: AuthInfoExtractor<A>,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, Error> {
|
||||||
// TODO: verify whether user is authorized
|
// TODO: verify whether user is authorized
|
||||||
|
let (_principal, cid, mut uid) = path.into_inner();
|
||||||
|
if uid.ends_with(".ics") {
|
||||||
|
uid.truncate(uid.len() - 4);
|
||||||
}
|
}
|
||||||
let event = context
|
let event = context
|
||||||
.store
|
.store
|
||||||
.read()
|
.read()
|
||||||
.await
|
.await
|
||||||
.get_event(&uid)
|
.get_event(&cid, &uid)
|
||||||
.await
|
.await
|
||||||
.map_err(|_e| Error::NotFound)?;
|
.map_err(|_e| Error::NotFound)?;
|
||||||
|
|
||||||
@@ -63,7 +66,7 @@ pub async fn put_event<A: CheckAuthentication, C: CalendarStore>(
|
|||||||
.store
|
.store
|
||||||
.write()
|
.write()
|
||||||
.await
|
.await
|
||||||
.upsert_event(uid, body)
|
.upsert_event(cid, uid, body)
|
||||||
.await
|
.await
|
||||||
.map_err(|_e| Error::InternalError)?;
|
.map_err(|_e| Error::InternalError)?;
|
||||||
|
|
||||||
|
|||||||
@@ -88,23 +88,38 @@ impl CalendarStore for TomlCalendarStore {
|
|||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_events(&self, _cid: &str) -> Result<Vec<Event>> {
|
async fn get_events(&self, cid: &str) -> Result<Vec<Event>> {
|
||||||
Ok(self.events.values().cloned().collect())
|
if let Some(events) = self.events.get(cid) {
|
||||||
|
Ok(events.values().cloned().collect())
|
||||||
|
} else {
|
||||||
|
Ok(Vec::new())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_event(&self, uid: &str) -> Result<Event> {
|
async fn get_event(&self, cid: &str, uid: &str) -> Result<Event> {
|
||||||
Ok(self.events.get(uid).ok_or(anyhow!("not found"))?.clone())
|
let events = self.events.get(cid).ok_or(anyhow!("not found"))?;
|
||||||
|
Ok(events.get(uid).ok_or(anyhow!("not found"))?.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn upsert_event(&mut self, uid: String, ics: String) -> Result<()> {
|
async fn upsert_event(&mut self, cid: String, uid: String, ics: String) -> Result<()> {
|
||||||
self.events.insert(uid.clone(), Event { uid, ics });
|
let events = self.events.entry(cid).or_insert(HashMap::new());
|
||||||
|
events.insert(
|
||||||
|
uid.clone(),
|
||||||
|
Event {
|
||||||
|
uid,
|
||||||
|
ics,
|
||||||
|
summary: None,
|
||||||
|
},
|
||||||
|
);
|
||||||
self.save().await.unwrap();
|
self.save().await.unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete_event(&mut self, uid: &str) -> Result<()> {
|
async fn delete_event(&mut self, cid: &str, uid: &str) -> Result<()> {
|
||||||
self.events.remove(uid);
|
if let Some(events) = self.events.get_mut(cid) {
|
||||||
self.save().await?;
|
events.remove(uid);
|
||||||
|
self.save().await?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user