From a7dc906fd73abccea4d269949066e9ea1bdb6a4e Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 3 Aug 2026 11:08:47 +0200 Subject: [PATCH] update main.py for swaggerui --- backend/main.py | 67 +++++++++++++++++++--------------------- backend/start_server.sh | 22 ++++++++++++- database/calendar.db | Bin 45056 -> 45056 bytes gitignore | 3 -- 4 files changed, 52 insertions(+), 40 deletions(-) delete mode 100644 gitignore diff --git a/backend/main.py b/backend/main.py index 186656a..fa20e00 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,11 +1,23 @@ -# Python backend for a calender for my friend group. -# We had the problem of never agreeing when or where -# we should meet up, and I hope this fixes the problem. +from fastapi import FastAPI +from pydantic import BaseModel -from fastapi import FastAPI, Request from database import fetch_all from events import create_event + +class EventCreate(BaseModel): + room_id: int + creator_id: int + type: str + title: str + description: str + start_time: str + end_time: str + visibility: str + status: str + min_people: int + + app = FastAPI( title="Calendar API", description="Room based agenda system", @@ -31,45 +43,28 @@ def database_status(): "tables": [table["name"] for table in tables] } + @app.post("/events") -async def api_create_event(request: Request): - data = await request.json() - - print(data) - +def api_create_event(event: EventCreate): event_id = create_event( - room_id=data["room_id"], - creator_id=data["creator_id"], - type=data["type"], - title=data["title"], - description=data["description"], - start_time=data["start_time"], - end_time=data["end_time"], - visibility=data["visibility"], - status=data["status"], - min_people=data["min_people"] + room_id=event.room_id, + creator_id=event.creator_id, + type=event.type, + title=event.title, + description=event.description, + start_time=event.start_time, + end_time=event.end_time, + visibility=event.visibility, + status=event.status, + min_people=event.min_people ) return { - "received": data - } + "status": "created", + "event_id": event_id + } -# def give_data(): -# event = create_event( -# room_id=, -# creator_id=, -# type=, -# title=, -# description=, -# start_time=, -# end_time=, -# visibility=, -# status=, -# min_people= -# ) - -# print("Nieuw event ID:", event) @app.get("/events") def get_events(): diff --git a/backend/start_server.sh b/backend/start_server.sh index 0470c69..81f4963 100755 --- a/backend/start_server.sh +++ b/backend/start_server.sh @@ -1 +1,21 @@ -python3 -m uvicorn main:app --reload \ No newline at end of file +#!/bin/bash + +echo "Waar wil je de Calendar API starten?" +echo "1) Lokaal " +echo "2) LAN " +read -p "Keuze [1/2]: " choice + +case $choice in + 1) + echo "Start lokaal..." + python3 -m uvicorn main:app --reload + ;; + 2) + echo "Start op LAN..." + python3 -m uvicorn main:app --host 0.0.0.0 --port 8000 --reload + ;; + *) + echo "Ongeldige keuze" + exit 1 + ;; +esac \ No newline at end of file diff --git a/database/calendar.db b/database/calendar.db index 1032ce16d09b1c9c7d25bedb61d61413055337e1..4cd3d6041bf26f9578832ec3d1d6a763d4775d73 100644 GIT binary patch delta 155 zcmZp8z|`=7X@WGP>O>i5M%9f8o%W1^n_t;WIS4WHJ!0Tr$#2K^h-V)JZWa_+#lytZ zu(45rDJDvghk=t(R$W(9Q&g6dsh}voAip>=$EiE-CH7_|oKRYuO!8bB6 gGSfBCHBd0Lv@$S2;Taa?=jTEUNln>o*MCR>0C(aq@Bjb+ delta 52 zcmZp8z|`=7X@WGP+(a2?M!Ag%o%W2}n_t;WIdC!Y+cEI3Hq)$ diff --git a/gitignore b/gitignore deleted file mode 100644 index 3c57703..0000000 --- a/gitignore +++ /dev/null @@ -1,3 +0,0 @@ -__pycache__/ -*.py[cod] -*.db-journal