Refactors type hints for clarity
Updates type hints in `crud.py`, `helpers.py`, and `models.py` for improved readability and maintainability. Replaces `Merchant | None` with `Optional[Merchant]` and `list[X]` with `List[X]` for consistency with standard Python typing practices.
This commit is contained in:
parent
429522adba
commit
e8ddc4b697
5 changed files with 122 additions and 115 deletions
31
views_api.py
31
views_api.py
|
|
@ -1,12 +1,13 @@
|
|||
import json
|
||||
from http import HTTPStatus
|
||||
from typing import List, Optional
|
||||
|
||||
from fastapi import Depends
|
||||
from fastapi.exceptions import HTTPException
|
||||
from lnbits.core.models import WalletTypeInfo
|
||||
from lnbits.core.crud import get_account, update_account
|
||||
from lnbits.core.services import websocket_updater
|
||||
from lnbits.decorators import (
|
||||
WalletTypeInfo,
|
||||
require_admin_key,
|
||||
require_invoice_key,
|
||||
)
|
||||
|
|
@ -167,7 +168,7 @@ async def api_create_merchant(
|
|||
@nostrmarket_ext.get("/api/v1/merchant")
|
||||
async def api_get_merchant(
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
) -> Merchant | None:
|
||||
) -> Optional[Merchant]:
|
||||
|
||||
try:
|
||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||
|
|
@ -335,7 +336,7 @@ async def api_delete_merchant_on_nostr(
|
|||
@nostrmarket_ext.get("/api/v1/zone")
|
||||
async def api_get_zones(
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
) -> list[Zone]:
|
||||
) -> List[Zone]:
|
||||
try:
|
||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||
assert merchant, "Merchant cannot be found"
|
||||
|
|
@ -535,7 +536,7 @@ async def api_get_stall(
|
|||
|
||||
@nostrmarket_ext.get("/api/v1/stall")
|
||||
async def api_get_stalls(
|
||||
pending: bool | None = False,
|
||||
pending: Optional[bool] = False,
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
):
|
||||
try:
|
||||
|
|
@ -559,7 +560,7 @@ async def api_get_stalls(
|
|||
@nostrmarket_ext.get("/api/v1/stall/product/{stall_id}")
|
||||
async def api_get_stall_products(
|
||||
stall_id: str,
|
||||
pending: bool | None = False,
|
||||
pending: Optional[bool] = False,
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
):
|
||||
try:
|
||||
|
|
@ -583,9 +584,9 @@ async def api_get_stall_products(
|
|||
@nostrmarket_ext.get("/api/v1/stall/order/{stall_id}")
|
||||
async def api_get_stall_orders(
|
||||
stall_id: str,
|
||||
paid: bool | None = None,
|
||||
shipped: bool | None = None,
|
||||
pubkey: str | None = None,
|
||||
paid: Optional[bool] = None,
|
||||
shipped: Optional[bool] = None,
|
||||
pubkey: Optional[str] = None,
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
):
|
||||
try:
|
||||
|
|
@ -719,7 +720,7 @@ async def api_update_product(
|
|||
async def api_get_product(
|
||||
product_id: str,
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
) -> Product | None:
|
||||
) -> Optional[Product]:
|
||||
try:
|
||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||
assert merchant, "Merchant cannot be found"
|
||||
|
|
@ -804,9 +805,9 @@ async def api_get_order(
|
|||
|
||||
@nostrmarket_ext.get("/api/v1/order")
|
||||
async def api_get_orders(
|
||||
paid: bool | None = None,
|
||||
shipped: bool | None = None,
|
||||
pubkey: str | None = None,
|
||||
paid: Optional[bool] = None,
|
||||
shipped: Optional[bool] = None,
|
||||
pubkey: Optional[str] = None,
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
):
|
||||
try:
|
||||
|
|
@ -892,7 +893,7 @@ async def api_update_order_status(
|
|||
async def api_restore_order(
|
||||
event_id: str,
|
||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||
) -> Order | None:
|
||||
) -> Optional[Order]:
|
||||
try:
|
||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||
assert merchant, "Merchant cannot be found"
|
||||
|
|
@ -1019,7 +1020,7 @@ async def api_reissue_order_invoice(
|
|||
@nostrmarket_ext.get("/api/v1/message/{public_key}")
|
||||
async def api_get_messages(
|
||||
public_key: str, wallet: WalletTypeInfo = Depends(require_invoice_key)
|
||||
) -> list[DirectMessage]:
|
||||
) -> List[DirectMessage]:
|
||||
try:
|
||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||
assert merchant, "Merchant cannot be found"
|
||||
|
|
@ -1075,7 +1076,7 @@ async def api_create_message(
|
|||
@nostrmarket_ext.get("/api/v1/customer")
|
||||
async def api_get_customers(
|
||||
wallet: WalletTypeInfo = Depends(require_invoice_key),
|
||||
) -> list[Customer]:
|
||||
) -> List[Customer]:
|
||||
try:
|
||||
merchant = await get_merchant_for_user(wallet.wallet.user)
|
||||
assert merchant, "Merchant cannot be found"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue