mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 19:22:26 +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
|
||||
.write()
|
||||
.await
|
||||
.delete_event(&uid)
|
||||
.delete_event(&cid, &uid)
|
||||
.await
|
||||
.map_err(|_e| Error::InternalError)?;
|
||||
|
||||
@@ -32,12 +32,15 @@ pub async fn get_event<A: CheckAuthentication, C: CalendarStore>(
|
||||
_auth: AuthInfoExtractor<A>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
// 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
|
||||
.store
|
||||
.read()
|
||||
.await
|
||||
.get_event(&uid)
|
||||
.get_event(&cid, &uid)
|
||||
.await
|
||||
.map_err(|_e| Error::NotFound)?;
|
||||
|
||||
@@ -63,7 +66,7 @@ pub async fn put_event<A: CheckAuthentication, C: CalendarStore>(
|
||||
.store
|
||||
.write()
|
||||
.await
|
||||
.upsert_event(uid, body)
|
||||
.upsert_event(cid, uid, body)
|
||||
.await
|
||||
.map_err(|_e| Error::InternalError)?;
|
||||
|
||||
|
||||
@@ -88,23 +88,38 @@ impl CalendarStore for TomlCalendarStore {
|
||||
.collect())
|
||||
}
|
||||
|
||||
async fn get_events(&self, _cid: &str) -> Result<Vec<Event>> {
|
||||
Ok(self.events.values().cloned().collect())
|
||||
async fn get_events(&self, cid: &str) -> Result<Vec<Event>> {
|
||||
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> {
|
||||
Ok(self.events.get(uid).ok_or(anyhow!("not found"))?.clone())
|
||||
async fn get_event(&self, cid: &str, uid: &str) -> Result<Event> {
|
||||
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<()> {
|
||||
self.events.insert(uid.clone(), Event { uid, ics });
|
||||
async fn upsert_event(&mut self, cid: String, uid: String, ics: String) -> Result<()> {
|
||||
let events = self.events.entry(cid).or_insert(HashMap::new());
|
||||
events.insert(
|
||||
uid.clone(),
|
||||
Event {
|
||||
uid,
|
||||
ics,
|
||||
summary: None,
|
||||
},
|
||||
);
|
||||
self.save().await.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_event(&mut self, uid: &str) -> Result<()> {
|
||||
self.events.remove(uid);
|
||||
self.save().await?;
|
||||
async fn delete_event(&mut self, cid: &str, uid: &str) -> Result<()> {
|
||||
if let Some(events) = self.events.get_mut(cid) {
|
||||
events.remove(uid);
|
||||
self.save().await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user