93 lines
3.0 KiB
Python
93 lines
3.0 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 app.db_sql import redis_lookup_id_random, sql_insert, sql_select, sql_update
|
|
from app.lib_general import log, logging
|
|
|
|
|
|
# ### BEGIN ### API Lookup Post Topic Methods ### load_post_topic() ###
|
|
# def load_lu_post_topic_obj(
|
|
# lu_post_topic_id: int|str,
|
|
# limit: int = 1000,
|
|
# by_alias: bool = True,
|
|
# exclude_unset: bool = True,
|
|
# model_as_dict: bool = False,
|
|
# enabled: str = 'enabled', # enabled, disabled, all
|
|
# ) -> Post_Base|bool:
|
|
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
# log.debug(locals())
|
|
|
|
# if post_id := redis_lookup_id_random(record_id_random=post_id, table_name='post'): pass
|
|
# else: return False
|
|
|
|
# if model_as_dict:
|
|
# return post_obj.dict(by_alias=by_alias, exclude_unset=exclude_unset) # pylint: disable=no-member
|
|
# else:
|
|
# return post_obj
|
|
# ### END ### API Post Methods ### load_post_obj() ###
|
|
|
|
|
|
# ### BEGIN ### API Lookup Post Topic Methods ### get_lu_post_topic_rec_list() ###
|
|
def get_lu_post_topic_rec_list(
|
|
account_id: str,
|
|
for_type: str,
|
|
inc_admin_options: bool = False,
|
|
limit: int = 1000,
|
|
enabled: str = 'enabled', # enabled, disabled, all
|
|
) -> list|bool:
|
|
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(locals())
|
|
|
|
if account_id := redis_lookup_id_random(record_id_random=account_id, table_name='account'): pass
|
|
else: return False
|
|
data = {}
|
|
|
|
if account_id:
|
|
data['account_id'] = account_id
|
|
sql_account_id = f'`tbl`.account_id = :account_id'
|
|
else:
|
|
sql_account_id = ''
|
|
|
|
if for_type:
|
|
data['for_type'] = for_type
|
|
sql_for_type = f'AND `tbl`.for_type = :for_type'
|
|
else:
|
|
sql_for_type = ''
|
|
|
|
if inc_admin_options:
|
|
data['admin_option'] = [0, 1]
|
|
sql_admin_option = f'AND `tbl`.admin_option IN :admin_option'
|
|
else:
|
|
data['admin_option'] = [0]
|
|
sql_admin_option = f'AND `tbl`.admin_option IN :admin_option'
|
|
|
|
if limit:
|
|
data['limit'] = limit
|
|
sql_limit = f'LIMIT :limit'
|
|
else:
|
|
sql_limit = ''
|
|
|
|
sql = f"""
|
|
SELECT * /*`tbl`.id AS 'lu_post_topic_id'*/
|
|
FROM `lu_post_topic` AS `tbl`
|
|
WHERE
|
|
{sql_account_id}
|
|
{sql_for_type}
|
|
{sql_admin_option}
|
|
ORDER BY `tbl`.sort DESC
|
|
{sql_limit};
|
|
"""
|
|
|
|
if lu_post_topic_rec_li_result := sql_select(data=data, sql=sql, as_list=True):
|
|
lu_post_topic_rec_li = lu_post_topic_rec_li_result
|
|
else:
|
|
lu_post_topic_rec_li = []
|
|
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
|
log.debug(lu_post_topic_rec_li_result)
|
|
|
|
return lu_post_topic_rec_li
|
|
# ### END ### API Lookup Post Topic Methods ### get_lu_post_topic_rec_list() ###
|