add admins
This commit is contained in:
@@ -43,7 +43,9 @@ app.include_router(users.emails, prefix='/users')
|
||||
app.include_router(users.add, prefix='/users')
|
||||
app.include_router(users.orgs, prefix='/users')
|
||||
app.include_router(orders.router, prefix='/orders')
|
||||
app.include_router(orgs.admins, prefix='/orgs')
|
||||
app.include_router(orgs.custom_pricing, prefix='/orgs')
|
||||
app.include_router(orgs.scheduled, prefix='/orgs')
|
||||
|
||||
|
||||
@app.get('/health')
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from .admins import router as admins
|
||||
from .custom_pricing import router as custom_pricing
|
||||
from .enrollments.scheduled import router as scheduled
|
||||
|
||||
__all__ = ['admins', 'custom_pricing']
|
||||
__all__ = ['admins', 'custom_pricing', 'scheduled']
|
||||
|
||||
@@ -2,7 +2,7 @@ from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import COURSE_TABLE, USER_TABLE
|
||||
from config import USER_TABLE
|
||||
|
||||
router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
@@ -11,7 +11,7 @@ dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
@router.get('/<org_id>/admins')
|
||||
def get_admins(org_id: str):
|
||||
return dyn.collection.query(
|
||||
# Post-migration: rename `admins` to `ADMIN`
|
||||
KeyPair(org_id, 'admins#'),
|
||||
table_name=COURSE_TABLE,
|
||||
limit=100,
|
||||
)
|
||||
|
||||
@@ -2,16 +2,15 @@ from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, PartitionKey
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import COURSE_TABLE, USER_TABLE
|
||||
from config import COURSE_TABLE
|
||||
|
||||
router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
dyn = DynamoDBPersistenceLayer(COURSE_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@router.get('/<org_id>/custompricing')
|
||||
@router.get('/<org_id>/custom-pricing')
|
||||
def get_custom_pricing(org_id: str):
|
||||
return dyn.collection.query(
|
||||
PartitionKey(f'CUSTOM_PRICING#ORG#{org_id}'),
|
||||
table_name=COURSE_TABLE,
|
||||
limit=100,
|
||||
)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
from aws_lambda_powertools import Logger
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, PartitionKey
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import ENROLLMENT_TABLE
|
||||
|
||||
logger = Logger(__name__)
|
||||
router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@router.get('/<org_id>/enrollments/scheduled')
|
||||
def scheduled(org_id: str):
|
||||
start_key = router.current_event.get_query_string_value('start_key', None)
|
||||
|
||||
return dyn.collection.query(
|
||||
# Post-migration: rename `scheduled_items` to `SCHEDULED#ORG#{org_id}`
|
||||
key=PartitionKey(f'scheduled_items#{org_id}'),
|
||||
start_key=start_key,
|
||||
limit=150,
|
||||
)
|
||||
39
api.saladeaula.digital/tests/routes/test_orgs.py
Normal file
39
api.saladeaula.digital/tests/routes/test_orgs.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import json
|
||||
from http import HTTPMethod, HTTPStatus
|
||||
|
||||
from ..conftest import HttpApiProxy, LambdaContext
|
||||
|
||||
|
||||
def test_get_admins(
|
||||
app,
|
||||
seeds,
|
||||
http_api_proxy: HttpApiProxy,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/f6000f79-6e5c-49a0-952f-3bda330ef278/admins',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
|
||||
r = json.loads(r['body'])
|
||||
assert len(r['items']) == 1
|
||||
|
||||
|
||||
def test_get_scheduled(
|
||||
app,
|
||||
seeds,
|
||||
http_api_proxy: HttpApiProxy,
|
||||
lambda_context: LambdaContext,
|
||||
):
|
||||
r = app.lambda_handler(
|
||||
http_api_proxy(
|
||||
raw_path='/orgs/1234/enrollments/scheduled',
|
||||
method=HTTPMethod.GET,
|
||||
),
|
||||
lambda_context,
|
||||
)
|
||||
assert r['statusCode'] == HTTPStatus.OK
|
||||
@@ -13,6 +13,9 @@
|
||||
{"id": "2a8963fc-4694-4fe2-953a-316d1b10f1f5", "sk": "0", "name": "pytest", "cnpj": "04978826000180"}
|
||||
{"id": "f6000f79-6e5c-49a0-952f-3bda330ef278", "sk": "0", "name": "Banco do Brasil", "cnpj": "00000000000191"}
|
||||
|
||||
// Org admins
|
||||
{"id": "f6000f79-6e5c-49a0-952f-3bda330ef278", "sk": "admins#15bacf02-1535-4bee-9022-19d106fd7518", "name": "Chester Bennington", "email": "chester@linkinpark.com"}
|
||||
|
||||
{"id": "orgmembers#f6000f79-6e5c-49a0-952f-3bda330ef278", "sk": "15bacf02-1535-4bee-9022-19d106fd7518"}
|
||||
|
||||
// Indicies
|
||||
|
||||
Reference in New Issue
Block a user