update id

This commit is contained in:
2025-10-30 02:02:23 -03:00
parent f284b64c60
commit 76dfc44b71
25 changed files with 103 additions and 40 deletions

View File

@@ -14,7 +14,7 @@ from aws_lambda_powertools.utilities.typing import LambdaContext
from api_gateway import JSONResponse
from json_encoder import JSONEncoder
from routes import courses, enrollments, orders, users
from routes import courses, enrollments, orders, orgs, users
logger = Logger(__name__)
tracer = Tracer()
@@ -42,6 +42,7 @@ app.include_router(users.router, prefix='/users')
app.include_router(users.emails, prefix='/users')
app.include_router(users.orgs, prefix='/users')
app.include_router(orders.router, prefix='/orders')
app.include_router(orgs.custom_pricing, prefix='/orgs')
@app.exception_handler(ServiceError)

View File

@@ -51,17 +51,18 @@ class Course(BaseModel):
@router.put('/<course_id>')
def edit_course(course_id: str):
def put_course(course_id: str):
event = router.current_event
if not event.decoded_body:
raise BadRequestError('Invalid request body')
body = BytesIO(event.decoded_body.encode())
course = Course.model_validate(
{'id': course_id, 'cert': {}} | parse(event.headers, body),
)
now_ = now()
body = parse(
event.headers,
BytesIO(event.decoded_body.encode()),
)
course = Course.model_validate({'id': course_id, 'cert': {}} | body)
if course.rawfile:
object_key = f'certs/templates/{course_id}.html'

View File

@@ -1,7 +1,6 @@
from aws_lambda_powertools import Logger
from aws_lambda_powertools.event_handler.api_gateway import Router
from aws_lambda_powertools.event_handler.exceptions import NotFoundError
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
from layercake.dynamodb import DynamoDBPersistenceLayer, SortKey, TransactKey
from boto3clients import dynamodb_client
from config import ENROLLMENT_TABLE
@@ -20,7 +19,6 @@ dyn = DynamoDBPersistenceLayer(ENROLLMENT_TABLE, dynamodb_client)
@router.get('/<enrollment_id>')
def get_enrollment(enrollment_id: str):
return dyn.collection.get_item(
KeyPair(enrollment_id, '0'),
exc_cls=NotFoundError,
return dyn.collection.get_items(
TransactKey(enrollment_id) + SortKey('0') + SortKey('ORG') + SortKey('LOCK'),
)

View File

@@ -0,0 +1,4 @@
from .custom_pricing import router as custom_pricing
__all__ = ['custom_pricing']

View File

@@ -0,0 +1,17 @@
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
router = Router()
dyn = DynamoDBPersistenceLayer(USER_TABLE, dynamodb_client)
@router.get('/<org_id>/custompricing')
def get_custom_pricing(org_id: str):
return dyn.collection.query(
PartitionKey(f'CUSTOM_PRICING#ORG#{org_id}'),
table_name=COURSE_TABLE,
limit=100,
)

View File

@@ -26,7 +26,7 @@ Globals:
Architectures:
- x86_64
Layers:
- !Sub arn:aws:lambda:sa-east-1:336641857101:layer:layercake:99
- !Sub arn:aws:lambda:sa-east-1:336641857101:layer:layercake:100
Environment:
Variables:
TZ: America/Sao_Paulo

View File

@@ -18,6 +18,7 @@ def pytest_configure():
os.environ['TZ'] = 'America/Sao_Paulo'
os.environ['COURSE_TABLE'] = PYTEST_TABLE_NAME
os.environ['USER_TABLE'] = PYTEST_TABLE_NAME
os.environ['ENROLLMENT_TABLE'] = PYTEST_TABLE_NAME
os.environ['BUCKET_NAME'] = 'saladeaula.digital'
os.environ['DYNAMODB_PARTITION_KEY'] = PK
os.environ['DYNAMODB_SORT_KEY'] = SK

View File

@@ -0,0 +1,24 @@
import json
from http import HTTPMethod, HTTPStatus
from ..conftest import HttpApiProxy, LambdaContext
def test_get_enrollment(
app,
seeds,
http_api_proxy: HttpApiProxy,
lambda_context: LambdaContext,
):
r = app.lambda_handler(
http_api_proxy(
raw_path='/enrollments/578ec87f-94c7-4840-8780-bb4839cc7e64',
method=HTTPMethod.GET,
),
lambda_context,
)
assert r['statusCode'] == HTTPStatus.OK
body = json.loads(r['body'])
assert 'user' in body
assert 'course' in body

View File

@@ -4,4 +4,7 @@
{"id": "15bacf02-1535-4bee-9022-19d106fd7518", "sk": "emails#sergio@somosbeta.com.br"}
// User orgs
{"id": "213a6682-2c59-4404-9189-12eec0a846d4", "sk": "orgs#286f7729-7765-482a-880a-0b153ea799be", "name": "ACME", "cnpj": "00000000000191"}
{"id": "213a6682-2c59-4404-9189-12eec0a846d4", "sk": "orgs#286f7729-7765-482a-880a-0b153ea799be", "name": "ACME", "cnpj": "00000000000191"}
// Enrollment
{"id": "578ec87f-94c7-4840-8780-bb4839cc7e64", "sk": "0", "course": {"id": "af3258f0-bccf-4781-aec6-d4c618d234a7", "name": "pytest", "access_period": 180}, "user": {"id": "068b4600-cc36-4b55-b832-bb620021705a", "name": "Benjamin Burnley", "email": "burnley@breakingbenjamin.com"}}

View File

@@ -592,7 +592,7 @@ wheels = [
[[package]]
name = "layercake"
version = "0.11.0"
version = "0.11.1"
source = { directory = "../layercake" }
dependencies = [
{ name = "arnparse" },