feat: manage shipping zones

This commit is contained in:
Vlad Stan 2023-02-28 16:30:09 +02:00
parent dcda99830e
commit 31c5a82cb9
8 changed files with 444 additions and 20 deletions

View file

@ -1,10 +1,12 @@
import json
from sqlite3 import Row
from typing import Optional
from typing import List, Optional
from fastapi import Query
from pydantic import BaseModel
######################################## MERCHANT ########################################
class MerchantConfig(BaseModel):
name: Optional[str]
@ -23,3 +25,21 @@ class Merchant(PartialMerchant):
merchant = cls(**dict(row))
merchant.config = MerchantConfig(**json.loads(row["meta"]))
return merchant
######################################## ZONES ########################################
class PartialZone(BaseModel):
name: Optional[str]
currency: str
cost: float
countries: List[str] = []
class Zone(PartialZone):
id: str
@classmethod
def from_row(cls, row: Row) -> "Zone":
zone = cls(**dict(row))
zone.countries = json.loads(row["regions"])
return zone