wip
This commit is contained in:
@@ -4,14 +4,13 @@ from typing import Annotated
|
||||
from fastapi import APIRouter, Query, Depends, HTTPException
|
||||
# from sqlmodel import SQLModel, Field
|
||||
from sqlmodel import select, and_
|
||||
from pydantic import BaseModel, Field
|
||||
# from sqlalchemy import select
|
||||
|
||||
import alchemy
|
||||
import utils
|
||||
from dependencies import get_session
|
||||
from utils import update_item, create_item
|
||||
from .status_model import Status
|
||||
from utils import update_item
|
||||
from .models.location import LocationCode, Country, LocationCreate, LocationCodeCreate, CountryCreate, CountryUpdate
|
||||
from .user import ACTIVE_USER
|
||||
|
||||
PRIMARY_ANNOTATION = utils.make_primary_annotation('Country')
|
||||
@@ -73,66 +72,6 @@ PRIMARY_ANNOTATION = utils.make_primary_annotation('Country')
|
||||
# notes: str | None = None
|
||||
|
||||
|
||||
class Contact(BaseModel):
|
||||
code: str
|
||||
address: str | None
|
||||
notes: str | None
|
||||
|
||||
|
||||
class Location(BaseModel):
|
||||
id: int
|
||||
code: str
|
||||
description: str | None
|
||||
notes: str | None
|
||||
status: Status
|
||||
contact: Contact | None
|
||||
|
||||
|
||||
class LocationCode(BaseModel):
|
||||
id: int
|
||||
code: str
|
||||
description: str | None
|
||||
notes: str | None
|
||||
status: Status
|
||||
locations: list[Location]
|
||||
contact: Contact | None
|
||||
|
||||
|
||||
|
||||
class Country(BaseModel):
|
||||
id: int
|
||||
code: str
|
||||
name: str
|
||||
notes: str | None
|
||||
status: Status
|
||||
location_codes: list[LocationCode] | None
|
||||
|
||||
|
||||
class LocationCreate(BaseModel):
|
||||
code: str = Field(max_length=30)
|
||||
description: str | None = None
|
||||
notes: str | None = None
|
||||
|
||||
class LocationCodeCreate(BaseModel):
|
||||
code: str = Field(max_length=8)
|
||||
description: str | None = None
|
||||
notes: str | None = None
|
||||
locations: list[LocationCreate] | None = None
|
||||
|
||||
class CountryCreate(BaseModel):
|
||||
code: str = Field(max_length=2)
|
||||
name: str = Field(max_length=80)
|
||||
notes: str | None = None
|
||||
location_codes: list[LocationCodeCreate] | None = None
|
||||
|
||||
class CountryUpdate(BaseModel):
|
||||
code: str | None = Field(default=None, max_length=2)
|
||||
name: str | None = Field(default=None, max_length=80)
|
||||
notes: str | None = None
|
||||
|
||||
|
||||
|
||||
|
||||
# class CountryUpdate(CountryBase):
|
||||
# code: str | None = None
|
||||
# name: str | None = None
|
||||
@@ -168,7 +107,7 @@ async def get_country(
|
||||
|
||||
|
||||
@router.post("/",
|
||||
response_model=Country)
|
||||
response_model=Country)
|
||||
async def create_country(
|
||||
country: CountryCreate,
|
||||
current_user: ACTIVE_USER,
|
||||
@@ -243,7 +182,7 @@ async def deactivate_country(
|
||||
|
||||
|
||||
@router.post("/{country}",
|
||||
response_model=LocationCode,)
|
||||
response_model=LocationCode, )
|
||||
async def create_location_code(
|
||||
country: PRIMARY_ANNOTATION,
|
||||
data: LocationCodeCreate,
|
||||
@@ -274,7 +213,7 @@ async def create_location_code(
|
||||
|
||||
|
||||
@router.post("/{country}/{location_code}",
|
||||
response_model=LocationCode,)
|
||||
response_model=LocationCode, )
|
||||
async def create_location(
|
||||
country: PRIMARY_ANNOTATION,
|
||||
location_code: PRIMARY_ANNOTATION,
|
||||
|
||||
Reference in New Issue
Block a user