Add project setup some models and a test
This commit is contained in:
0
src/allmende_payment_system/api/__init__.py
Normal file
0
src/allmende_payment_system/api/__init__.py
Normal file
@@ -1,11 +1,16 @@
|
||||
# backend/app/main.py
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
app = FastAPI()
|
||||
templates = Jinja2Templates(directory="src/allmende_payment_system/templates")
|
||||
app.mount("/static", StaticFiles(directory="src/allmende_payment_system/static"), name="static")
|
||||
app.mount(
|
||||
"/static",
|
||||
StaticFiles(directory="src/allmende_payment_system/static"),
|
||||
name="static",
|
||||
)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
async def landing_page(request: Request):
|
||||
|
||||
6
src/allmende_payment_system/database.py
Normal file
6
src/allmende_payment_system/database.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
SQLALCHEMY_DATABASE_URL = "sqlite:///./aps_db.db"
|
||||
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
39
src/allmende_payment_system/models.py
Normal file
39
src/allmende_payment_system/models.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from sqlalchemy import Column, ForeignKey, Table
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
||||
|
||||
TABLE_PREFIX = "aps_"
|
||||
|
||||
|
||||
class Base(DeclarativeBase):
|
||||
pass
|
||||
|
||||
|
||||
class Account(Base):
|
||||
__tablename__ = TABLE_PREFIX + "account"
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
name: Mapped[str] = mapped_column(nullable=False, unique=True)
|
||||
|
||||
users: Mapped[list["User"]] = relationship(
|
||||
"User",
|
||||
secondary=TABLE_PREFIX + "user_account_association",
|
||||
back_populates="accounts",
|
||||
)
|
||||
|
||||
|
||||
user_account_association = Table(
|
||||
TABLE_PREFIX + "user_account_association",
|
||||
Base.metadata,
|
||||
Column("user_id", ForeignKey(TABLE_PREFIX + "user.id"), primary_key=True),
|
||||
Column("account_id", ForeignKey(TABLE_PREFIX + "account.id"), primary_key=True),
|
||||
)
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = TABLE_PREFIX + "user"
|
||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||
username: Mapped[str] = mapped_column(nullable=False, unique=True)
|
||||
display_name: Mapped[str] = mapped_column(nullable=False)
|
||||
|
||||
accounts: Mapped[list["Account"]] = relationship(
|
||||
"Account", secondary=user_account_association, back_populates="users"
|
||||
)
|
||||
BIN
src/allmende_payment_system/static/img/Logo.png
Normal file
BIN
src/allmende_payment_system/static/img/Logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
@@ -15,7 +15,7 @@
|
||||
<div class="col-md-3 col-lg-2 p-0 sidebar">
|
||||
<div class="d-flex flex-column p-3">
|
||||
<a href="/" class="navbar-brand d-flex align-items-center mb-4">
|
||||
<img src="https://via.placeholder.com/40" alt="Logo" class="me-2">
|
||||
<img src="/static/img/Logo.png" alt="Logo" class="me-2">
|
||||
<span class="fs-4">APS</span>
|
||||
</a>
|
||||
<ul class="nav nav-pills flex-column mb-auto">
|
||||
|
||||
Reference in New Issue
Block a user