initial commit
This commit is contained in:
0
app/__init__.py
Normal file
0
app/__init__.py
Normal file
0
app/api/__init__.py
Normal file
0
app/api/__init__.py
Normal file
13
app/api/deps.py
Normal file
13
app/api/deps.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from collections.abc import Generator
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import Depends
|
||||
from sqlmodel import Session
|
||||
|
||||
from app.core.db import engine
|
||||
|
||||
def get_db() -> Generator[Session, None, None]:
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
|
||||
SessionDep = Annotated[Session, Depends(get_db)]
|
||||
6
app/api/main.py
Normal file
6
app/api/main.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.api.routes import registration
|
||||
|
||||
api_router = APIRouter()
|
||||
api_router.include_router(registration.router)
|
||||
0
app/api/routes/__init__.py
Normal file
0
app/api/routes/__init__.py
Normal file
31
app/api/routes/registration.py
Normal file
31
app/api/routes/registration.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Form
|
||||
from app.models import RegistrationCreate
|
||||
from app import crud
|
||||
from app.api.deps import SessionDep
|
||||
|
||||
router = APIRouter(prefix="/registration")
|
||||
|
||||
|
||||
@router.post(
|
||||
"/register",
|
||||
)
|
||||
def register(*, session: SessionDep, registration_create: Annotated[RegistrationCreate, Form()]):
|
||||
print(registration_create)
|
||||
"""
|
||||
Register
|
||||
"""
|
||||
|
||||
registration = crud.create_registration(session=session, registration_create=registration_create)
|
||||
#if settings.emails_enabled and user_in.email:
|
||||
# email_data = generate_new_account_email(
|
||||
# email_to=user_in.email, username=user_in.email, password=user_in.password
|
||||
# )
|
||||
# send_email(
|
||||
# email_to=user_in.email,
|
||||
# subject=email_data.subject,
|
||||
# html_content=email_data.html_content,
|
||||
# )
|
||||
|
||||
return registration
|
||||
0
app/core/__init__.py
Normal file
0
app/core/__init__.py
Normal file
10
app/core/config.py
Normal file
10
app/core/config.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
import os
|
||||
|
||||
class Settings(BaseSettings):
|
||||
API_V1_STR: str = ""
|
||||
PROJECT_NAME: str = "Choriosity Anmeldung"
|
||||
SQLALCHEMY_DATABASE_URI: str = "sqlite:///" + os.environ.get("DATABASE_URL", "./db.sqlite")
|
||||
|
||||
|
||||
settings = Settings()
|
||||
19
app/core/db.py
Normal file
19
app/core/db.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from sqlmodel import Session, create_engine
|
||||
from app.core.config import settings
|
||||
from app.models import Registration, RegistrationCreate
|
||||
|
||||
engine = create_engine(str(settings.SQLALCHEMY_DATABASE_URI))
|
||||
|
||||
|
||||
# make sure all SQLModel models are imported (app.models) before initializing DB
|
||||
# otherwise, SQLModel might fail to initialize relationships properly
|
||||
# for more details: https://github.com/fastapi/full-stack-fastapi-template/issues/28
|
||||
|
||||
def init_db(session: Session) -> None:
|
||||
# Tables should be created with Alembic migrations
|
||||
# But if you don't want to use migrations, create
|
||||
# the tables un-commenting the next lines
|
||||
from sqlmodel import SQLModel
|
||||
|
||||
# This works because the models are already imported and registered from app.models
|
||||
SQLModel.metadata.create_all(engine)
|
||||
11
app/crud.py
Normal file
11
app/crud.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from sqlmodel import Session
|
||||
|
||||
from app.models import Registration, RegistrationCreate
|
||||
|
||||
|
||||
def create_registration(*, session: Session, registration_create: RegistrationCreate) -> Registration:
|
||||
db_obj = Registration.model_validate(registration_create)
|
||||
session.add(db_obj)
|
||||
session.commit()
|
||||
session.refresh(db_obj)
|
||||
return db_obj
|
||||
79
app/index.html
Normal file
79
app/index.html
Normal file
@@ -0,0 +1,79 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Choriosity Anmeldung</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<form method="POST" action="/registration/register">
|
||||
|
||||
|
||||
<label for="email">E-Mail-Adresse:</label> <input type="email" id="email" name="email" />
|
||||
<label for="first_name">Dein Vorname:</label> <input type="text" id="first_name" name="first_name" />
|
||||
<label for="last_name">Dein Nachname:</label> <input type="text" id="last_name" name="last_name" />
|
||||
<label for="birthday">Dein Geburtstag:</label> <input type="date" id="birthday" name="birthday" />
|
||||
|
||||
<fieldset>
|
||||
<legend>Welche Stimme singst du?</legend>
|
||||
|
||||
<div>
|
||||
<input type="radio" id="base" name="voice" value="Bass" checked />
|
||||
<label for="base">Bass</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input type="radio" id="tenor" name="voice" value="Tenor" checked />
|
||||
<label for="tenor">Tenor</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input type="radio" id="alto" name="voice" value="Alt" checked />
|
||||
<label for="alto">Alt</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input type="radio" id="soprano" name="voice" value="Sopran" checked />
|
||||
<label for="soprano">Sopran</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input type="radio" id="women" name="voice" value="Alt oder Sopran" checked />
|
||||
<label for="women">Sopran oder Alt</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input type="radio" id="men" name="voice" value="Bass oder Tenor" checked />
|
||||
<label for="men">Bass oder Tenor</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<fieldset>
|
||||
<legend>Wie lange bleibst du in Ulm?</legend>
|
||||
|
||||
<div>
|
||||
<input type="radio" id="halfyear" name="duration" value="1/2 Jahr" checked />
|
||||
<label for="halfyear">1/2 Jahr</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input type="radio" id="halfyear" name="duration" value="1/2 - 1 Jahr" checked />
|
||||
<label for="halfyear">1/2 - 1 Jahr</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input type="radio" id="twoyears" name="duration" value="1 - 2 Jahre" checked />
|
||||
<label for="twoyears">1 - 2 jahre</label>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input type="radio" id="longterm" name="duration" value="mehr als zwei Jahre" checked />
|
||||
<label for="longterm">länger als 2 Jahre</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<input type="submit" value="Anmelden" />
|
||||
|
||||
</form>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
25
app/main.py
Normal file
25
app/main.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from fastapi import FastAPI
|
||||
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
from app.api.main import api_router
|
||||
from app.core.config import settings
|
||||
|
||||
from app.core.db import init_db, engine
|
||||
|
||||
from sqlmodel import Session
|
||||
|
||||
with Session(engine) as session:
|
||||
init_db(session)
|
||||
|
||||
app = FastAPI(
|
||||
title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json"
|
||||
)
|
||||
|
||||
@api_router.get("/")
|
||||
def index():
|
||||
return FileResponse("app/index.html")
|
||||
|
||||
app.include_router(api_router, prefix=settings.API_V1_STR)
|
||||
|
||||
|
||||
42
app/models.py
Normal file
42
app/models.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import uuid
|
||||
|
||||
from pydantic import EmailStr
|
||||
from sqlmodel import Field, SQLModel
|
||||
from enum import Enum
|
||||
|
||||
from datetime import date, datetime
|
||||
|
||||
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
|
||||
class VoiceEnum(str, Enum):
|
||||
base = "Bass"
|
||||
tenor = "Tenor"
|
||||
alto = "Alt"
|
||||
soprano = "Sopran"
|
||||
men = "Bass oder Tenor"
|
||||
women = "Alt oder Sopran"
|
||||
|
||||
|
||||
class PeriodEnum(str, Enum):
|
||||
halfyear = "1/2 Jahr"
|
||||
year = "1/2 - 1 Jahr"
|
||||
twoyears = "1 - 2 Jahre"
|
||||
longterm = "mehr als zwei Jahre"
|
||||
|
||||
class RegistrationBase(SQLModel):
|
||||
email: EmailStr = Field(unique=True, index=True, max_length=255)
|
||||
first_name: str
|
||||
last_name: str
|
||||
birthday: date
|
||||
voice: VoiceEnum
|
||||
duration: PeriodEnum
|
||||
|
||||
class RegistrationCreate(RegistrationBase):
|
||||
pass
|
||||
|
||||
class Registration(RegistrationBase, table=True):
|
||||
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
|
||||
timestamp: datetime = Field(default_factory=func.now)
|
||||
|
||||
Reference in New Issue
Block a user