diff --git a/rust_crud_api/src/db/init.rs b/rust_crud_api/src/db/init.rs index 9e090aca00dac164a115e7c1f2e7d9c6d947e2b3..377bcdb2d99f04c4d8927f36e38131e3d45f5b0f 100644 --- a/rust_crud_api/src/db/init.rs +++ b/rust_crud_api/src/db/init.rs @@ -23,25 +23,39 @@ pub fn init_db(db_url: &str) -> PyResult<()> { profilepicture VARCHAR, firstlogin BOOLEAN NOT NULL DEFAULT TRUE ); + CREATE TABLE IF NOT EXISTS groups ( id SERIAL PRIMARY KEY, name VARCHAR NOT NULL, member_count INTEGER DEFAULT 0 ); + CREATE TABLE IF NOT EXISTS group_members ( group_id INTEGER REFERENCES groups(id), user_id INTEGER REFERENCES users(id), PRIMARY KEY (group_id, user_id) ); + CREATE TABLE IF NOT EXISTS posts ( - id SERIAL PRIMARY KEY, - user_id INTEGER REFERENCES users(id), - group_id INTEGER REFERENCES groups(id), - content TEXT NOT NULL, - created_at TIMESTAMPTZ NOT NULL DEFAULT now() + id SERIAL PRIMARY KEY, + user_id INTEGER REFERENCES users(id), + group_id INTEGER REFERENCES groups(id), + content TEXT NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT now() + ); + + CREATE TABLE IF NOT EXISTS events ( + id SERIAL PRIMARY KEY, + title TEXT NOT NULL, + description TEXT, + location TEXT NOT NULL, + date DATE NOT NULL, + time TIME NOT NULL, + created_by INTEGER REFERENCES users(id), + group_id INTEGER REFERENCES groups(id), + created_at TIMESTAMPTZ NOT NULL DEFAULT now() ); " ).map_err(pg_err)?; Ok(()) -} - +} \ No newline at end of file diff --git a/rust_crud_api/src/models/events.rs b/rust_crud_api/src/models/events.rs new file mode 100644 index 0000000000000000000000000000000000000000..d7ab003147cbe52a84f33f8e96ad0b4bd4ee525f --- /dev/null +++ b/rust_crud_api/src/models/events.rs @@ -0,0 +1,25 @@ +use pyo3::prelude::*; +use serde::{Serialize, Deserialize}; + +#[pyclass] +#[derive(Serialize, Deserialize, Debug)] +pub struct Event { + #[pyo3(get, set)] + pub id: i32, + #[pyo3(get, set)] + pub title: String, + #[pyo3(get, set)] + pub description: Option<String>, + #[pyo3(get, set)] + pub location: String, + #[pyo3(get, set)] + pub date: String, // or NaiveDate + #[pyo3(get, set)] + pub time: String, // or NaiveTime + #[pyo3(get, set)] + pub created_by: i32, + #[pyo3(get, set)] + pub group_id: Option<i32>, + #[pyo3(get, set)] + pub created_at: String, +} \ No newline at end of file