remove subscription endpoint
This commit is contained in:
@@ -50,6 +50,7 @@ app.include_router(users.password, prefix='/users')
|
||||
app.include_router(orders.router, prefix='/orders')
|
||||
app.include_router(orders.checkout, prefix='/orders')
|
||||
app.include_router(orders.payment_retries, prefix='/orders')
|
||||
app.include_router(orgs.router, prefix='/orgs')
|
||||
app.include_router(orgs.add, prefix='/orgs')
|
||||
app.include_router(orgs.address, prefix='/orgs')
|
||||
app.include_router(orgs.admins, prefix='/orgs')
|
||||
|
||||
@@ -38,6 +38,9 @@ class UserConflictError(ConflictError): ...
|
||||
class EmailConflictError(ConflictError): ...
|
||||
|
||||
|
||||
class CNPJConflictError(ConflictError): ...
|
||||
|
||||
|
||||
class CPFConflictError(ConflictError): ...
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,10 @@ def get_scorm(enrollment_id: str):
|
||||
if not enrollment:
|
||||
raise NotFoundError('Enrollment not found')
|
||||
|
||||
spec = {'id': 'course.id', 'scormset': 'course.scormset'}
|
||||
spec = {
|
||||
'id': 'course.id',
|
||||
'scormset': 'course.scormset',
|
||||
}
|
||||
course_id, scormset_id = glom(enrollment, spec).values()
|
||||
scormset = dyn.collection.get_item(
|
||||
KeyPair(course_id, f'SCORMSET#{scormset_id}'),
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
from aws_lambda_powertools import Logger
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, SortKey, TransactKey
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import USER_TABLE
|
||||
|
||||
from .add import router as add
|
||||
from .address import router as address
|
||||
from .admins import router as admins
|
||||
@@ -23,3 +30,18 @@ __all__ = [
|
||||
'users',
|
||||
'batch_jobs',
|
||||
]
|
||||
|
||||
|
||||
logger = Logger(__name__)
|
||||
router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@router.get('/<org_id>')
|
||||
def get_org(org_id: str):
|
||||
return dyn.collection.get_items(
|
||||
TransactKey(org_id)
|
||||
+ SortKey('0')
|
||||
+ SortKey('METADATA#ADDRESS', rename_key='address')
|
||||
+ SortKey('METADATA#SUBSCRIPTION', rename_key='subscription')
|
||||
)
|
||||
|
||||
@@ -3,7 +3,6 @@ from typing import Annotated
|
||||
from uuid import uuid4
|
||||
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from aws_lambda_powertools.event_handler.exceptions import NotFoundError
|
||||
from aws_lambda_powertools.event_handler.openapi.params import Body
|
||||
from layercake.dateutils import now
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
@@ -13,24 +12,17 @@ from pydantic import UUID4, BaseModel, EmailStr
|
||||
from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client
|
||||
from config import INTERNAL_EMAIL_DOMAIN, USER_TABLE
|
||||
from exceptions import ConflictError
|
||||
from exceptions import (
|
||||
CNPJConflictError,
|
||||
EmailConflictError,
|
||||
EmailNotFoundError,
|
||||
UserNotFoundError,
|
||||
)
|
||||
|
||||
router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
class CNPJConflictError(ConflictError): ...
|
||||
|
||||
|
||||
class EmailConflictError(ConflictError): ...
|
||||
|
||||
|
||||
class UserNotFoundError(NotFoundError): ...
|
||||
|
||||
|
||||
class EmailNotFoundError(NotFoundError): ...
|
||||
|
||||
|
||||
class User(BaseModel):
|
||||
id: str | UUID4
|
||||
name: NameStr
|
||||
@@ -101,6 +93,14 @@ def add(
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
# Post-migration (users): rename `orgmembers#` to `MEMBER#ORG#`
|
||||
'id': f'orgmembers#{org_id}',
|
||||
'sk': user.id,
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': user.id,
|
||||
@@ -119,14 +119,6 @@ def add(
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
# Post-migration (users): rename `orgmembers#` to `MEMBER#ORG#`
|
||||
'id': f'orgmembers#{org_id}',
|
||||
'sk': user.id,
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
transact.condition(
|
||||
key=KeyPair(str(user.id), '0'),
|
||||
cond_expr='attribute_exists(sk)',
|
||||
|
||||
@@ -16,15 +16,6 @@ router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
@router.get('/<org_id>/address')
|
||||
def address(org_id: str):
|
||||
return dyn.collection.get_item(
|
||||
KeyPair(org_id, 'METADATA#ADDRESS'),
|
||||
raise_on_error=False,
|
||||
default={},
|
||||
)
|
||||
|
||||
|
||||
class Address(BaseModel):
|
||||
model_config = ConfigDict(str_strip_whitespace=True)
|
||||
|
||||
|
||||
@@ -22,18 +22,6 @@ class PaymentMethod(str, Enum):
|
||||
MANUAL = 'MANUAL'
|
||||
|
||||
|
||||
@router.get('/<org_id>/subscription')
|
||||
def subscription(org_id: str):
|
||||
return dyn.collection.get_item(
|
||||
KeyPair(
|
||||
pk=org_id,
|
||||
sk='METADATA#SUBSCRIPTION',
|
||||
),
|
||||
raise_on_error=False,
|
||||
default={},
|
||||
)
|
||||
|
||||
|
||||
@router.post('/<org_id>/subscription')
|
||||
def add(
|
||||
org_id: str,
|
||||
@@ -44,8 +32,13 @@ def add(
|
||||
now_ = now()
|
||||
|
||||
with dyn.transact_writer() as transact:
|
||||
transact.condition(
|
||||
transact.update(
|
||||
key=KeyPair(org_id, '0'),
|
||||
update_expr='SET subscription_covered = :true, updated_at = :now',
|
||||
expr_attr_values={
|
||||
':true': True,
|
||||
':now': now_,
|
||||
},
|
||||
cond_expr='attribute_exists(sk)',
|
||||
exc_cls=OrgNotFoundError,
|
||||
)
|
||||
|
||||
@@ -3,7 +3,6 @@ from typing import Annotated
|
||||
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from aws_lambda_powertools.event_handler.exceptions import (
|
||||
NotFoundError,
|
||||
ServiceError,
|
||||
)
|
||||
from aws_lambda_powertools.event_handler.openapi.params import Body
|
||||
@@ -19,6 +18,7 @@ from layercake.extra_types import CpfStr, NameStr
|
||||
from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client
|
||||
from config import USER_TABLE
|
||||
from exceptions import CPFConflictError, UserNotFoundError
|
||||
|
||||
from .emails import router as emails
|
||||
from .orgs import router as orgs
|
||||
@@ -30,14 +30,6 @@ router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
class UserNotFoundError(NotFoundError): ...
|
||||
|
||||
|
||||
class CPFConflictError(ServiceError):
|
||||
def __init__(self, msg: str | dict):
|
||||
super().__init__(HTTPStatus.CONFLICT, msg)
|
||||
|
||||
|
||||
class RateLimitExceededError(ServiceError):
|
||||
def __init__(self, msg: str | dict):
|
||||
super().__init__(HTTPStatus.TOO_MANY_REQUESTS, msg)
|
||||
|
||||
Reference in New Issue
Block a user