add discount

This commit is contained in:
2025-12-24 01:40:07 -03:00
parent 1a59ad9e91
commit 2459bafc5d
16 changed files with 423 additions and 132 deletions

View File

@@ -15,7 +15,7 @@ from aws_lambda_powertools.utilities.typing import LambdaContext
from api_gateway import JSONResponse
from json_encoder import JSONEncoder
from middlewares.authentication_middleware import AuthenticationMiddleware
from routes import courses, enrollments, orders, orgs, users
from routes import coupons, courses, enrollments, orders, orgs, users
logger = Logger(__name__)
tracer = Tracer()
@@ -35,6 +35,7 @@ app = APIGatewayHttpResolver(
)
app.use(middlewares=[AuthenticationMiddleware()])
app.enable_swagger(path='/swagger')
app.include_router(coupons.router, prefix='/coupons')
app.include_router(courses.router, prefix='/courses')
app.include_router(enrollments.router, prefix='/enrollments')
app.include_router(enrollments.cancel, prefix='/enrollments')

View File

@@ -0,0 +1,25 @@
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 Path
from layercake.dynamodb import DynamoDBPersistenceLayer, KeyPair
from boto3clients import dynamodb_client
from config import ORDER_TABLE
router = Router()
dyn = DynamoDBPersistenceLayer(ORDER_TABLE, dynamodb_client)
class CouponNotFoundError(NotFoundError): ...
@router.get('/<coupon>')
def coupon(coupon: Annotated[str, Path(min_length=3)]):
return dyn.collection.get_item(
KeyPair('COUPON', coupon.upper()),
exc_cls=CouponNotFoundError,
)