Skip to content

Commit

Permalink
switch ownign user on bank to be the users email
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Whited committed Oct 15, 2018
1 parent 2fba044 commit 41ca8c6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ run `dep ensure`; this will install necessary dependencies to the project and ge
- `{bankId}` is the unique id of the bank.
- CURL example
```bash
curl -XGET http://localhost:5002/api/v1/user/4b7b2def-e76e-48bf-993b-8ec2b193b855/bank/01e173f4-02a2-4310-a7cc-e2b919f13aac
curl -XGET http://localhost:5002/api/v1/user/[email protected]/bank/01e173f4-02a2-4310-a7cc-e2b919f13aac
```
- Example Response:
```json
{
"owningUserId": "4b7b2def-e76e-48bf-993b-8ec2b193b855",
"owningUserId": "[email protected]",
"bankId": "01e173f4-02a2-4310-a7cc-e2b919f13aac",
"bankName": "US Bank",
"accountNumber": "2112"
Expand All @@ -57,7 +57,7 @@ run `dep ensure`; this will install necessary dependencies to the project and ge
- Example Request Body
```json
{
"owningUserId": "4b7b2def-e76e-48bf-993b-8ec2b193b855",
"owningUserId": "[email protected]",
"bankName": "BANK NAME",
"accountNumber": "1234"
}
Expand All @@ -71,7 +71,7 @@ run `dep ensure`; this will install necessary dependencies to the project and ge
- Example Response
```json
{
"owningUserId": "4b7b2def-e76e-48bf-993b-8ec2b193b855",
"owningUserId": "[email protected]",
"bankId": "b920cfc7-c455-4ac6-b856-f9d3a416d9d1",
"bankName": "BANK NAME",
"accountNumber": "1234"
Expand Down
9 changes: 4 additions & 5 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ func PingHandler(w http.ResponseWriter, r *http.Request) {
// Grab the owningUserId and bankId out of the route params and use them to get a Bank record
func GetBankHandler(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
owningUserId := params["owningUserId"] // get the owning user id from request route params
_owningUserId := uuid.FromStringOrNil(owningUserId) // convert string id to uuid
bankId := params["bankId"] // get the bank id from the request route params
_bankId := uuid.FromStringOrNil(bankId) // convert bank id string to uuid
bank, err := GetBank(_owningUserId, _bankId) // get bank record
owningUserId := params["owningUserId"] // get the owning user id from request route params
bankId := params["bankId"] // get the bank id from the request route params
_bankId := uuid.FromStringOrNil(bankId) // convert bank id string to uuid
bank, err := GetBank(owningUserId, _bankId) // get bank record
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down
4 changes: 2 additions & 2 deletions services.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ func DoPing() Ping {

// Get a unique Bank record by the owningUserId and bankId composite key.
// Use the AWS DynamoDB service instance to query the UserBanks table in DynamoDB by the Primary & Sort key
func GetBank(owningUserId, bankId uuid.UUID) (bank *Bank, err error) {
func GetBank(owningUserId string, bankId uuid.UUID) (bank *Bank, err error) {
req := awsSvc.DynamoDbSvc().GetItemRequest(&dynamodb.GetItemInput{
TableName: aws.String("UserBanks"),
Key: map[string]dynamodb.AttributeValue{
"owningUserId": {
S: aws.String(owningUserId.String()),
S: aws.String(owningUserId),
},
"bankId": {
S: aws.String(bankId.String()),
Expand Down

0 comments on commit 41ca8c6

Please sign in to comment.