Add example model, route and logic for development testing and boilerplate
This commit is contained in:
parent
f1cd1e8bfa
commit
cac002e3e6
11 changed files with 80 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
from pydantic_settings import BaseSettings
|
||||
|
||||
class Settings(BaseSettings):
|
||||
|
||||
app_name: str = "DagemarkBackend"
|
||||
|
||||
app_version: str = "0.1"
|
||||
|
||||
database_url: str = "sqlite:///data/app.db"
|
||||
|
||||
debug: bool = True
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
|
||||
settings = Settings()
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
from sqlmodel import SQLModel, create_engine
|
||||
|
||||
from app.config import settings
|
||||
|
||||
engine = create_engine(
|
||||
settings.database_url,
|
||||
connect_args={"check_same_thread": False},
|
||||
)
|
||||
|
||||
def create_database():
|
||||
SQLModel.metadata.create_all(engine)
|
||||
5
app/logic/example_logic.py
Normal file
5
app/logic/example_logic.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def get_example_message():
|
||||
|
||||
return {
|
||||
"message": "Hello, this is an example response :]"
|
||||
}
|
||||
18
app/main.py
18
app/main.py
|
|
@ -0,0 +1,18 @@
|
|||
from fastapi import FastAPI
|
||||
|
||||
from app.config import settings
|
||||
from app.database import create_database
|
||||
from app.routers import example_route
|
||||
|
||||
app = FastAPI(
|
||||
title=settings.app_name,
|
||||
version=settings.app_version
|
||||
)
|
||||
|
||||
@app.on_event("startup")
|
||||
def startup():
|
||||
create_database()
|
||||
|
||||
app.include_router(
|
||||
example_route.router
|
||||
)
|
||||
12
app/models/example_model.py
Normal file
12
app/models/example_model.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from sqlmodel import SQLModel, Field
|
||||
|
||||
class ExampleModel(SQLModel, table=True):
|
||||
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
example_text: str
|
||||
|
||||
example_number: int
|
||||
1
app/models/init.py
Normal file
1
app/models/init.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .example_model import ExampleModel
|
||||
15
app/routers/example_route.py
Normal file
15
app/routers/example_route.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from fastapi import APIRouter
|
||||
|
||||
from app.logic.example_logic import get_example_message
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/example",
|
||||
tags=["Example"]
|
||||
)
|
||||
|
||||
@router.get("/")
|
||||
def get_example():
|
||||
|
||||
return(
|
||||
get_example_message()
|
||||
)
|
||||
2
src/dagemark_backend/__init__.py
Normal file
2
src/dagemark_backend/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def main() -> None:
|
||||
print("Hello from dagemark-backend!")
|
||||
Loading…
Reference in a new issue