User service: Generate user id if empty (#160)

This commit is contained in:
Janos Dobronszki
2021-06-15 12:39:07 +01:00
committed by GitHub
parent fe0f4f4169
commit b73dab3345
3 changed files with 5 additions and 3 deletions

2
go.mod
View File

@@ -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

View File

@@ -8,7 +8,6 @@
"password": "mySecretPass123"
},
"response": {
"id": "1"
}
}],
"read": [{

View File

@@ -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),