Skip to content

Conversation

@vic-cortes
Copy link

Lambda Excercise with python aproach. This PR introduce using pydantic V2 as data validator and uv for fast library installations.

- Add *.csv to .gitignore to exclude data files
- Add set_env_variables target for AWS credential management
- Add export_serverless_requirements target for Python dependency compilation
- Update requirements.txt with uv-generated dependencies including python-dotenv
- Add check_lambda_status target to Makefile for monitoring function state
- Replace pip with uv pip install in deploy script for faster dependency resolution
Replace hardcoded status code with HTTPStatus.OK enum and add boto3>=1.40.67 dependency for AWS services integration
- Add SubscriptionTable class extending DynamoFender for subscription data operations
- Replace inline response dict with success_response utility function
- Simplify handler to use centralized response formatting
Add pydantic>=2.12.4 to project dependencies along with all required transitive dependencies including annotated-types, pydantic-core, typing-extensions, and typing-inspection. This enables robust data validation and serialization capabilities for the application.
…antic

- Add generic write method to DynamoFender base class with batch writing support
- Implement type-safe write method in SubscriptionTable using SubscriptionSchema
- Migrate dataclass schemas to Pydantic BaseModel for better validation
- Update table name from "sub" to "FenderSubscriptions"
- Add proper type annotations and validation for subscription status
- Changed import from src.utils.response to utils.response for correct module resolution
- Added debug print statement to log event and context parameters in handler function
Move boto3 from main dependencies to dev dependency group since it's only needed for development/testing. Add ipython to dev dependencies for better development experience. Update requirements.txt to reflect removal of AWS-related packages from production dependencies.
Add SubscriptionType enum, MetadataSchema, and SubscriptionEvent models with helper properties to support subscription event handling and type checking.
Add pytest>=8.4.2 to development dependencies for unit testing support. This includes the pytest package and its required dependencies (iniconfig, packaging, pluggy) in the lock file.
…event tests

- Remove complex Annotated type constraint from PlanSchema.status field
- Replace with simple list type for better flexibility
- Add comprehensive test for SubscriptionEvent schema validation
- Include sample data structure for subscription event testing
- Add EVENT_SAMPLE with realistic AWS API Gateway event structure for testing
- Import json module and wrap response body in JSON format with message field
- Enhance test data coverage for subscription endpoint scenarios
- Add SupportedMethods enum for GET and POST operations
- Create EventSchema with httpMethod validation and convenience properties
- Rename EVENT_SAMPLE to GET_EVENT_SUBSCRIPTION for clarity
- Add POST_EVENT_SUBSCRIPTION test data with request body
- Enable method-specific validation through is_get and is_post properties
- Replace generic typing with Literal for stronger type constraints
- Make cancelledAt field optional with union type
- Add EventSchema import and implement HTTP method validation tests
- Rename test constants for better AWS context clarity
- Add new SubscriptionStatus enum with ACTIVE, PENDING, CANCELLED states
- Add PlanStatus enum separate from SubscriptionStatus
- Add cancelledAt field to SubscriptionEvent model
- Implement cancellation date parsing and status computation logic
- Add properties to determine pending/cancelled states based on timestamps
- Update test data variable name for clarity (SAMPLE_DATA -> CREATED_SUBSCRIPTION_EVENT)
- Add PlanTable class to dynamo.py for FenderPlans table management
- Create BillingCycle enum with MONTHLY and YEARLY options
- Set default value "sub" for SubscriptionSchema type field
- Improve PlanSchema type hints with stricter literal types and list[str]
- Add path, body, and pathParameters fields to EventSchema for better request handling
- Rename SubscriptionEvent to SubscriptionEventPayload for clarity
- Implement event validation in Lambda handler using EventSchema
- Update tests to reflect model rename and maintain functionality
- Replace hardcoded response with Router class for event processing
- Add router import and instantiation in main handler
- Fix relative imports in routes.py and tests
- Add basic handler test for success response validation
… GET handler

- Moved success_response import from main.py to routes.py where it's actually used
- Implemented GET method handler to return success response instead of placeholder pass statement
- Improves code organization by placing imports closer to their usage
- Add new SubscriptionPlanModel class with payload attribute
- Import SubscriptionEventPayload from schemas module
- Extend model layer to support subscription plan events
… structure

- Update AWS_KEY_ID and AWS_KEY_SECRET to standard AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
- Fix import path in dynamo.py to use relative import
- Add BaseModel inheritance to data models with proper payload attributes
- Add documentation to SubscriptionPlanModel class
- Import DynamoFenderTables in test module
- Add DynamoDB serialization utilities for data type conversion
- Simplify batch_write method to accept both dict and list inputs
- Add get_by_pk and get_or_create methods to DynamoFender class
- Move data models from schemas to models module with proper separation
- Add pk/sk properties to SubscriptionEventPayload for DynamoDB keys
- Create adapter pattern for subscription and plan operations
- Remove duplicate enum definitions and consolidate in models
- Add create method to SubscriptionModel for DynamoDB writes
- Replace placeholder create method in SubscriptionAdapter with process method
- Implement complete subscription data mapping from event payload
- Remove unused SubscriptionPlanModel class
- Add proper field mapping for subscription attributes and metadata
…Table methods

- Remove unused SubscriptionSchema import and write method from SubscriptionTable
- Refactor SubscriptionAdapter.process() to use private _create() method for better separation of concerns
- Replace union type syntax with Optional for better Python 3.8+ compatibility
- Add new test for SubscriptionAdapter and skip existing tests temporarily
- Add faker dependency for generating mock plan data
- Update DynamoFender.write() to accept dict or list parameters
- Implement PlanAdapter.create() method with random billing cycles and features
- Add plan_name property to SubscriptionEventPayload for formatted plan names
- Update SubscriptionModel to ignore None values when writing to database
…ta flow

