diff --git a/app/models/archive_content_models.py b/app/models/archive_content_models.py index 62a5219..fc0b2c5 100644 --- a/app/models/archive_content_models.py +++ b/app/models/archive_content_models.py @@ -11,18 +11,22 @@ from app.models.common_field_schema import base_fields, default_num_bytes # ### BEGIN ### API Archive Content Models ### Archive_Content_Base() ### class Archive_Content_Base(BaseModel): - log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL log.debug(locals()) + def testing(test_var=None): + log.debug(test_var) + return test_var + id_random: Optional[str] = Field( - **base_fields['archive_content_id_random'], + # **base_fields['archive_content_id_random'], alias = 'archive_content_id_random', ) id: Optional[int] = Field( alias = 'archive_content_id' ) - account_id_random: Optional[str] # Is this field really needed? - account_id: Optional[int] # Is this field really needed? + # account_id_random: Optional[str] # Is this field really needed? + # account_id: Optional[int] # Is this field really needed? archive_id_random: Optional[str] archive_id: Optional[int] @@ -45,9 +49,16 @@ class Archive_Content_Base(BaseModel): hosted_file_id: Optional[int] file_path: Optional[str] + filename: Optional[str] file_extension: Optional[str] + # xxxx_red: str = Field(default='xxx') + # xxxx_blue: str = Field(default_factory=testing) + hosted_file_path: str = None # '/testing/test-test' + + wtf: str = 'HELLO???' + original_datetime: Optional[datetime.datetime] original_datetime_timezone: Optional[str] original_location: Optional[str] @@ -72,45 +83,58 @@ class Archive_Content_Base(BaseModel): _processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now) - #@validator('archive_content_id_random', always=True) - def archive_content_id_random_copy(cls, v, values, **kwargs): - log.setLevel(logging.WARNING) - log.debug(locals()) - - if values['id_random']: - return values['id_random'] - return None - @validator('id', always=True) def archive_content_id_lookup(cls, v, values, **kwargs): - log.setLevel(logging.WARNING) - log.debug(locals()) - - if values['id_random']: - log.debug(values['id_random']) - return redis_lookup_id_random(record_id_random=values['id_random'], table_name='archive_content') + if isinstance(v, int) and v > 0: return v + elif id_random := values.get('id_random'): + return redis_lookup_id_random(record_id_random=id_random, table_name='archive_content') return None @validator('archive_id', always=True) def archive_id_lookup(cls, v, values, **kwargs): - log.setLevel(logging.WARNING) - log.debug(locals()) - - if values['archive_id_random']: - return redis_lookup_id_random(record_id_random=values['archive_id_random'], table_name='archive') + if isinstance(v, int) and v > 0: return v + elif id_random := values.get('archive_id_random'): + return redis_lookup_id_random(record_id_random=id_random, table_name='archive') return None - @validator('account_id', always=True) - def account_id_lookup(cls, v, values, **kwargs): - log.setLevel(logging.WARNING) - log.debug(locals()) - - if values['account_id_random']: - return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account') + @validator('hosted_file_id', always=True) + def hosted_file_id_lookup(cls, v, values, **kwargs): + if isinstance(v, int) and v > 0: return v + elif id_random := values.get('hosted_file_id_random'): + return redis_lookup_id_random(record_id_random=id_random, table_name='hosted_file') return None + @validator('hosted_file_path', always=True) + def hosted_file_path_lookup(cls, v, values, **kwargs): + log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL + log.debug(v) + log.debug(values) + + if hosted_file_id_random := values.get('hosted_file_id_random'): + log.debug('Found hosted_file_id_random...') + path_str = f'/hosted_file/download/{hosted_file_id_random}' + + if filename := values.get('filename'): + path_str = f'{path_str}?filename={filename}' + + log.debug(path_str) + return path_str + log.debug('NOT Found hosted_file_id_random...') + return v + + + + # @validator('account_id', always=True) + # def account_id_lookup(cls, v, values, **kwargs): + # log.setLevel(logging.WARNING) + # log.debug(locals()) + + # if values['account_id_random']: + # return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account') + # return None + class Config: underscore_attrs_are_private = True allow_population_by_field_name = True fields = base_fields -# ### END ### API Archive Content Models ### Archive_Content_Base() ### \ No newline at end of file +# ### END ### API Archive Content Models ### Archive_Content_Base() ### diff --git a/app/models/archive_models.py b/app/models/archive_models.py index 77804c3..a406ebb 100644 --- a/app/models/archive_models.py +++ b/app/models/archive_models.py @@ -65,36 +65,22 @@ class Archive_Base(BaseModel): _processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now) - #@validator('archive_id_random', always=True) - def archive_id_random_copy(cls, v, values, **kwargs): - log.setLevel(logging.WARNING) - log.debug(locals()) - - if values['id_random']: - return values['id_random'] - return None - @validator('id', always=True) def archive_id_lookup(cls, v, values, **kwargs): - log.setLevel(logging.WARNING) - log.debug(locals()) - - if values['id_random']: - log.debug(values['id_random']) - return redis_lookup_id_random(record_id_random=values['id_random'], table_name='archive') + if isinstance(v, int) and v > 0: return v + elif id_random := values.get('id_random'): + return redis_lookup_id_random(record_id_random=id_random, table_name='archive') return None @validator('account_id', always=True) def account_id_lookup(cls, v, values, **kwargs): - log.setLevel(logging.WARNING) - log.debug(locals()) - - if values['account_id_random']: - return redis_lookup_id_random(record_id_random=values['account_id_random'], table_name='account') + if isinstance(v, int) and v > 0: return v + elif id_random := values.get('account_id_random'): + return redis_lookup_id_random(record_id_random=id_random, table_name='account') return None class Config: underscore_attrs_are_private = True allow_population_by_field_name = True fields = base_fields -# ### END ### API Archive Models ### Archive_Base() ### \ No newline at end of file +# ### END ### API Archive Models ### Archive_Base() ### diff --git a/app/models/data_store_models.py b/app/models/data_store_models.py index 6f030f8..ed90df2 100644 --- a/app/models/data_store_models.py +++ b/app/models/data_store_models.py @@ -68,12 +68,6 @@ class Data_Store_Base(BaseModel): _processed_at: datetime.datetime = PrivateAttr(default_factory=datetime.datetime.now) - #@validator('data_store_id_random', always=True) - def data_store_id_random_copy(cls, v, values, **kwargs): - if values['id_random']: - return values['id_random'] - return None - @validator('id', always=True) def data_store_id_lookup(cls, v, values, **kwargs): if isinstance(v, int) and v > 0: return v diff --git a/app/routers/archive_content.py b/app/routers/archive_content.py index 6354755..5da995d 100644 --- a/app/routers/archive_content.py +++ b/app/routers/archive_content.py @@ -88,14 +88,14 @@ async def get_archive_content_obj_li( for_obj_type=for_obj_type, for_obj_id=for_obj_id, by_alias=True, - exclude_unset=True, + exclude_unset=False, ) return result @router.get('/{obj_id}', response_model=Resp_Body_Base) async def get_archive_content_obj( - obj_id: str = Query(..., min_length=1, max_length=22), + obj_id: str = Query(..., min_length=11, max_length=22), x_account_id: str = Header(...), by_alias: Optional[bool] = True, exclude_unset: Optional[bool] = True,