feat: basic stall flow
This commit is contained in:
parent
c15b765a7d
commit
e9b7494bb6
8 changed files with 432 additions and 14 deletions
86
views_api.py
86
views_api.py
|
|
@ -16,14 +16,18 @@ from lnbits.utils.exchange_rates import currencies
|
|||
from . import nostrmarket_ext
|
||||
from .crud import (
|
||||
create_merchant,
|
||||
create_stall,
|
||||
create_zone,
|
||||
delete_zone,
|
||||
get_merchant_for_user,
|
||||
get_stall,
|
||||
get_stalls,
|
||||
get_zone,
|
||||
get_zones,
|
||||
update_stall,
|
||||
update_zone,
|
||||
)
|
||||
from .models import Merchant, PartialMerchant, PartialZone, Zone
|
||||
from .models import Merchant, PartialMerchant, PartialStall, PartialZone, Stall, Zone
|
||||
|
||||
######################################## MERCHANT ########################################
|
||||
|
||||
|
|
@ -138,6 +142,86 @@ async def api_delete_zone(zone_id, wallet: WalletTypeInfo = Depends(require_admi
|
|||
)
|
||||
|
||||
|
||||
######################################## STALLS ########################################
|
||||
|
||||
|
||||
@nostrmarket_ext.post("/api/v1/stall")
|
||||
async def api_create_stall(
|
||||
data: PartialStall,
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
):
|
||||
try:
|
||||
stall = await create_stall(wallet.wallet.user, data=data)
|
||||
return stall.dict()
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
detail="Cannot create stall",
|
||||
)
|
||||
|
||||
|
||||
@nostrmarket_ext.put("/api/v1/stall/{stall_id}")
|
||||
async def api_update_stall(
|
||||
data: Stall,
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
):
|
||||
try:
|
||||
stall = await get_stall(wallet.wallet.user, data.id)
|
||||
if not stall:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND,
|
||||
detail="Stall does not exist.",
|
||||
)
|
||||
stall = await update_stall(wallet.wallet.user, data.id, **data.dict())
|
||||
assert stall, "Cannot fetch updated stall"
|
||||
return stall.dict()
|
||||
except HTTPException as ex:
|
||||
raise ex
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
detail="Cannot create stall",
|
||||
)
|
||||
|
||||
|
||||
@nostrmarket_ext.get("/api/v1/stall/{stall_id}")
|
||||
async def api_get_stall(stall_id: str, wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
try:
|
||||
stall = await get_stall(wallet.wallet.user, stall_id)
|
||||
if not stall:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND,
|
||||
detail="Stall does not exist.",
|
||||
)
|
||||
return stall
|
||||
except HTTPException as ex:
|
||||
raise ex
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
detail="Cannot create stall",
|
||||
)
|
||||
|
||||
|
||||
@nostrmarket_ext.get("/api/v1/stall")
|
||||
async def api_gey_stalls(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
try:
|
||||
stalls = await get_stalls(wallet.wallet.user)
|
||||
return stalls
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
detail="Cannot create stall",
|
||||
)
|
||||
|
||||
|
||||
######################################## OTHER ########################################
|
||||
|
||||
|
||||
@nostrmarket_ext.get("/api/v1/currencies")
|
||||
async def api_list_currencies_available():
|
||||
return list(currencies.keys())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue