Added better fundraising routes, methods, and models! I thought I already did this...
This commit is contained in:
83
app/routers/fundraising.py
Normal file
83
app/routers/fundraising.py
Normal file
@@ -0,0 +1,83 @@
|
||||
import datetime, time
|
||||
from fastapi import APIRouter, Body, Depends, Header, HTTPException, Query, Response, status
|
||||
from pydantic import BaseModel, EmailStr, Field
|
||||
from typing import Dict, List, Optional, Set, Union
|
||||
|
||||
from app.lib_general import log, logging, secure_hash_string, verify_secure_hash_string, common_route_params, Common_Route_Params
|
||||
from app.config import settings
|
||||
from app.db_sql import sql_insert, sql_update, sql_insert_or_update, sql_select, sql_delete, redis_lookup_id_random
|
||||
|
||||
from app.routers.api_crud import delete_obj_template, get_obj_template, get_obj_li_template, patch_obj_template, post_obj_template
|
||||
|
||||
from app.methods.fundraising_methods import get_fundraising_rec_list, load_fundraising_obj
|
||||
# from app.methods.fundraising_cfg_methods import load_fundraising_cfg_obj
|
||||
|
||||
from app.models.fundraising_models import Fundraising_Base
|
||||
from app.models.response_models import Resp_Body_Base, mk_resp
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# ### BEGIN ### API Event ### get_account_obj_fundraising_list() ###
|
||||
# Updated 2021-12-13
|
||||
@router.get('/account/{account_id}/fundraising/list', response_model=Resp_Body_Base)
|
||||
async def get_account_obj_fundraising_list(
|
||||
account_id: str = Query(..., min_length=11, max_length=22),
|
||||
|
||||
hidden: str = 'not_hidden', # hidden, not_hidden, all
|
||||
priority: str = 'all', # priority, not_priority, all
|
||||
|
||||
inc_account_cfg: bool = False,
|
||||
inc_fundraising_cfg: bool = False,
|
||||
inc_product: bool = False,
|
||||
inc_product_list: bool = False,
|
||||
|
||||
commons: Common_Route_Params = Depends(common_route_params),
|
||||
):
|
||||
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log.debug(locals())
|
||||
|
||||
account_id = commons.x_account_id
|
||||
|
||||
# Updated 2021-12-13
|
||||
if fundraising_rec_list_result := get_fundraising_rec_list(
|
||||
account_id = account_id,
|
||||
|
||||
enabled = commons.enabled,
|
||||
hidden = hidden,
|
||||
priority = priority,
|
||||
|
||||
limit = commons.limit,
|
||||
offset = commons.offset,
|
||||
):
|
||||
fundraising_result_list = []
|
||||
for fundraising_rec in fundraising_rec_list_result:
|
||||
if load_fundraising_result := load_fundraising_obj(
|
||||
fundraising_id = fundraising_rec.get('fundraising_id', None),
|
||||
|
||||
inc_fundraising_cfg = inc_fundraising_cfg,
|
||||
inc_product_list = inc_product_list,
|
||||
|
||||
enabled = commons.enabled,
|
||||
limit = commons.limit,
|
||||
offset = commons.offset,
|
||||
|
||||
# exclude_unset = commons.exclude_unset,
|
||||
# model_as_dict = model_as_dict,
|
||||
):
|
||||
fundraising_result_list.append(load_fundraising_result)
|
||||
else:
|
||||
fundraising_result_list.append(None)
|
||||
response_data = fundraising_result_list
|
||||
elif isinstance(fundraising_rec_list_result, list) or fundraising_rec_list_result is None: # Empty list or None
|
||||
log.info('No results')
|
||||
return mk_resp(data=None, status_code=404, response=commons.response) # Not Found
|
||||
else:
|
||||
log.warning('Likely bad request')
|
||||
return mk_resp(data=False, status_code=400, response=commons.response) # Bad Request
|
||||
|
||||
log.debug(response_data)
|
||||
|
||||
return mk_resp(data=response_data, response=commons.response)
|
||||
# ### END ### API Event ### get_account_obj_fundraising_list() ###
|
||||
Reference in New Issue
Block a user