Skip to content

Commit

Permalink
Merge pull request #2 from decentralized-cloud/added-userid
Browse files Browse the repository at this point in the history
Added userID to the read user by email response
  • Loading branch information
mortezaalizadeh committed Feb 14, 2021
2 parents 16a34f7 + cc148d2 commit fa52be9
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 125 deletions.
238 changes: 124 additions & 114 deletions contract/grpc/go/user.pb.go

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion contract/grpc/proto/user.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,11 @@ message ReadUserByEmailResponse {
// Contains error message if the operation was unsuccessful
string errorMessage = 2;

// The unique user identifier
string userID = 3;

// The user object
User user = 3;
User user = 4;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/onsi/gomega v1.10.5
github.com/prometheus/client_golang v1.9.0
github.com/savsgio/atreugo/v11 v11.6.0
github.com/spf13/cobra v1.1.1
github.com/spf13/cobra v1.1.3
github.com/thoas/go-funk v0.7.0
go.mongodb.org/mongo-driver v1.4.6
go.uber.org/zap v1.16.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasO
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v1.1.1 h1:KfztREH0tPxJJ+geloSLaAkaPkr4ki2Er5quFV1TDo4=
github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=
github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M=
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
Expand Down
5 changes: 3 additions & 2 deletions services/business/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ type ReadUserByEmailRequest struct {

// ReadUserByEmailResponse contains the result of reading an existing user by email address
type ReadUserByEmailResponse struct {
Err error
User models.User
Err error
UserID string
User models.User
}

// UpdateUserRequest contains the request to update an existing user
Expand Down
3 changes: 2 additions & 1 deletion services/business/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ func (service *businessService) ReadUserByEmail(
}

return &ReadUserByEmailResponse{
User: response.User,
UserID: response.UserID,
User: response.User,
}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion services/repository/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ type ReadUserByEmailRequest struct {

// ReadUserByEmailResponse contains the result of reading an existing user by email address
type ReadUserByEmailResponse struct {
User models.User
UserID string
User models.User
}

// UpdateUserRequest contains the request to update an existing user
Expand Down
15 changes: 13 additions & 2 deletions services/repository/mongodb/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,24 @@ func (service *mongodbRepositoryService) ReadUserByEmail(
filter := bson.D{{Key: "email", Value: request.Email}}
var user models.User

err = collection.FindOne(ctx, filter).Decode(&user)
result := collection.FindOne(ctx, filter)
err = result.Decode(&user)
if err != nil {
return nil, repository.NewUserByEmailNotFoundError(request.Email)
}

var userBson bson.M

err = result.Decode(&userBson)
if err != nil {
return nil, repository.NewUnknownErrorWithError("Failed to load user bson data", err)
}

userID := userBson["_id"].(primitive.ObjectID).Hex()

return &repository.ReadUserByEmailResponse{
User: user,
UserID: userID,
User: user,
}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion services/transport/grpc/encoder-decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ func encodeReadUserByEmailResponse(

if castedResponse.Err == nil {
return &userGRPCContract.ReadUserByEmailResponse{
Error: userGRPCContract.Error_NO_ERROR,
Error: userGRPCContract.Error_NO_ERROR,
UserID: castedResponse.UserID,
User: &userGRPCContract.User{
Email: castedResponse.User.Email,
},
Expand Down

0 comments on commit fa52be9

Please sign in to comment.