add subscription test
This commit is contained in:
@@ -57,6 +57,7 @@ app.include_router(orgs.billing, prefix='/orgs')
|
||||
app.include_router(orgs.custom_pricing, prefix='/orgs')
|
||||
app.include_router(orgs.scheduled, prefix='/orgs')
|
||||
app.include_router(orgs.submissions, prefix='/orgs')
|
||||
app.include_router(orgs.subscription, prefix='/orgs')
|
||||
app.include_router(orgs.seats, prefix='/orgs')
|
||||
app.include_router(orgs.users, prefix='/orgs')
|
||||
app.include_router(orgs.batch_jobs, prefix='/orgs')
|
||||
|
||||
@@ -11,6 +11,12 @@ class ConflictError(ServiceError):
|
||||
super().__init__(HTTPStatus.CONFLICT, msg)
|
||||
|
||||
|
||||
class OrgNotFoundError(NotFoundError): ...
|
||||
|
||||
|
||||
class MemberNotFoundError(NotFoundError): ...
|
||||
|
||||
|
||||
class OrderNotFoundError(NotFoundError): ...
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from .custom_pricing import router as custom_pricing
|
||||
from .enrollments.scheduled import router as scheduled
|
||||
from .enrollments.submissions import router as submissions
|
||||
from .seats import router as seats
|
||||
from .subscription import router as subscription
|
||||
from .users.add import router as users
|
||||
from .users.batch_jobs import router as batch_jobs
|
||||
|
||||
@@ -18,6 +19,7 @@ __all__ = [
|
||||
'scheduled',
|
||||
'submissions',
|
||||
'seats',
|
||||
'subscription',
|
||||
'users',
|
||||
'batch_jobs',
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from http import HTTPStatus
|
||||
from typing import Annotated
|
||||
|
||||
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
|
||||
@@ -12,17 +11,12 @@ from pydantic import UUID4, BaseModel, EmailStr
|
||||
from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client
|
||||
from config import USER_TABLE
|
||||
from exceptions import MemberNotFoundError, OrgNotFoundError
|
||||
|
||||
router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
class OrgNotFoundError(NotFoundError): ...
|
||||
|
||||
|
||||
class MemberNotFoundError(NotFoundError): ...
|
||||
|
||||
|
||||
@router.get('/<org_id>/admins')
|
||||
def admins(org_id: str):
|
||||
return dyn.collection.query(
|
||||
|
||||
@@ -7,7 +7,7 @@ from aws_lambda_powertools.event_handler.openapi.params import Query
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import ORDER_TABLE, USER_TABLE
|
||||
from config import ORDER_TABLE
|
||||
|
||||
router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
|
||||
@@ -16,19 +16,6 @@ dyn = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
|
||||
class BillingNotFoundError(NotFoundError): ...
|
||||
|
||||
|
||||
@router.get('/<org_id>/subscription')
|
||||
def subscription(org_id: str):
|
||||
return dyn.collection.get_item(
|
||||
KeyPair(
|
||||
pk=org_id,
|
||||
sk='METADATA#SUBSCRIPTION',
|
||||
table_name=USER_TABLE,
|
||||
),
|
||||
raise_on_error=False,
|
||||
default={},
|
||||
)
|
||||
|
||||
|
||||
@router.get('/<org_id>/billing')
|
||||
def billing(
|
||||
org_id: str,
|
||||
|
||||
71
api.saladeaula.digital/app/routes/orgs/subscription.py
Normal file
71
api.saladeaula.digital/app/routes/orgs/subscription.py
Normal file
@@ -0,0 +1,71 @@
|
||||
from enum import Enum
|
||||
from http import HTTPStatus
|
||||
from typing import Annotated
|
||||
|
||||
from aws_lambda_powertools.event_handler.api_gateway import Router
|
||||
from aws_lambda_powertools.event_handler.openapi.params import Body
|
||||
from layercake.dateutils import now
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
|
||||
|
||||
from api_gateway import JSONResponse
|
||||
from boto3clients import dynamodb_client
|
||||
from config import USER_TABLE
|
||||
from exceptions import OrgNotFoundError
|
||||
|
||||
router = Router()
|
||||
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
|
||||
|
||||
|
||||
class PaymentMethod(str, Enum):
|
||||
PIX = 'PIX'
|
||||
BANK_SLIP = 'BANK_SLIP'
|
||||
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,
|
||||
name: Annotated[str, Body(embed=True)],
|
||||
billing_day: Annotated[int, Body(embed=True, ge=1)],
|
||||
payment_method: Annotated[PaymentMethod, Body(embed=True)],
|
||||
):
|
||||
now_ = now()
|
||||
|
||||
with dyn.transact_writer() as transact:
|
||||
transact.condition(
|
||||
key=KeyPair(org_id, '0'),
|
||||
cond_expr='attribute_exists(sk)',
|
||||
exc_cls=OrgNotFoundError,
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': 'SUBSCRIPTION',
|
||||
'sk': f'ORG#{org_id}',
|
||||
'name': name,
|
||||
'created_at': now_,
|
||||
},
|
||||
cond_expr='attribute_not_exists(sk)',
|
||||
)
|
||||
transact.put(
|
||||
item={
|
||||
'id': org_id,
|
||||
'sk': 'METADATA#SUBSCRIPTION',
|
||||
'billing_day': billing_day,
|
||||
'payment_method': payment_method.value,
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
|
||||
return JSONResponse(status_code=HTTPStatus.CREATED)
|
||||
@@ -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, ttl
|
||||
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair, SortKey
|
||||
@@ -16,6 +15,7 @@ from config import INTERNAL_EMAIL_DOMAIN, USER_TABLE
|
||||
from exceptions import (
|
||||
CPFConflictError,
|
||||
EmailConflictError,
|
||||
OrgNotFoundError,
|
||||
UserConflictError,
|
||||
UserNotFoundError,
|
||||
)
|
||||
@@ -37,7 +37,7 @@ class User(BaseModel):
|
||||
email: EmailStr
|
||||
|
||||
|
||||
class OrgNotFoundError(NotFoundError): ...
|
||||
# class OrgNotFoundError(NotFoundError): ...
|
||||
|
||||
|
||||
@router.post('/<org_id>/users')
|
||||
|
||||
Reference in New Issue
Block a user