mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 21:42:34 +00:00
Changed CalendarStore put_object interface
This commit is contained in:
@@ -6,6 +6,7 @@ use actix_web::web::{Data, Path};
|
|||||||
use actix_web::HttpRequest;
|
use actix_web::HttpRequest;
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
use rustical_auth::{AuthInfoExtractor, CheckAuthentication};
|
use rustical_auth::{AuthInfoExtractor, CheckAuthentication};
|
||||||
|
use rustical_store::model::CalendarObject;
|
||||||
use rustical_store::CalendarStore;
|
use rustical_store::CalendarStore;
|
||||||
|
|
||||||
pub async fn get_event<A: CheckAuthentication, C: CalendarStore + ?Sized>(
|
pub async fn get_event<A: CheckAuthentication, C: CalendarStore + ?Sized>(
|
||||||
@@ -94,7 +95,8 @@ pub async fn put_event<A: CheckAuthentication, C: CalendarStore + ?Sized>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
store.put_object(principal, cid, uid, body).await?;
|
let object = CalendarObject::from_ics(uid, body)?;
|
||||||
|
store.put_object(principal, cid, object).await?;
|
||||||
|
|
||||||
Ok(HttpResponse::Created().body(""))
|
Ok(HttpResponse::Created().body(""))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ pub trait CalendarStore: Send + Sync + 'static {
|
|||||||
&mut self,
|
&mut self,
|
||||||
principal: String,
|
principal: String,
|
||||||
cid: String,
|
cid: String,
|
||||||
uid: String,
|
object: CalendarObject,
|
||||||
ics: String,
|
|
||||||
) -> Result<(), Error>;
|
) -> Result<(), Error>;
|
||||||
async fn delete_object(
|
async fn delete_object(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|||||||
@@ -222,31 +222,24 @@ impl CalendarStore for SqliteCalendarStore {
|
|||||||
&mut self,
|
&mut self,
|
||||||
principal: String,
|
principal: String,
|
||||||
cid: String,
|
cid: String,
|
||||||
uid: String,
|
object: CalendarObject,
|
||||||
ics: String,
|
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let mut tx = self.db.begin().await?;
|
let mut tx = self.db.begin().await?;
|
||||||
|
|
||||||
// input validation
|
let (uid, ics) = (object.get_uid(), object.get_ics());
|
||||||
CalendarObject::from_ics(uid.to_owned(), ics.to_owned())?;
|
|
||||||
sqlx::query!(
|
sqlx::query!(
|
||||||
"REPLACE INTO calendarobjects (principal, cid, uid, ics) VALUES (?, ?, ?, ?)",
|
"REPLACE INTO calendarobjects (principal, cid, uid, ics) VALUES (?, ?, ?, ?)",
|
||||||
principal,
|
principal,
|
||||||
cid,
|
cid,
|
||||||
uid,
|
uid,
|
||||||
ics,
|
ics
|
||||||
)
|
)
|
||||||
.execute(&mut *tx)
|
.execute(&mut *tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
log_object_operation(
|
log_object_operation(&mut tx, &principal, &cid, uid, CalendarChangeOperation::Add).await?;
|
||||||
&mut tx,
|
|
||||||
&principal,
|
|
||||||
&cid,
|
|
||||||
&uid,
|
|
||||||
CalendarChangeOperation::Add,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use rstest::rstest;
|
use rstest::rstest;
|
||||||
use rstest_reuse::{self, apply, template};
|
use rstest_reuse::{self, apply, template};
|
||||||
use rustical_store::sqlite_store::create_test_store;
|
use rustical_store::sqlite_store::create_test_store;
|
||||||
use rustical_store::CalendarStore;
|
use rustical_store::{model::CalendarObject, CalendarStore};
|
||||||
|
|
||||||
const TIMEZONE: &str = include_str!("examples/timezone.ics");
|
const TIMEZONE: &str = include_str!("examples/timezone.ics");
|
||||||
const EVENT: &str = include_str!("examples/event.ics");
|
const EVENT: &str = include_str!("examples/event.ics");
|
||||||
@@ -36,13 +36,9 @@ async fn test_create_event<CS: CalendarStore>(mut store: CS) {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let object = CalendarObject::from_ics("asd".to_owned(), EVENT.to_owned()).unwrap();
|
||||||
store
|
store
|
||||||
.put_object(
|
.put_object("testuser".to_owned(), "test".to_owned(), object)
|
||||||
"testuser".to_owned(),
|
|
||||||
"test".to_owned(),
|
|
||||||
"asd".to_owned(),
|
|
||||||
EVENT.to_owned(),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user