diff --git a/backend/__pycache__/database.cpython-311.pyc b/backend/__pycache__/database.cpython-311.pyc new file mode 100644 index 0000000..baf9784 Binary files /dev/null and b/backend/__pycache__/database.cpython-311.pyc differ diff --git a/backend/__pycache__/main.cpython-311.pyc b/backend/__pycache__/main.cpython-311.pyc new file mode 100644 index 0000000..387bfa1 Binary files /dev/null and b/backend/__pycache__/main.cpython-311.pyc differ diff --git a/backend/database.py b/backend/database.py index c47173a..daf1fb9 100644 --- a/backend/database.py +++ b/backend/database.py @@ -74,4 +74,4 @@ if __name__ == "__main__": for table in tables: print("-", table["name"]) else: - print("Geen tabellen gevonden.") \ No newline at end of file + print("Geen tabellen gevonden.") diff --git a/backend/events.py b/backend/events.py index e69de29..a45ac85 100644 --- a/backend/events.py +++ b/backend/events.py @@ -0,0 +1,69 @@ +from database import execute + +def create_event( + room_id, + creator_id, + event_type, + title, + description, + start_time, + end_time, + visibility, + status, + min_people +): + query = """ + INSERT INTO events ( + room_id, + creator_id, + type, + title, + description, + start_time, + end_time, + visibility, + status, + min_people + ) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + """ + + event_id = execute( + query, + ( + room_id, + creator_id, + event_type, + title, + description, + start_time, + end_time, + visibility, + status, + min_people + ) + ) + + return event_id + + +# voorbeeld create_event. alleen voor deocumentatie, +# als je echt een event toe wil voegen, moet je data +# uit de fastapi halen. +# +# +# event = create_event( +# room_id=2, +# creator_id=3, +# event_type="proposal", +# title="Kaas eten", +# description="We gaan met z'n allen kaas eten.", +# start_time="2026-08-10 19:00", +# end_time="2026-08-10 21:00", +# visibility="room", +# status="proposed", +# min_people=4 +# ) + +# print("Nieuw event ID:", event) + \ No newline at end of file diff --git a/backend/main.py b/backend/main.py index 43cc70f..3d0ab7c 100644 --- a/backend/main.py +++ b/backend/main.py @@ -4,6 +4,7 @@ from fastapi import FastAPI from database import fetch_all +from events.py import create_event app = FastAPI( title="Calendar API", @@ -30,3 +31,5 @@ def database_status(): "tables": [table["name"] for table in tables] } +@app.ge("/events") +def create_events(): diff --git a/database/calendar.db b/database/calendar.db index 77a865a..1f7b0dc 100644 Binary files a/database/calendar.db and b/database/calendar.db differ diff --git a/database/calendar.db-journal b/database/calendar.db-journal new file mode 100644 index 0000000..a63a7fa Binary files /dev/null and b/database/calendar.db-journal differ diff --git a/database/testdata.sql b/database/testdata.sql new file mode 100644 index 0000000..f20cd2d --- /dev/null +++ b/database/testdata.sql @@ -0,0 +1,52 @@ +INSERT INTO users (username, password_hash) +VALUES +('ben', 'hash1'), +('jan', 'hash2'), +('piet', 'hash3'); + + +INSERT INTO rooms (name, owner_id, invite_code) +VALUES +('Vriendengroep', 1, 'ABC123'), +('Projectgroep', 2, 'XYZ789'); + + +INSERT INTO room_members (room_id, user_id, role) +VALUES +(1, 1, 'owner'), +(1, 2, 'member'), +(1, 3, 'member'), +(2, 2, 'owner'); + + +INSERT INTO events ( + room_id, + creator_id, + type, + title, + description, + start_time, + end_time, + visibility, + status, + min_people +) +VALUES +( + 1, + 1, + 'proposal', + 'Bowlen', + 'Avondje bowlen', + '2026-08-10 19:00', + '2026-08-10 22:00', + 'room', + 'proposed', + 3 +); + + +INSERT INTO event_signups (event_id, user_id, status) +VALUES +(1, 1, 'going'), +(1, 2, 'going');