From 69b3b9dab5cbc6625c958ac7a3b7e2491ead893e Mon Sep 17 00:00:00 2001
From: Badrudeen <badrudeen2.mohammed@live.uwe.ac.uk>
Date: Fri, 28 Mar 2025 13:56:00 +0000
Subject: [PATCH] first commit

---
 rust_crud_api/src/db/init.rs       | 28 +++++++++++++++++++++-------
 rust_crud_api/src/models/events.rs | 25 +++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 7 deletions(-)
 create mode 100644 rust_crud_api/src/models/events.rs

diff --git a/rust_crud_api/src/db/init.rs b/rust_crud_api/src/db/init.rs
index 9e090ac..377bcdb 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 0000000..d7ab003
--- /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
-- 
GitLab