Add demo button to deposit money
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
from fastapi import APIRouter, Request
|
||||
import os
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
from fastapi.responses import RedirectResponse
|
||||
from starlette import status
|
||||
|
||||
from allmende_payment_system.api.dependencies import SessionDep, UserDep
|
||||
from allmende_payment_system.models import Transaction
|
||||
from allmende_payment_system.tools import get_jinja_renderer
|
||||
|
||||
root_router = APIRouter()
|
||||
@@ -31,3 +36,22 @@ async def landing_page(
|
||||
"focused_account": focused_account,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@root_router.get("/demo/add_balance/{account_id}")
|
||||
async def add_balance(
|
||||
request: Request, session: SessionDep, user: UserDep, account_id: int
|
||||
):
|
||||
if "APS_PRODUCTION_MODE" in os.environ:
|
||||
raise HTTPException(status_code=403, detail="Not allowed in production mode.")
|
||||
|
||||
for account in user.accounts:
|
||||
if account.id == account_id:
|
||||
break
|
||||
else:
|
||||
raise HTTPException(status_code=400, detail="Invalid account ID.")
|
||||
|
||||
account.transactions.append(Transaction(total_amount=100.0, type="deposit"))
|
||||
session.flush()
|
||||
|
||||
return RedirectResponse(url=f"/", status_code=status.HTTP_302_FOUND)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import os
|
||||
|
||||
from sqlalchemy import create_engine, select
|
||||
from sqlalchemy.orm import Session, sessionmaker
|
||||
|
||||
from allmende_payment_system.models import User, Account, Transaction
|
||||
from allmende_payment_system.models import Account, Transaction, User
|
||||
|
||||
SQLALCHEMY_DATABASE_URL = "sqlite:///./aps_db.db"
|
||||
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
||||
|
||||
@@ -80,6 +80,7 @@
|
||||
<div class="alert alert-primary" role="alert">
|
||||
<h2> Testmodus 🚧</h2>
|
||||
<p>Die hier dargestellten Produkte, Konten und Transaktionen entsprechen keinen echten. Bitte noch keine wirklichen Abrechnungen vornehmen!</p>
|
||||
<p>Schaltflächen mit dem 🚧-Symbol stellen Demo-Funktionen dar, die es im Echtbetrieb nicht mehr geben wird.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% block content %}
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
<p class="h3 mb-2 {% if account.balance < 0 %}text-danger{% else %}text-success{% endif %}">
|
||||
{{ account.balance | format_number }} €
|
||||
</p>
|
||||
{% if user.accounts|length > 1 and (not focused_account or (focused_account.id != account.id)) %}
|
||||
<div class="d-flex gap-2 mt-3">
|
||||
{% if user.accounts|length > 1 and (not focused_account or (focused_account.id != account.id)) %}
|
||||
<a href="/?account_id={{ account.id }}" class="btn btn-sm btn-outline-primary">Transaktionen ansehen</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
<a href="/demo/add_balance/{{ account.id }}" class="btn btn-sm btn-outline-primary">🚧 100 € einzahlen 🚧</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user