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 1032ce1..4cd3d60 100644 Binary files a/database/calendar.db and b/database/calendar.db differ 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