update main.py for swaggerui

This commit is contained in:
ben
2026-08-03 11:08:47 +02:00
parent 0e91f3c1f2
commit a7dc906fd7
4 changed files with 52 additions and 40 deletions
+30 -35
View File
@@ -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():
+20
View File
@@ -1 +1,21 @@
#!/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
Binary file not shown.
-3
View File
@@ -1,3 +0,0 @@
__pycache__/
*.py[cod]
*.db-journal