Fixed formatting
This commit is contained in:
parent
bbdd41ef87
commit
e03eb3c82b
|
@ -43,7 +43,7 @@ async def api_wallet():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@core_app.put("/api/v1/wallet/<new_name>")
|
@core_app.put("/api/v1/wallet/{new_name}")
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_update_wallet(new_name: str):
|
async def api_update_wallet(new_name: str):
|
||||||
await update_wallet(g().wallet.id, new_name)
|
await update_wallet(g().wallet.id, new_name)
|
||||||
|
@ -260,7 +260,7 @@ async def api_payments_pay_lnurl(data: CreateLNURLData):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@core_app.get("/api/v1/payments/<payment_hash>")
|
@core_app.get("/api/v1/payments/{payment_hash}")
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_payment(payment_hash):
|
async def api_payment(payment_hash):
|
||||||
payment = await g().wallet.get_payment(payment_hash)
|
payment = await g().wallet.get_payment(payment_hash)
|
||||||
|
@ -334,7 +334,7 @@ async def api_payments_sse():
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@core_app.get("/api/v1/lnurlscan/<code>")
|
@core_app.get("/api/v1/lnurlscan/{code}")
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_lnurlscan(code: str):
|
async def api_lnurlscan(code: str):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -38,9 +38,9 @@ async def home(request: Request, lightning: str = None):
|
||||||
@core_app.get("/extensions")
|
@core_app.get("/extensions")
|
||||||
@validate_uuids(["usr"], required=True)
|
@validate_uuids(["usr"], required=True)
|
||||||
@check_user_exists()
|
@check_user_exists()
|
||||||
async def extensions():
|
async def extensions(enable: str, disable: str):
|
||||||
extension_to_enable = request.args.get("enable", type=str)
|
extension_to_enable = enable
|
||||||
extension_to_disable = request.args.get("disable", type=str)
|
extension_to_disable = disable
|
||||||
|
|
||||||
if extension_to_enable and extension_to_disable:
|
if extension_to_enable and extension_to_disable:
|
||||||
abort(
|
abort(
|
||||||
|
@ -177,7 +177,7 @@ async def deletewallet():
|
||||||
return redirect(url_for("core.home"))
|
return redirect(url_for("core.home"))
|
||||||
|
|
||||||
|
|
||||||
@core_app.get("/withdraw/notify/<service>")
|
@core_app.get("/withdraw/notify/{service}")
|
||||||
@validate_uuids(["wal"], required=True)
|
@validate_uuids(["wal"], required=True)
|
||||||
async def lnurl_balance_notify(service: str):
|
async def lnurl_balance_notify(service: str):
|
||||||
bc = await get_balance_check(request.args.get("wal"), service)
|
bc = await get_balance_check(request.args.get("wal"), service)
|
||||||
|
@ -204,7 +204,7 @@ async def lnurlwallet():
|
||||||
return redirect(url_for("core.wallet", usr=user.id, wal=wallet.id))
|
return redirect(url_for("core.wallet", usr=user.id, wal=wallet.id))
|
||||||
|
|
||||||
|
|
||||||
@core_app.get("/manifest/<usr>.webmanifest")
|
@core_app.get("/manifest/{usr}.webmanifest")
|
||||||
async def manifest(usr: str):
|
async def manifest(usr: str):
|
||||||
user = await get_user(usr)
|
user = await get_user(usr)
|
||||||
if not user:
|
if not user:
|
||||||
|
|
|
@ -10,7 +10,7 @@ from ..crud import get_standalone_payment
|
||||||
from ..tasks import api_invoice_listeners
|
from ..tasks import api_invoice_listeners
|
||||||
|
|
||||||
|
|
||||||
@core_app.get("/public/v1/payment/<payment_hash>")
|
@core_app.get("/public/v1/payment/{payment_hash}")
|
||||||
async def api_public_payment_longpolling(payment_hash):
|
async def api_public_payment_longpolling(payment_hash):
|
||||||
payment = await get_standalone_payment(payment_hash)
|
payment = await get_standalone_payment(payment_hash)
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ async def api_bleskomats():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bleskomat_ext.get("/api/v1/bleskomat/<bleskomat_id>")
|
@bleskomat_ext.get("/api/v1/bleskomat/{bleskomat_id}")
|
||||||
@api_check_wallet_key("admin")
|
@api_check_wallet_key("admin")
|
||||||
async def api_bleskomat_retrieve(bleskomat_id):
|
async def api_bleskomat_retrieve(bleskomat_id):
|
||||||
bleskomat = await get_bleskomat(bleskomat_id)
|
bleskomat = await get_bleskomat(bleskomat_id)
|
||||||
|
@ -58,7 +58,7 @@ class CreateData(BaseModel):
|
||||||
fee: Union[str, int, float] = Query(...)
|
fee: Union[str, int, float] = Query(...)
|
||||||
|
|
||||||
@bleskomat_ext.post("/api/v1/bleskomat")
|
@bleskomat_ext.post("/api/v1/bleskomat")
|
||||||
@bleskomat_ext.put("/api/v1/bleskomat/<bleskomat_id>")
|
@bleskomat_ext.put("/api/v1/bleskomat/{bleskomat_id}")
|
||||||
@api_check_wallet_key("admin")
|
@api_check_wallet_key("admin")
|
||||||
async def api_bleskomat_create_or_update(data: CreateData, bleskomat_id=None):
|
async def api_bleskomat_create_or_update(data: CreateData, bleskomat_id=None):
|
||||||
try:
|
try:
|
||||||
|
@ -93,7 +93,7 @@ async def api_bleskomat_create_or_update(data: CreateData, bleskomat_id=None):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bleskomat_ext.delete("/api/v1/bleskomat/<bleskomat_id>")
|
@bleskomat_ext.delete("/api/v1/bleskomat/{bleskomat_id}")
|
||||||
@api_check_wallet_key("admin")
|
@api_check_wallet_key("admin")
|
||||||
async def api_bleskomat_delete(bleskomat_id):
|
async def api_bleskomat_delete(bleskomat_id):
|
||||||
bleskomat = await get_bleskomat(bleskomat_id)
|
bleskomat = await get_bleskomat(bleskomat_id)
|
||||||
|
|
|
@ -5,7 +5,9 @@ from lnbits.decorators import check_user_exists, validate_uuids
|
||||||
|
|
||||||
from . import captcha_ext
|
from . import captcha_ext
|
||||||
from .crud import get_captcha
|
from .crud import get_captcha
|
||||||
|
from fastapi.templating import Jinja2Templates
|
||||||
|
from fastapi import Request
|
||||||
|
templates = Jinja2Templates(directory="templates")
|
||||||
|
|
||||||
@captcha_ext.route("/")
|
@captcha_ext.route("/")
|
||||||
@validate_uuids(["usr"], required=True)
|
@validate_uuids(["usr"], required=True)
|
||||||
|
@ -14,9 +16,9 @@ async def index():
|
||||||
return await render_template("captcha/index.html", user=g.user)
|
return await render_template("captcha/index.html", user=g.user)
|
||||||
|
|
||||||
|
|
||||||
@captcha_ext.route("/<captcha_id>")
|
@captcha_ext.route("/{captcha_id}")
|
||||||
async def display(captcha_id):
|
async def display(request: Request, captcha_id):
|
||||||
captcha = await get_captcha(captcha_id) or abort(
|
captcha = await get_captcha(captcha_id) or abort(
|
||||||
HTTPStatus.NOT_FOUND, "captcha does not exist."
|
HTTPStatus.NOT_FOUND, "captcha does not exist."
|
||||||
)
|
)
|
||||||
return await render_template("captcha/display.html", captcha=captcha)
|
return await templates.TemplateResponse("captcha/display.html", {"request": request, "captcha": captcha})
|
||||||
|
|
|
@ -9,7 +9,7 @@ from . import captcha_ext
|
||||||
from .crud import create_captcha, get_captcha, get_captchas, delete_captcha
|
from .crud import create_captcha, get_captcha, get_captchas, delete_captcha
|
||||||
|
|
||||||
|
|
||||||
@captcha_ext.route("/api/v1/captchas", methods=["GET"])
|
@captcha_ext.get("/api/v1/captchas")
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_captchas():
|
async def api_captchas():
|
||||||
wallet_ids = [g.wallet.id]
|
wallet_ids = [g.wallet.id]
|
||||||
|
@ -23,7 +23,7 @@ async def api_captchas():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@captcha_ext.route("/api/v1/captchas", methods=["POST"])
|
@captcha_ext.post("/api/v1/captchas")
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
@api_validate_post_request(
|
@api_validate_post_request(
|
||||||
schema={
|
schema={
|
||||||
|
@ -44,7 +44,7 @@ async def api_captcha_create():
|
||||||
return jsonify(captcha._asdict()), HTTPStatus.CREATED
|
return jsonify(captcha._asdict()), HTTPStatus.CREATED
|
||||||
|
|
||||||
|
|
||||||
@captcha_ext.route("/api/v1/captchas/<captcha_id>", methods=["DELETE"])
|
@captcha_ext.delete("/api/v1/captchas/{captcha_id}")
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_captcha_delete(captcha_id):
|
async def api_captcha_delete(captcha_id):
|
||||||
captcha = await get_captcha(captcha_id)
|
captcha = await get_captcha(captcha_id)
|
||||||
|
@ -60,7 +60,7 @@ async def api_captcha_delete(captcha_id):
|
||||||
return "", HTTPStatus.NO_CONTENT
|
return "", HTTPStatus.NO_CONTENT
|
||||||
|
|
||||||
|
|
||||||
@captcha_ext.route("/api/v1/captchas/<captcha_id>/invoice", methods=["POST"])
|
@captcha_ext.post("/api/v1/captchas/{captcha_id}/invoice")
|
||||||
@api_validate_post_request(
|
@api_validate_post_request(
|
||||||
schema={"amount": {"type": "integer", "min": 1, "required": True}}
|
schema={"amount": {"type": "integer", "min": 1, "required": True}}
|
||||||
)
|
)
|
||||||
|
@ -92,7 +92,7 @@ async def api_captcha_create_invoice(captcha_id):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@captcha_ext.route("/api/v1/captchas/<captcha_id>/check_invoice", methods=["POST"])
|
@captcha_ext.post("/api/v1/captchas/{captcha_id}/check_invoice")
|
||||||
@api_validate_post_request(
|
@api_validate_post_request(
|
||||||
schema={"payment_hash": {"type": "string", "empty": False, "required": True}}
|
schema={"payment_hash": {"type": "string", "empty": False, "required": True}}
|
||||||
)
|
)
|
||||||
|
@ -100,13 +100,13 @@ async def api_paywal_check_invoice(captcha_id):
|
||||||
captcha = await get_captcha(captcha_id)
|
captcha = await get_captcha(captcha_id)
|
||||||
|
|
||||||
if not captcha:
|
if not captcha:
|
||||||
return jsonify({"message": "captcha does not exist."}), HTTPStatus.NOT_FOUND
|
return {"message": "captcha does not exist."}, HTTPStatus.NOT_FOUND
|
||||||
|
|
||||||
try:
|
try:
|
||||||
status = await check_invoice_status(captcha.wallet, g.data["payment_hash"])
|
status = await check_invoice_status(captcha.wallet, g.data["payment_hash"])
|
||||||
is_paid = not status.pending
|
is_paid = not status.pending
|
||||||
except Exception:
|
except Exception:
|
||||||
return jsonify({"paid": False}), HTTPStatus.OK
|
return {"paid": False}, HTTPStatus.OK
|
||||||
|
|
||||||
if is_paid:
|
if is_paid:
|
||||||
wallet = await get_wallet(captcha.wallet)
|
wallet = await get_wallet(captcha.wallet)
|
||||||
|
@ -114,8 +114,8 @@ async def api_paywal_check_invoice(captcha_id):
|
||||||
await payment.set_pending(False)
|
await payment.set_pending(False)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
jsonify({"paid": True, "url": captcha.url, "remembers": captcha.remembers}),
|
{"paid": True, "url": captcha.url, "remembers": captcha.remembers},
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
return jsonify({"paid": False}), HTTPStatus.OK
|
return {"paid": False}, HTTPStatus.OK
|
||||||
|
|
|
@ -38,7 +38,7 @@ async def panel(request: Request):
|
||||||
connected_websockets = defaultdict(set)
|
connected_websockets = defaultdict(set)
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.websocket("/ws/<id>/")
|
@copilot_ext.websocket("/ws/{id}/")
|
||||||
async def wss(id):
|
async def wss(id):
|
||||||
copilot = await get_copilot(id)
|
copilot = await get_copilot(id)
|
||||||
if not copilot:
|
if not copilot:
|
||||||
|
|
|
@ -20,88 +20,83 @@ from .crud import (
|
||||||
|
|
||||||
#######################COPILOT##########################
|
#######################COPILOT##########################
|
||||||
|
|
||||||
|
class CreateData(BaseModel):
|
||||||
|
title: str
|
||||||
|
lnurl_toggle: Optional[int]
|
||||||
|
wallet: Optional[str]
|
||||||
|
animation1: Optional[str]
|
||||||
|
animation2: Optional[str]
|
||||||
|
animation3: Optional[str]
|
||||||
|
animation1threshold: Optional[int]
|
||||||
|
animation2threshold: Optional[int]
|
||||||
|
animation2threshold: Optional[int]
|
||||||
|
animation1webhook: Optional[str]
|
||||||
|
animation2webhook: Optional[str]
|
||||||
|
animation3webhook: Optional[str]
|
||||||
|
lnurl_title: Optional[str]
|
||||||
|
show_message: Optional[int]
|
||||||
|
show_ack: Optional[int]
|
||||||
|
show_price: Optional[str]
|
||||||
|
|
||||||
@copilot_ext.route("/api/v1/copilot", methods=["POST"])
|
@copilot_ext.post("/api/v1/copilot")
|
||||||
@copilot_ext.route("/api/v1/copilot/<copilot_id>", methods=["PUT"])
|
@copilot_ext.put("/api/v1/copilot/{copilot_id}")
|
||||||
@api_check_wallet_key("admin")
|
@api_check_wallet_key("admin")
|
||||||
@api_validate_post_request(
|
async def api_copilot_create_or_update(data: CreateData,copilot_id=None):
|
||||||
schema={
|
|
||||||
"title": {"type": "string", "empty": False, "required": True},
|
|
||||||
"lnurl_toggle": {"type": "integer", "empty": False},
|
|
||||||
"wallet": {"type": "string", "empty": False, "required": False},
|
|
||||||
"animation1": {"type": "string", "empty": True, "required": False},
|
|
||||||
"animation2": {"type": "string", "empty": True, "required": False},
|
|
||||||
"animation3": {"type": "string", "empty": True, "required": False},
|
|
||||||
"animation1threshold": {"type": "integer", "empty": True, "required": False},
|
|
||||||
"animation2threshold": {"type": "integer", "empty": True, "required": False},
|
|
||||||
"animation3threshold": {"type": "integer", "empty": True, "required": False},
|
|
||||||
"animation1webhook": {"type": "string", "empty": True, "required": False},
|
|
||||||
"animation2webhook": {"type": "string", "empty": True, "required": False},
|
|
||||||
"animation3webhook": {"type": "string", "empty": True, "required": False},
|
|
||||||
"lnurl_title": {"type": "string", "empty": True, "required": False},
|
|
||||||
"show_message": {"type": "integer", "empty": True, "required": False},
|
|
||||||
"show_ack": {"type": "integer", "empty": True},
|
|
||||||
"show_price": {"type": "string", "empty": True},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
async def api_copilot_create_or_update(copilot_id=None):
|
|
||||||
if not copilot_id:
|
if not copilot_id:
|
||||||
copilot = await create_copilot(user=g.wallet.user, **g.data)
|
copilot = await create_copilot(user=g.wallet.user, **data)
|
||||||
return jsonify(copilot._asdict()), HTTPStatus.CREATED
|
return jsonify(copilot._asdict()), HTTPStatus.CREATED
|
||||||
else:
|
else:
|
||||||
copilot = await update_copilot(copilot_id=copilot_id, **g.data)
|
copilot = await update_copilot(copilot_id=copilot_id, **data)
|
||||||
return jsonify(copilot._asdict()), HTTPStatus.OK
|
return jsonify(copilot._asdict()), HTTPStatus.OK
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/api/v1/copilot", methods=["GET"])
|
@copilot_ext.get("/api/v1/copilot")
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_copilots_retrieve():
|
async def api_copilots_retrieve():
|
||||||
try:
|
try:
|
||||||
return (
|
return (
|
||||||
jsonify(
|
[{**copilot._asdict()} for copilot in await get_copilots(g.wallet.user)],
|
||||||
[{**copilot._asdict()} for copilot in await get_copilots(g.wallet.user)]
|
|
||||||
),
|
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
except:
|
except:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/api/v1/copilot/<copilot_id>", methods=["GET"])
|
@copilot_ext.get("/api/v1/copilot/{copilot_id}")
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_copilot_retrieve(copilot_id):
|
async def api_copilot_retrieve(copilot_id):
|
||||||
copilot = await get_copilot(copilot_id)
|
copilot = await get_copilot(copilot_id)
|
||||||
if not copilot:
|
if not copilot:
|
||||||
return jsonify({"message": "copilot does not exist"}), HTTPStatus.NOT_FOUND
|
return {"message": "copilot does not exist"}, HTTPStatus.NOT_FOUND
|
||||||
if not copilot.lnurl_toggle:
|
if not copilot.lnurl_toggle:
|
||||||
return (
|
return (
|
||||||
jsonify({**copilot._asdict()}),
|
{**copilot._asdict()},
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
jsonify({**copilot._asdict(), **{"lnurl": copilot.lnurl}}),
|
{**copilot._asdict(), **{"lnurl": copilot.lnurl}},
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/api/v1/copilot/<copilot_id>", methods=["DELETE"])
|
@copilot_ext.delete("/api/v1/copilot/{copilot_id}")
|
||||||
@api_check_wallet_key("admin")
|
@api_check_wallet_key("admin")
|
||||||
async def api_copilot_delete(copilot_id):
|
async def api_copilot_delete(copilot_id):
|
||||||
copilot = await get_copilot(copilot_id)
|
copilot = await get_copilot(copilot_id)
|
||||||
|
|
||||||
if not copilot:
|
if not copilot:
|
||||||
return jsonify({"message": "Wallet link does not exist."}), HTTPStatus.NOT_FOUND
|
return {"message": "Wallet link does not exist."}, HTTPStatus.NOT_FOUND
|
||||||
|
|
||||||
await delete_copilot(copilot_id)
|
await delete_copilot(copilot_id)
|
||||||
|
|
||||||
return "", HTTPStatus.NO_CONTENT
|
return "", HTTPStatus.NO_CONTENT
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/api/v1/copilot/ws/<copilot_id>/<comment>/<data>", methods=["GET"])
|
@copilot_ext.get("/api/v1/copilot/ws/{copilot_id}/{comment}/{data}")
|
||||||
async def api_copilot_ws_relay(copilot_id, comment, data):
|
async def api_copilot_ws_relay(copilot_id, comment, data):
|
||||||
copilot = await get_copilot(copilot_id)
|
copilot = await get_copilot(copilot_id)
|
||||||
if not copilot:
|
if not copilot:
|
||||||
return jsonify({"message": "copilot does not exist"}), HTTPStatus.NOT_FOUND
|
return {"message": "copilot does not exist"}, HTTPStatus.NOT_FOUND
|
||||||
try:
|
try:
|
||||||
await updater(copilot_id, data, comment)
|
await updater(copilot_id, data, comment)
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -2,10 +2,13 @@ from quart import g, render_template
|
||||||
|
|
||||||
from lnbits.decorators import check_user_exists, validate_uuids
|
from lnbits.decorators import check_user_exists, validate_uuids
|
||||||
from lnbits.extensions.diagonalley import diagonalley_ext
|
from lnbits.extensions.diagonalley import diagonalley_ext
|
||||||
|
from fastapi import FastAPI, Request
|
||||||
|
from fastapi.templating import Jinja2Templates
|
||||||
|
|
||||||
|
templates = Jinja2Templates(directory="templates")
|
||||||
|
|
||||||
@diagonalley_ext.route("/")
|
@diagonalley_ext.route("/")
|
||||||
@validate_uuids(["usr"], required=True)
|
@validate_uuids(["usr"], required=True)
|
||||||
@check_user_exists()
|
@check_user_exists()
|
||||||
async def index():
|
async def index(request: Request):
|
||||||
return await render_template("diagonalley/index.html", user=g.user)
|
return await templates.TemplateResponse("diagonalley/index.html", {"request": request, "user": g.user})
|
|
@ -28,7 +28,7 @@ from lnbits.db import open_ext_db
|
||||||
### Products
|
### Products
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/products", methods=["GET"])
|
@diagonalley_ext.get("/api/v1/diagonalley/products")
|
||||||
@api_check_wallet_key(key_type="invoice")
|
@api_check_wallet_key(key_type="invoice")
|
||||||
async def api_diagonalley_products():
|
async def api_diagonalley_products():
|
||||||
wallet_ids = [g.wallet.id]
|
wallet_ids = [g.wallet.id]
|
||||||
|
@ -43,20 +43,17 @@ async def api_diagonalley_products():
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class CreateData(BaseModel):
|
||||||
|
product: str
|
||||||
|
categories: str
|
||||||
|
description: str
|
||||||
|
image: str
|
||||||
|
price: int = Query(ge=0)
|
||||||
|
quantity: int = Query(ge=0)
|
||||||
|
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/products", methods=["POST"])
|
@diagonalley_ext.post("/api/v1/diagonalley/products")
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/products<product_id>", methods=["PUT"])
|
@diagonalley_ext.put("/api/v1/diagonalley/products{product_id}")
|
||||||
@api_check_wallet_key(key_type="invoice")
|
@api_check_wallet_key(key_type="invoice")
|
||||||
@api_validate_post_request(
|
|
||||||
schema={
|
|
||||||
"product": {"type": "string", "empty": False, "required": True},
|
|
||||||
"categories": {"type": "string", "empty": False, "required": True},
|
|
||||||
"description": {"type": "string", "empty": False, "required": True},
|
|
||||||
"image": {"type": "string", "empty": False, "required": True},
|
|
||||||
"price": {"type": "integer", "min": 0, "required": True},
|
|
||||||
"quantity": {"type": "integer", "min": 0, "required": True},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
async def api_diagonalley_product_create(product_id=None):
|
async def api_diagonalley_product_create(product_id=None):
|
||||||
|
|
||||||
if product_id:
|
if product_id:
|
||||||
|
@ -84,7 +81,7 @@ async def api_diagonalley_product_create(product_id=None):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/products/<product_id>", methods=["DELETE"])
|
@diagonalley_ext.delete("/api/v1/diagonalley/products/{product_id}")
|
||||||
@api_check_wallet_key(key_type="invoice")
|
@api_check_wallet_key(key_type="invoice")
|
||||||
async def api_diagonalley_products_delete(product_id):
|
async def api_diagonalley_products_delete(product_id):
|
||||||
product = get_diagonalleys_product(product_id)
|
product = get_diagonalleys_product(product_id)
|
||||||
|
@ -103,7 +100,7 @@ async def api_diagonalley_products_delete(product_id):
|
||||||
###Indexers
|
###Indexers
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/indexers", methods=["GET"])
|
@diagonalley_ext.get("/api/v1/diagonalley/indexers")
|
||||||
@api_check_wallet_key(key_type="invoice")
|
@api_check_wallet_key(key_type="invoice")
|
||||||
async def api_diagonalley_indexers():
|
async def api_diagonalley_indexers():
|
||||||
wallet_ids = [g.wallet.id]
|
wallet_ids = [g.wallet.id]
|
||||||
|
@ -118,22 +115,19 @@ async def api_diagonalley_indexers():
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class CreateData(BaseModel):
|
||||||
|
shopname: str
|
||||||
|
indexeraddress: str
|
||||||
|
shippingzone1: str
|
||||||
|
shippingzone2: str
|
||||||
|
email: str
|
||||||
|
zone1cost: int = Query(ge=0)
|
||||||
|
zone2cost: int = Query(ge=0)
|
||||||
|
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/indexers", methods=["POST"])
|
@diagonalley_ext.post("/api/v1/diagonalley/indexers")
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/indexers<indexer_id>", methods=["PUT"])
|
@diagonalley_ext.put("/api/v1/diagonalley/indexers{indexer_id}")
|
||||||
@api_check_wallet_key(key_type="invoice")
|
@api_check_wallet_key(key_type="invoice")
|
||||||
@api_validate_post_request(
|
async def api_diagonalley_indexer_create(data: CreateData, indexer_id=None):
|
||||||
schema={
|
|
||||||
"shopname": {"type": "string", "empty": False, "required": True},
|
|
||||||
"indexeraddress": {"type": "string", "empty": False, "required": True},
|
|
||||||
"shippingzone1": {"type": "string", "empty": False, "required": True},
|
|
||||||
"shippingzone2": {"type": "string", "empty": False, "required": True},
|
|
||||||
"email": {"type": "string", "empty": False, "required": True},
|
|
||||||
"zone1cost": {"type": "integer", "min": 0, "required": True},
|
|
||||||
"zone2cost": {"type": "integer", "min": 0, "required": True},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
async def api_diagonalley_indexer_create(indexer_id=None):
|
|
||||||
|
|
||||||
if indexer_id:
|
if indexer_id:
|
||||||
indexer = get_diagonalleys_indexer(indexer_id)
|
indexer = get_diagonalleys_indexer(indexer_id)
|
||||||
|
@ -150,26 +144,26 @@ async def api_diagonalley_indexer_create(indexer_id=None):
|
||||||
HTTPStatus.FORBIDDEN,
|
HTTPStatus.FORBIDDEN,
|
||||||
)
|
)
|
||||||
|
|
||||||
indexer = update_diagonalleys_indexer(indexer_id, **g.data)
|
indexer = update_diagonalleys_indexer(indexer_id, **data)
|
||||||
else:
|
else:
|
||||||
indexer = create_diagonalleys_indexer(wallet_id=g.wallet.id, **g.data)
|
indexer = create_diagonalleys_indexer(wallet_id=g.wallet.id, **data)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
jsonify(indexer._asdict()),
|
indexer._asdict(),
|
||||||
HTTPStatus.OK if indexer_id else HTTPStatus.CREATED,
|
HTTPStatus.OK if indexer_id else HTTPStatus.CREATED,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/indexers/<indexer_id>", methods=["DELETE"])
|
@diagonalley_ext.delete("/api/v1/diagonalley/indexers/{indexer_id}")
|
||||||
@api_check_wallet_key(key_type="invoice")
|
@api_check_wallet_key(key_type="invoice")
|
||||||
async def api_diagonalley_indexer_delete(indexer_id):
|
async def api_diagonalley_indexer_delete(indexer_id):
|
||||||
indexer = get_diagonalleys_indexer(indexer_id)
|
indexer = get_diagonalleys_indexer(indexer_id)
|
||||||
|
|
||||||
if not indexer:
|
if not indexer:
|
||||||
return jsonify({"message": "Indexer does not exist."}), HTTPStatus.NOT_FOUND
|
return {"message": "Indexer does not exist."}, HTTPStatus.NOT_FOUND
|
||||||
|
|
||||||
if indexer.wallet != g.wallet.id:
|
if indexer.wallet != g.wallet.id:
|
||||||
return jsonify({"message": "Not your Indexer."}), HTTPStatus.FORBIDDEN
|
return {"message": "Not your Indexer."}, HTTPStatus.FORBIDDEN
|
||||||
|
|
||||||
delete_diagonalleys_indexer(indexer_id)
|
delete_diagonalleys_indexer(indexer_id)
|
||||||
|
|
||||||
|
@ -179,7 +173,7 @@ async def api_diagonalley_indexer_delete(indexer_id):
|
||||||
###Orders
|
###Orders
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/orders", methods=["GET"])
|
@diagonalley_ext.get("/api/v1/diagonalley/orders")
|
||||||
@api_check_wallet_key(key_type="invoice")
|
@api_check_wallet_key(key_type="invoice")
|
||||||
async def api_diagonalley_orders():
|
async def api_diagonalley_orders():
|
||||||
wallet_ids = [g.wallet.id]
|
wallet_ids = [g.wallet.id]
|
||||||
|
@ -188,44 +182,42 @@ async def api_diagonalley_orders():
|
||||||
wallet_ids = get_user(g.wallet.user).wallet_ids
|
wallet_ids = get_user(g.wallet.user).wallet_ids
|
||||||
|
|
||||||
return (
|
return (
|
||||||
jsonify([order._asdict() for order in get_diagonalleys_orders(wallet_ids)]),
|
[order._asdict() for order in get_diagonalleys_orders(wallet_ids)],
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class CreateData(BaseModel):
|
||||||
|
id: str
|
||||||
|
address: str
|
||||||
|
email: str
|
||||||
|
quantity: int
|
||||||
|
shippingzone: int
|
||||||
|
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/orders", methods=["POST"])
|
@diagonalley_ext.post("/api/v1/diagonalley/orders")
|
||||||
@api_check_wallet_key(key_type="invoice")
|
@api_check_wallet_key(key_type="invoice")
|
||||||
@api_validate_post_request(
|
|
||||||
schema={
|
async def api_diagonalley_order_create(data: CreateData):
|
||||||
"id": {"type": "string", "empty": False, "required": True},
|
order = create_diagonalleys_order(wallet_id=g.wallet.id, **data)
|
||||||
"address": {"type": "string", "empty": False, "required": True},
|
return order._asdict(), HTTPStatus.CREATED
|
||||||
"email": {"type": "string", "empty": False, "required": True},
|
|
||||||
"quantity": {"type": "integer", "empty": False, "required": True},
|
|
||||||
"shippingzone": {"type": "integer", "empty": False, "required": True},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
async def api_diagonalley_order_create():
|
|
||||||
order = create_diagonalleys_order(wallet_id=g.wallet.id, **g.data)
|
|
||||||
return jsonify(order._asdict()), HTTPStatus.CREATED
|
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/orders/<order_id>", methods=["DELETE"])
|
@diagonalley_ext.delete("/api/v1/diagonalley/orders/{order_id}")
|
||||||
@api_check_wallet_key(key_type="invoice")
|
@api_check_wallet_key(key_type="invoice")
|
||||||
async def api_diagonalley_order_delete(order_id):
|
async def api_diagonalley_order_delete(order_id):
|
||||||
order = get_diagonalleys_order(order_id)
|
order = get_diagonalleys_order(order_id)
|
||||||
|
|
||||||
if not order:
|
if not order:
|
||||||
return jsonify({"message": "Indexer does not exist."}), HTTPStatus.NOT_FOUND
|
return {"message": "Indexer does not exist."}, HTTPStatus.NOT_FOUND
|
||||||
|
|
||||||
if order.wallet != g.wallet.id:
|
if order.wallet != g.wallet.id:
|
||||||
return jsonify({"message": "Not your Indexer."}), HTTPStatus.FORBIDDEN
|
return {"message": "Not your Indexer."}, HTTPStatus.FORBIDDEN
|
||||||
|
|
||||||
delete_diagonalleys_indexer(order_id)
|
delete_diagonalleys_indexer(order_id)
|
||||||
|
|
||||||
return "", HTTPStatus.NO_CONTENT
|
return "", HTTPStatus.NO_CONTENT
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/orders/paid/<order_id>", methods=["GET"])
|
@diagonalley_ext.get("/api/v1/diagonalley/orders/paid/{order_id}")
|
||||||
@api_check_wallet_key(key_type="invoice")
|
@api_check_wallet_key(key_type="invoice")
|
||||||
async def api_diagonalleys_order_paid(order_id):
|
async def api_diagonalleys_order_paid(order_id):
|
||||||
with open_ext_db("diagonalley") as db:
|
with open_ext_db("diagonalley") as db:
|
||||||
|
@ -239,7 +231,7 @@ async def api_diagonalleys_order_paid(order_id):
|
||||||
return "", HTTPStatus.OK
|
return "", HTTPStatus.OK
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/orders/shipped/<order_id>", methods=["GET"])
|
@diagonalley_ext.get("/api/v1/diagonalley/orders/shipped/{order_id}")
|
||||||
@api_check_wallet_key(key_type="invoice")
|
@api_check_wallet_key(key_type="invoice")
|
||||||
async def api_diagonalleys_order_shipped(order_id):
|
async def api_diagonalleys_order_shipped(order_id):
|
||||||
with open_ext_db("diagonalley") as db:
|
with open_ext_db("diagonalley") as db:
|
||||||
|
@ -265,8 +257,8 @@ async def api_diagonalleys_order_shipped(order_id):
|
||||||
###List products based on indexer id
|
###List products based on indexer id
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.route(
|
@diagonalley_ext.get(
|
||||||
"/api/v1/diagonalley/stall/products/<indexer_id>", methods=["GET"]
|
"/api/v1/diagonalley/stall/products/{indexer_id}"
|
||||||
)
|
)
|
||||||
async def api_diagonalleys_stall_products(indexer_id):
|
async def api_diagonalleys_stall_products(indexer_id):
|
||||||
with open_ext_db("diagonalley") as db:
|
with open_ext_db("diagonalley") as db:
|
||||||
|
@ -275,18 +267,16 @@ async def api_diagonalleys_stall_products(indexer_id):
|
||||||
)
|
)
|
||||||
print(rows[1])
|
print(rows[1])
|
||||||
if not rows:
|
if not rows:
|
||||||
return jsonify({"message": "Indexer does not exist."}), HTTPStatus.NOT_FOUND
|
return {"message": "Indexer does not exist."}, HTTPStatus.NOT_FOUND
|
||||||
|
|
||||||
products = db.fetchone(
|
products = db.fetchone(
|
||||||
"SELECT * FROM diagonalley.products WHERE wallet = ?", (rows[1],)
|
"SELECT * FROM diagonalley.products WHERE wallet = ?", (rows[1],)
|
||||||
)
|
)
|
||||||
if not products:
|
if not products:
|
||||||
return jsonify({"message": "No products"}), HTTPStatus.NOT_FOUND
|
return {"message": "No products"}, HTTPStatus.NOT_FOUND
|
||||||
|
|
||||||
return (
|
return (
|
||||||
jsonify(
|
[products._asdict() for products in get_diagonalleys_products(rows[1])],
|
||||||
[products._asdict() for products in get_diagonalleys_products(rows[1])]
|
|
||||||
),
|
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -294,8 +284,8 @@ async def api_diagonalleys_stall_products(indexer_id):
|
||||||
###Check a product has been shipped
|
###Check a product has been shipped
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.route(
|
@diagonalley_ext.get(
|
||||||
"/api/v1/diagonalley/stall/checkshipped/<checking_id>", methods=["GET"]
|
"/api/v1/diagonalley/stall/checkshipped/{checking_id}"
|
||||||
)
|
)
|
||||||
async def api_diagonalleys_stall_checkshipped(checking_id):
|
async def api_diagonalleys_stall_checkshipped(checking_id):
|
||||||
with open_ext_db("diagonalley") as db:
|
with open_ext_db("diagonalley") as db:
|
||||||
|
@ -303,13 +293,13 @@ async def api_diagonalleys_stall_checkshipped(checking_id):
|
||||||
"SELECT * FROM diagonalley.orders WHERE invoiceid = ?", (checking_id,)
|
"SELECT * FROM diagonalley.orders WHERE invoiceid = ?", (checking_id,)
|
||||||
)
|
)
|
||||||
|
|
||||||
return jsonify({"shipped": rows["shipped"]}), HTTPStatus.OK
|
return {"shipped": rows["shipped"]}, HTTPStatus.OK
|
||||||
|
|
||||||
|
|
||||||
###Place order
|
###Place order
|
||||||
|
|
||||||
|
|
||||||
@diagonalley_ext.route("/api/v1/diagonalley/stall/order/<indexer_id>", methods=["POST"])
|
@diagonalley_ext.post("/api/v1/diagonalley/stall/order/{indexer_id}")
|
||||||
@api_validate_post_request(
|
@api_validate_post_request(
|
||||||
schema={
|
schema={
|
||||||
"id": {"type": "string", "empty": False, "required": True},
|
"id": {"type": "string", "empty": False, "required": True},
|
||||||
|
@ -355,6 +345,6 @@ async def api_diagonalley_stall_order(indexer_id):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return (
|
return (
|
||||||
jsonify({"checking_id": checking_id, "payment_request": payment_request}),
|
{"checking_id": checking_id, "payment_request": payment_request},
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user