From 41ca8c60f66aaa14fc40711cac3e664c3e24373c Mon Sep 17 00:00:00 2001 From: Chris Whited Date: Sun, 14 Oct 2018 19:11:19 -0500 Subject: [PATCH] switch ownign user on bank to be the users email --- README.md | 8 ++++---- handlers.go | 9 ++++----- services.go | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9d6c2d4..b373377 100644 --- a/README.md +++ b/README.md @@ -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/test@test.com/bank/01e173f4-02a2-4310-a7cc-e2b919f13aac ``` - Example Response: ```json { - "owningUserId": "4b7b2def-e76e-48bf-993b-8ec2b193b855", + "owningUserId": "test@test.com", "bankId": "01e173f4-02a2-4310-a7cc-e2b919f13aac", "bankName": "US Bank", "accountNumber": "2112" @@ -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": "test@test.com", "bankName": "BANK NAME", "accountNumber": "1234" } @@ -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": "test@test.com", "bankId": "b920cfc7-c455-4ac6-b856-f9d3a416d9d1", "bankName": "BANK NAME", "accountNumber": "1234" diff --git a/handlers.go b/handlers.go index b30bcbe..bea2967 100644 --- a/handlers.go +++ b/handlers.go @@ -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 diff --git a/services.go b/services.go index 183bd82..75db476 100644 --- a/services.go +++ b/services.go @@ -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()),