- Add default values to model fields (cancelledAt, lastModified)
- Implement get() methods for existence checking in adapters
- Add create() method to PlanModel for database operations
- Refactor adapter methods to check existence before creation
- Create unified process_subscription_and_plan() function
- Integrate processing logic into post_user_subscription route
- Fix feature naming capitalization and add lastModified tracking
- Add validation_wrapper decorator for error handling
- Fix model_dump parameter from ignore_none to exclude_none
- Change SubscriptionAdapter.process() return type to bool
- Add error_response utility function
- Enable test_handler_post_event and skip test_subscription_adapter
- Import validation_wrapper in models module
- Add dynamo_write_serializer function to convert float values to Decimal for DynamoDB compatibility
- Update batch_put_items to use serializer before writing data
- Modify process_subscription_and_plan to return success_response instead of boolean
- Streamline post_user_subscription to directly return processed response
- Add debug print statement in test for response validation
- Fix DynamoDB table reference from PLAN to SUBSCRIPTION in SubscriptionAdapter
- Extract subscription methods from Router class to standalone functions
- Implement user ID extraction for GET requests from path parameters
- Replace success_response with error_response for unsupported methods
- Update test data with simplified user IDs and path parameters
…ndpoint

- Rename public methods to private (_get_by_pk) in SubscriptionAdapter and PlanAdapter
- Fix SubscriptionAdapter to use userId instead of planSku for lookup
- Add new SubscriptionAndPlanAdapter class for combined subscription/plan retrieval
- Add retrieve() methods with proper error handling for missing records
- Implement process_user_id function and router_get_user_subscription endpoint
- Update route handlers with consistent naming (router_ prefix)
- Enhance EventSchema with typed UserParamsSchema for path parameters
- Improve pathParameters access from dict.get() to direct attribute access
- Move SubscriptionStatus enum from schemas to models module
- Add SubscriptionAttributes model for structured subscription data
- Implement status computation logic with pending/cancelled state detection
- Update SubscriptionModel with datetime utilities and status methods
- Enhance SubscriptionAndPlanAdapter to return structured subscription data
- Remove redundant status logic from schemas module
Replace print statement with proper success response and enhance success_response utility to support optional data payload for better API consistency
- Add faker==37.12.0 and tzdata==2025.2 dependencies for fake data generation
- Change default environment from "development" to "staging" in config
- Implement try/except import pattern across all modules for dual compatibility between local development (relative imports) and AWS Lambda deployment (absolute imports)
- Ensure application works seamlessly in both local and serverless environments
- Add comment explaining uv usage for faster package installs
- Include detailed NOTE about pydantic v2 AWS Lambda deployment requirements
- Reference official pydantic documentation for Lambda compatibility
- Provide option to comment out pydantic-specific steps if not using v2
- Change parse_cancelledAt from property to method with error handling
- Reorder subscription processing before plan processing
- Add route documentation and use HTTPStatus enum for better readability
- Update method calls to use new parse_cancelled_at() function signature
…ssing

- Add DynamoDB update method with field constants for pk/sk handling
- Implement renewal and cancellation update logic in SubscriptionAdapter
- Fix subscription status logic to use lastModified instead of current time
- Remove redundant cancelledAt field from initial subscription creation
- Rename retrieve methods to process for better semantic clarity
- Add SK_FIELD validation and inclusion in DynamoDB update operations
- Include sort key in subscription update methods for proper composite key handling
- Add internalStatus field tracking for ACTIVE/CANCELLED subscription states
- Conditionally include cancelledAt field only when subscription is cancelled
- Remove unused return statement and improve data structure handling
- Fix is_pending/is_cancelled comparison operators to use strict inequalities
- Add validation_wrapper decorator to process_event method
- Make paymentId optional in SubscriptionEventPayload schema
- Expand test coverage to include GET, CREATE, RENEW, and CANCEL subscription flows
- Update EventSchema.body type from dict to str to match AWS Lambda event format
- Add parse_body() method to EventSchema for JSON deserialization
- Update router to use parse_body() instead of direct body access
- Update test fixture to serialize body as JSON string
Add new DynamoDB table handler class to support querying subscriptions and plans together, improving data access patterns for the fender digital code exercise use case.
… structure

- Change table reference from SUBSCRIPTION to SUBSCRIPTIONS_AND_PLANS
- Make _get_by_pk() method public and use payload.pk instead of userId
- Update _create() method to use payload.pk and payload.sk properties
- Add pk and sk properties to SubscriptionEventPayload schema
- Add new SubscriptionAndPlanAdapterPost model class
…cture

- Remove unused timezone import from datetime
- Add plan_pk property to SubscriptionModel for consistent key generation
- Update table references from separate SUBSCRIPTION/PLAN to unified SUBSCRIPTIONS_AND_PLANS
- Add is_active/is_inactive properties to PlanModel for status validation
- Refactor SubscriptionAdapter methods to use sub_pk/plan_pk naming convention
- Add plan validation in subscription processing to prevent inactive plan usage
- Update key generation patterns across adapters for consistency
Remove "plan:" prefix from plan_pk properties to simplify key format. Update _get_plan_by_pk method to use SUBSCRIPTIONS_AND_PLANS table instead of PLAN table and rename parameter for clarity. Clean up commented code and add minor formatting improvements.
…lass

Refactored SubscriptionAdapter by extracting subscription data transformation logic into a dedicated SubscriptionDetailsSchema class. This improves code organization, reusability, and maintainability while keeping the same functionality. Also uncommented a test assertion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant