feat: init merchant
This commit is contained in:
parent
2832ee928c
commit
99492b36c8
6 changed files with 164 additions and 8 deletions
45
views_api.py
45
views_api.py
|
|
@ -0,0 +1,45 @@
|
|||
from http import HTTPStatus
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import Depends
|
||||
from fastapi.exceptions import HTTPException
|
||||
from loguru import logger
|
||||
|
||||
from lnbits.decorators import WalletTypeInfo, require_admin_key, require_invoice_key
|
||||
|
||||
from . import nostrmarket_ext
|
||||
from .crud import create_merchant, get_merchant_for_user
|
||||
from .models import Merchant, PartialMerchant
|
||||
|
||||
|
||||
@nostrmarket_ext.post("/api/v1/merchant")
|
||||
async def api_create_merchant(
|
||||
data: PartialMerchant,
|
||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||
) -> Merchant:
|
||||
|
||||
try:
|
||||
merchant = await create_merchant(wallet.wallet.user, data)
|
||||
return merchant
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
detail="Cannot create merchant",
|
||||
)
|
||||
|
||||
|
||||
@nostrmarket_ext.get("/api/v1/merchant")
|
||||
async def api_get_merchant(
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
) -> Optional[Merchant]:
|
||||
|
||||
try:
|
||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||
return merchant
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
detail="Cannot create merchant",
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue