Working on membership and users
This commit is contained in:
@@ -4,11 +4,11 @@ from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, stat
|
||||
from pydantic import BaseModel, EmailStr, Field
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
|
||||
from app.lib_general import *
|
||||
from app.lib_general import log, logging
|
||||
from app.config import settings
|
||||
from app.db_sql import *
|
||||
from app.db_sql import sql_select, redis_lookup_id_random
|
||||
|
||||
from .api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||
|
||||
from app.models.response_models import *
|
||||
#from app.models.lookup_models import Lookup_Base
|
||||
@@ -31,9 +31,7 @@ async def get_lookup_li(
|
||||
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
print('HERE')
|
||||
|
||||
allowed_lookup_tables = ['country', 'country_subdivision', 'event_session_type', 'file_purpose', 'membership_status', 'order_status', 'user_status']
|
||||
allowed_lookup_tables = ['country', 'country_subdivision', 'event_session_type', 'file_purpose', 'membership_member_status', 'order_status', 'user_status']
|
||||
|
||||
if for_lookup_name in allowed_lookup_tables:
|
||||
table_name = f'lu_{for_lookup_name}'
|
||||
|
||||
@@ -178,7 +178,6 @@ async def lookup_membership_group_obj(
|
||||
return mk_resp(data=data)
|
||||
|
||||
|
||||
|
||||
# ### BEGIN ### API Membership Group ### get_membership_group_obj() ###
|
||||
# Working well as of 2021-06-21. Using as a template for other routes.
|
||||
@router.get('/{membership_group_id}', response_model=Resp_Body_Base)
|
||||
|
||||
@@ -178,11 +178,10 @@ async def lookup_membership_type_obj(
|
||||
return mk_resp(data=data)
|
||||
|
||||
|
||||
|
||||
# ### BEGIN ### API Membership Type ### get_membership_type_obj() ###
|
||||
# Working well as of 2021-06-21. Using as a template for other routes.
|
||||
@router.get('/{membership_type_id}/v5', response_model=Resp_Body_Base)
|
||||
async def get_membership_type_obj_v5(
|
||||
@router.get('/{membership_type_id}', response_model=Resp_Body_Base)
|
||||
async def get_membership_type_obj(
|
||||
membership_type_id: str = Query(..., min_length=1, max_length=22),
|
||||
enabled: str = 'enabled', # For now this covers any included objects or object lists
|
||||
limit: int = 500, # For now this covers any included objects or object lists
|
||||
@@ -235,24 +234,24 @@ async def get_membership_type_obj_v5(
|
||||
# ### END ### API Membership ### get_membership_type_obj() ###
|
||||
|
||||
|
||||
@router.get('/{obj_id}', response_model=Resp_Body_Base)
|
||||
async def get_membership_type_obj_old(
|
||||
obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
x_account_id: str = Header(...),
|
||||
by_alias: Optional[bool] = True,
|
||||
exclude_unset: Optional[bool] = True,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
# @router.get('/{obj_id}', response_model=Resp_Body_Base)
|
||||
# async def get_membership_type_obj_old(
|
||||
# obj_id: str = Query(..., min_length=1, max_length=22),
|
||||
# x_account_id: str = Header(...),
|
||||
# by_alias: Optional[bool] = True,
|
||||
# exclude_unset: Optional[bool] = True,
|
||||
# ):
|
||||
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(locals())
|
||||
|
||||
obj_type = 'membership_type'
|
||||
result = get_obj_template(
|
||||
obj_type=obj_type,
|
||||
obj_id=obj_id,
|
||||
by_alias=True,
|
||||
exclude_unset=True,
|
||||
)
|
||||
return result
|
||||
# obj_type = 'membership_type'
|
||||
# result = get_obj_template(
|
||||
# obj_type=obj_type,
|
||||
# obj_id=obj_id,
|
||||
# by_alias=True,
|
||||
# exclude_unset=True,
|
||||
# )
|
||||
# return result
|
||||
|
||||
|
||||
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
||||
|
||||
@@ -489,7 +489,7 @@ async def lookup_username(
|
||||
account_id: Union[int,str],
|
||||
username: str = Query(..., min_length=2, max_length=50),
|
||||
x_account_id: str = Header(...),
|
||||
inc_roles: bool = False,
|
||||
inc_user_role_list: bool = False,
|
||||
inc_contact: bool = False,
|
||||
inc_organization: bool = False,
|
||||
inc_person: bool = False,
|
||||
@@ -531,12 +531,12 @@ async def lookup_username(
|
||||
if isinstance(user_obj_result, dict):
|
||||
user_id = user_obj_result.get('user_id', None)
|
||||
user_obj = load_user_obj(
|
||||
user_id=user_id,
|
||||
inc_roles=inc_roles,
|
||||
inc_contact=inc_contact,
|
||||
inc_organization=inc_organization,
|
||||
inc_person=inc_person
|
||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
user_id = user_id,
|
||||
inc_contact = inc_contact,
|
||||
inc_organization = inc_organization,
|
||||
inc_person = inc_person,
|
||||
inc_user_role_list = inc_user_role_list,
|
||||
).dict(by_alias = by_alias, exclude_unset=exclude_unset)
|
||||
data = user_obj
|
||||
elif isinstance(user_obj_result, list):
|
||||
user_obj_li = []
|
||||
@@ -544,11 +544,11 @@ async def lookup_username(
|
||||
user_id = user_obj.get('user_id', None)
|
||||
user_obj_li.append(
|
||||
load_user_obj(
|
||||
user_id=user_id,
|
||||
inc_roles=inc_roles,
|
||||
inc_contact=inc_contact,
|
||||
inc_organization=inc_organization,
|
||||
inc_person=inc_person,
|
||||
user_id = user_id,
|
||||
inc_contact = inc_contact,
|
||||
inc_organization = inc_organization,
|
||||
inc_person = inc_person,
|
||||
inc_user_role_list = inc_user_role_list,
|
||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
)
|
||||
data = user_obj_li
|
||||
@@ -558,11 +558,10 @@ async def lookup_username(
|
||||
return mk_resp(data=data)
|
||||
|
||||
|
||||
|
||||
# ### BEGIN ### API User ### get_user_obj_v5() ###
|
||||
# ### BEGIN ### API User ### get_user_obj() ###
|
||||
# Working well as of 2021-06-11. Using as a template for other routes.
|
||||
@router.get('/{user_id}/v5', response_model=Resp_Body_Base)
|
||||
async def get_user_obj_v5(
|
||||
@router.get('/{user_id}', response_model=Resp_Body_Base)
|
||||
async def get_user_obj(
|
||||
user_id: str = Query(..., min_length=1, max_length=22),
|
||||
limit: int = 500, # For now this covers any included objects or object lists
|
||||
enabled: str = 'enabled', # For now this covers any included objects or object lists
|
||||
@@ -596,65 +595,62 @@ async def get_user_obj_v5(
|
||||
else:
|
||||
return mk_resp(data=None, status_code=404)
|
||||
|
||||
if user_dict := load_user_obj(
|
||||
user_id = user_id,
|
||||
limit = limit,
|
||||
model_as_dict = True, # NOTE: returning model as a dict
|
||||
enabled = enabled,
|
||||
inc_address = inc_address,
|
||||
# inc_archive_list = inc_archive_list,
|
||||
inc_contact = inc_contact,
|
||||
inc_event_list = inc_event_list,
|
||||
# inc_hosted_file_list = inc_hosted_file_list,
|
||||
inc_journal_list = inc_journal_list,
|
||||
# inc_journal_entry_list = inc_journal_entry_list,
|
||||
inc_membership_member = inc_membership_member,
|
||||
# inc_membership_list = inc_membership_list, # ???
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
inc_order_list = inc_order_list,
|
||||
inc_order_cart_list = inc_order_cart_list,
|
||||
inc_organization = inc_organization,
|
||||
# inc_organization_list = inc_organization_list,
|
||||
inc_person = inc_person,
|
||||
# inc_person_list = inc_person_list,
|
||||
inc_post_list = inc_post_list,
|
||||
# inc_post_comment_list = inc_post_comment_list,
|
||||
inc_user_role_list = inc_user_role_list,
|
||||
):
|
||||
if isinstance(user_dict, dict):
|
||||
response_data = user_dict
|
||||
else:
|
||||
response_data = user_dict
|
||||
if user_result := load_user_obj(
|
||||
user_id = user_id,
|
||||
limit = limit,
|
||||
model_as_dict = True, # NOTE: returning model as a dict
|
||||
enabled = enabled,
|
||||
inc_address = inc_address,
|
||||
# inc_archive_list = inc_archive_list,
|
||||
inc_contact = inc_contact,
|
||||
inc_event_list = inc_event_list,
|
||||
# inc_hosted_file_list = inc_hosted_file_list,
|
||||
inc_journal_list = inc_journal_list,
|
||||
# inc_journal_entry_list = inc_journal_entry_list,
|
||||
inc_membership_member = inc_membership_member,
|
||||
# inc_membership_list = inc_membership_list, # ???
|
||||
inc_order_line_list = inc_order_line_list,
|
||||
inc_order_list = inc_order_list,
|
||||
inc_order_cart_list = inc_order_cart_list,
|
||||
inc_organization = inc_organization,
|
||||
# inc_organization_list = inc_organization_list,
|
||||
inc_person = inc_person,
|
||||
# inc_person_list = inc_person_list,
|
||||
inc_post_list = inc_post_list,
|
||||
# inc_post_comment_list = inc_post_comment_list,
|
||||
inc_user_role_list = inc_user_role_list,
|
||||
):
|
||||
response_data = user_result
|
||||
else:
|
||||
return mk_resp(data=False, status_code=400) # Bad Request
|
||||
|
||||
return mk_resp(data=response_data)
|
||||
# ### END ### API User ### get_user_obj_v5() ###
|
||||
# ### END ### API User ### get_user_obj() ###
|
||||
|
||||
|
||||
@router.get('/{user_id}', response_model=Resp_Body_Base)
|
||||
async def get_user_obj(
|
||||
user_id: str = Query(..., min_length=1, max_length=22),
|
||||
x_account_id: str = Header(...),
|
||||
inc_roles: bool = False,
|
||||
inc_contact: bool = False,
|
||||
inc_organization: bool = False,
|
||||
inc_person: bool = False,
|
||||
by_alias: bool = True,
|
||||
exclude_unset: bool = True,
|
||||
):
|
||||
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
# @router.get('/{user_id}', response_model=Resp_Body_Base)
|
||||
# async def get_user_obj(
|
||||
# user_id: str = Query(..., min_length=1, max_length=22),
|
||||
# x_account_id: str = Header(...),
|
||||
# inc_roles: bool = False,
|
||||
# inc_contact: bool = False,
|
||||
# inc_organization: bool = False,
|
||||
# inc_person: bool = False,
|
||||
# by_alias: bool = True,
|
||||
# exclude_unset: bool = True,
|
||||
# ):
|
||||
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
# log.debug(locals())
|
||||
|
||||
user_obj = load_user_obj(
|
||||
user_id=user_id,
|
||||
inc_roles=inc_roles,
|
||||
inc_contact=inc_contact,
|
||||
inc_organization=inc_organization,
|
||||
inc_person=inc_person
|
||||
).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
data = user_obj
|
||||
return mk_resp(data=data)
|
||||
# user_obj = load_user_obj(
|
||||
# user_id=user_id,
|
||||
# inc_roles=inc_roles,
|
||||
# inc_contact=inc_contact,
|
||||
# inc_organization=inc_organization,
|
||||
# inc_person=inc_person
|
||||
# ).dict(by_alias=by_alias, exclude_unset=exclude_unset)
|
||||
# data = user_obj
|
||||
# return mk_resp(data=data)
|
||||
|
||||
|
||||
@router.delete('/{obj_id}', response_model=Resp_Body_Base)
|
||||
|
||||
Reference in New Issue
Block a user