update main.py for swaggerui
This commit is contained in:
+30
-35
@@ -1,11 +1,23 @@
|
|||||||
# Python backend for a calender for my friend group.
|
from fastapi import FastAPI
|
||||||
# We had the problem of never agreeing when or where
|
from pydantic import BaseModel
|
||||||
# we should meet up, and I hope this fixes the problem.
|
|
||||||
|
|
||||||
from fastapi import FastAPI, Request
|
|
||||||
from database import fetch_all
|
from database import fetch_all
|
||||||
from events import create_event
|
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(
|
app = FastAPI(
|
||||||
title="Calendar API",
|
title="Calendar API",
|
||||||
description="Room based agenda system",
|
description="Room based agenda system",
|
||||||
@@ -31,45 +43,28 @@ def database_status():
|
|||||||
"tables": [table["name"] for table in tables]
|
"tables": [table["name"] for table in tables]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@app.post("/events")
|
@app.post("/events")
|
||||||
async def api_create_event(request: Request):
|
def api_create_event(event: EventCreate):
|
||||||
data = await request.json()
|
|
||||||
|
|
||||||
print(data)
|
|
||||||
|
|
||||||
|
|
||||||
event_id = create_event(
|
event_id = create_event(
|
||||||
room_id=data["room_id"],
|
room_id=event.room_id,
|
||||||
creator_id=data["creator_id"],
|
creator_id=event.creator_id,
|
||||||
type=data["type"],
|
type=event.type,
|
||||||
title=data["title"],
|
title=event.title,
|
||||||
description=data["description"],
|
description=event.description,
|
||||||
start_time=data["start_time"],
|
start_time=event.start_time,
|
||||||
end_time=data["end_time"],
|
end_time=event.end_time,
|
||||||
visibility=data["visibility"],
|
visibility=event.visibility,
|
||||||
status=data["status"],
|
status=event.status,
|
||||||
min_people=data["min_people"]
|
min_people=event.min_people
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
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")
|
@app.get("/events")
|
||||||
def get_events():
|
def get_events():
|
||||||
|
|||||||
+21
-1
@@ -1 +1,21 @@
|
|||||||
python3 -m uvicorn main:app --reload
|
#!/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.
Reference in New Issue
Block a user