34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from __future__ import annotations
|
|
import datetime
|
|
|
|
from typing import Dict, List, Optional, Set, Union
|
|
from pydantic import BaseModel, EmailStr, Field, PrivateAttr, ValidationError, validator
|
|
|
|
from ..lib_general import *
|
|
from ..db_sql import redis_lookup_id_random, sql_insert, sql_select
|
|
|
|
from .address_model import Address_Base
|
|
|
|
|
|
# ### BEGIN ### API Address Methods ### create_address_obj() ###
|
|
def create_address_obj(address_obj_new:Address_Base):
|
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
if not address_obj_new:
|
|
return False
|
|
|
|
address_obj_data = address_obj_new.dict(by_alias=False, exclude_defaults=False, exclude_unset=True, exclude={'created_on', 'updated_on'})
|
|
|
|
if address_obj_in_result := sql_insert(data=address_obj_data, table_name='address', rm_id_random=True, id_random_length=8): pass
|
|
else:
|
|
return False
|
|
|
|
log.debug(address_obj_in_result)
|
|
|
|
address_id = address_obj_in_result
|
|
|
|
log.debug(f'Returning the new address_id: {address_id}')
|
|
return address_id
|
|
# ### END ### API Address Methods ### create_address_obj() ###
|