Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extends API capabilities to interact with Database (#7)
* feat: Adds formal API path for playerHand The `playerHand` path has been added to the legalBrawl API. This will be the destination where POST requests are made by the game client to submit, and in return receive an opposing player's selected cards. A model has been added to ensure that the body's JSON data is valid before it reaches the Lambda (though this doesn't stop unsanitary inputs, it's a matter of validation at a schema-level). * feat: Adds handling for POST reqs to playerHand A first-cut of handling logic for POST requests to `playerHand` has been added. Currently, this only *submits* `playerHandInfo` payloads into the `playerHands` database. This change provides the capability for an HTTP POST request of a specific format to be inserted into the `playerHands` dynamoDB database using the `PutItem` API. Known Bugs: - There is currently an unhandled scenario where if an entry already exists, it should return an error - When marshalling the Golang struct to a DynamoDB struct using `MarshalMap`, there doesn't seem to be any indication that the payload coming in is bogus. For example, a field could be called "hand" rather than "card". This causes the data for the unmatching field to be "Null". * refactor: Reorganizes aws package The `aws` package use by the `legalbrawlapi` module is getting needlessly deep, and is causing circular dependencies. Because the API gateway request body is being used by DynamoDB in `PutItem` requests (among others). This "flattening" of the structure should better support the requirements that these two components have. * refactor: Merges struct types Throughout the API Gateway and DynamoDB code, there were similarities that were suitable to merge into common struct types. The benefit of this is that bespoke "conversion" logic isn't necessary if HandInfo is a 1:1 to its DynamoDB counterpart. So in theory the body coming in from the request can immediately be used in the `PutItem` API call. This results in (hopefully) maintable code, while also still being terse. * refactor: Changes type scopes for aws package to private * chore: Tweaks HandleRequest function * doc: Adds docstring to addHand method * doc: Removes "bug" regarding duplicate hands. Players may be using their existing hand for matchmaking. Since DynamoDB doesn't duplicate entries anyway. This isn't a bug as far as we would be concerned. This may change as requirements evolve. * feat: Adds POST and GET to playerHands API * feat: Adds timeout to playerHands GET request * feat: Adds timeout to playerHands POST request * feat: Adds PUT method to API * feat: Adds validation to POST & PUT methods NOTE: The requestValidatorOptions had to be broken out into individual objects. Refer to: aws/aws-cdk#7613 * feat: Adds validation to GET method * feat: Adds API-side validation of GET method * feat: Adds API-side validation of POST and PUT request * feat: Adds logic to PUT request * feat: Adds preexisting player checks for POST request * chore: Cleans up error codes, and messages for apigateway * refactor: Removes an unnecessary dDBHandler client creation * feat: Adds timeout to playerHands PUT request
- Loading branch information