Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from CastyLab/develop
Browse files Browse the repository at this point in the history
Adding Get Single Connection in user service
  • Loading branch information
mrjosh authored Aug 26, 2020
2 parents b7ed9f2 + 9d324ef commit 0f07586
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/CastyLab/grpc.server
go 1.14

require (
github.com/CastyLab/grpc.proto v0.0.0-20200826181838-2f9360028306
github.com/CastyLab/grpc.proto v0.0.0-20200826191006-9099557119fd
github.com/MrJoshLab/go-respond v0.0.0-20191125172458-25d4d18aaa1b
github.com/asticode/go-astisub v0.2.0
github.com/dgrijalva/jwt-go v3.2.0+incompatible
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ github.com/CastyLab/grpc.proto v0.0.0-20200826180959-ee61a995f35f h1:+gsV1RgXrjP
github.com/CastyLab/grpc.proto v0.0.0-20200826180959-ee61a995f35f/go.mod h1:5ypgijUv7rWXMsRbUZXEgTucAA+4BpHtXgGIvOyUGRU=
github.com/CastyLab/grpc.proto v0.0.0-20200826181838-2f9360028306 h1:rxE+/s9/T0FQGEDD2J+FtgwVAZuQWSRJzr0Yt6hXa9g=
github.com/CastyLab/grpc.proto v0.0.0-20200826181838-2f9360028306/go.mod h1:5ypgijUv7rWXMsRbUZXEgTucAA+4BpHtXgGIvOyUGRU=
github.com/CastyLab/grpc.proto v0.0.0-20200826191006-9099557119fd h1:FBfJeHIVSQ8mCDTg1WP3FQRjpFpC0d67Zvc1uq+0UxQ=
github.com/CastyLab/grpc.proto v0.0.0-20200826191006-9099557119fd/go.mod h1:5ypgijUv7rWXMsRbUZXEgTucAA+4BpHtXgGIvOyUGRU=
github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EFZQ978U7x8IRnstaskI3IysnWY5Ao3QgZUKOXlsAdw=
github.com/CloudyKit/jet v2.1.3-0.20180809161101-62edd43e4f88+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w=
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
Expand Down
42 changes: 42 additions & 0 deletions services/user/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,48 @@ import (
"net/http"
)

func (s *Service) GetConnection(ctx context.Context, req *proto.GetConnectionRequest) (*proto.ConnectionsResponse, error) {

var (
connections = make([]*proto.Connection, 0)
collection = db.Connection.Collection("connections")
)

user, err := auth.Authenticate(req.AuthRequest)
if err != nil {
return nil, err
}

filter := bson.M{
"type": req.Connection.Type,
"user_id": user.ID,
}

cursor, err := collection.Find(ctx, filter)
if err != nil {
return nil, status.Error(codes.NotFound, "Could not find connections!")
}

for cursor.Next(ctx) {
connection := new(models.Connection)
if err := cursor.Decode(connection); err != nil {
continue
}
protoConnection, err := helpers.NewProtoConnection(connection)
if err != nil {
continue
}
connections = append(connections, protoConnection)
}

return &proto.ConnectionsResponse{
Status: "success",
Code: http.StatusOK,
Result: connections,
}, nil

}

func (s *Service) GetConnections(ctx context.Context, req *proto.AuthenticateRequest) (*proto.ConnectionsResponse, error) {

var (
Expand Down

0 comments on commit 0f07586

Please sign in to comment.