From b73dab33452dad081fd9689c5de6effffebac631 Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Tue, 15 Jun 2021 12:39:07 +0100 Subject: [PATCH] User service: Generate user id if empty (#160) --- go.mod | 2 +- user/examples.json | 1 - user/handler/handler.go | 5 ++++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 8bc6cb9..b91b204 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/lib/pq v1.9.0 // indirect github.com/mattheath/base62 v0.0.0-20150408093626-b80cdc656a7a // indirect github.com/mattheath/kala v0.0.0-20171219141654-d6276794bf0e - github.com/micro/dev v0.0.0-20201117163752-d3cfc9788dfa + github.com/micro/dev v0.0.0-20201117163752-d3cfc9788dfa // indirect github.com/micro/micro/v3 v3.3.1-0.20210611161948-fd9821dd4f52 github.com/miekg/dns v1.1.31 // indirect github.com/onsi/ginkgo v1.15.0 // indirect diff --git a/user/examples.json b/user/examples.json index 494d9f3..7342c54 100644 --- a/user/examples.json +++ b/user/examples.json @@ -8,7 +8,6 @@ "password": "mySecretPass123" }, "response": { - "id": "1" } }], "read": [{ diff --git a/user/handler/handler.go b/user/handler/handler.go index 6701147..e5d14b2 100644 --- a/user/handler/handler.go +++ b/user/handler/handler.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "github.com/google/uuid" "github.com/micro/micro/v3/service/errors" db "github.com/micro/services/db/proto" "github.com/micro/services/user/domain" @@ -54,7 +55,9 @@ func (s *User) Create(ctx context.Context, req *pb.CreateRequest, rsp *pb.Create return errors.InternalServerError("user.Create", err.Error()) } pp := base64.StdEncoding.EncodeToString(h) - + if req.Id == "" { + req.Id = uuid.New().String() + } return s.domain.Create(ctx, &pb.Account{ Id: req.Id, Username: strings.ToLower(req.Username),