From d7b4a6b278d7be90fef0e57bc3353e21c41efe06 Mon Sep 17 00:00:00 2001 From: agungdwiprasetyo Date: Thu, 2 May 2024 15:36:00 +0700 Subject: [PATCH] update grpc delivery template --- cmd/candi/template_delivery_grpc.go | 56 ++++++++++++++--------------- go.mod | 2 +- go.sum | 4 +-- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/cmd/candi/template_delivery_grpc.go b/cmd/candi/template_delivery_grpc.go index e4504f9..efbb59e 100644 --- a/cmd/candi/template_delivery_grpc.go +++ b/cmd/candi/template_delivery_grpc.go @@ -79,7 +79,7 @@ func (h *GRPCHandler) GetAll{{upper (camel .ModuleName)}}(ctx context.Context, r for _, d := range result.Data { data := &proto.{{upper (camel .ModuleName)}}Model{ - ID: {{if and .MongoDeps (not .SQLDeps)}}d.ID{{else}}int64(d.ID){{end}}, Field: d.Field, CreatedAt: d.CreatedAt, UpdatedAt: d.UpdatedAt, + Id: {{if and .MongoDeps (not .SQLDeps)}}d.ID{{else}}int64(d.ID){{end}}, Field: d.Field, CreatedAt: d.CreatedAt, UpdatedAt: d.UpdatedAt, } resp.Data = append(resp.Data, data) } @@ -94,13 +94,13 @@ func (h *GRPCHandler) GetDetail{{upper (camel .ModuleName)}}(ctx context.Context // tokenClaim := candishared.ParseTokenClaimFromContext(ctx) // must using GRPCBearerAuth in middleware for this handler - data, err := h.uc.{{upper (camel .ModuleName)}}().GetDetail{{upper (camel .ModuleName)}}(ctx, {{if and .MongoDeps (not .SQLDeps)}}req.ID{{else}}int(req.ID){{end}}) + data, err := h.uc.{{upper (camel .ModuleName)}}().GetDetail{{upper (camel .ModuleName)}}(ctx, {{if and .MongoDeps (not .SQLDeps)}}req.Id{{else}}int(req.Id){{end}}) if err != nil { return nil, status.Errorf(codes.FailedPrecondition, err.Error()) } resp := &proto.{{upper (camel .ModuleName)}}Model{ - ID: {{if and .MongoDeps (not .SQLDeps)}}data.ID{{else}}int64(data.ID){{end}}, Field: data.Field, CreatedAt: data.CreatedAt, UpdatedAt: data.UpdatedAt, + Id: {{if and .MongoDeps (not .SQLDeps)}}data.ID{{else}}int64(data.ID){{end}}, Field: data.Field, CreatedAt: data.CreatedAt, UpdatedAt: data.UpdatedAt, } return resp, nil } @@ -123,7 +123,7 @@ func (h *GRPCHandler) Create{{upper (camel .ModuleName)}}(ctx context.Context, r } resp = &proto.{{upper (camel .ModuleName)}}Model{ - ID: {{if and .MongoDeps (not .SQLDeps)}}data.ID{{else}}int64(data.ID){{end}}, Field: data.Field, CreatedAt: data.CreatedAt, UpdatedAt: data.UpdatedAt, + Id: {{if and .MongoDeps (not .SQLDeps)}}data.ID{{else}}int64(data.ID){{end}}, Field: data.Field, CreatedAt: data.CreatedAt, UpdatedAt: data.UpdatedAt, } return resp, nil } @@ -136,7 +136,7 @@ func (h *GRPCHandler) Update{{upper (camel .ModuleName)}}(ctx context.Context, r // tokenClaim := candishared.ParseTokenClaimFromContext(ctx) // must using GRPCBearerAuth in middleware for this handler var payload domain.Request{{upper (camel .ModuleName)}} - payload.ID = {{if and .MongoDeps (not .SQLDeps)}}req.ID{{else}}int(req.ID){{end}} + payload.ID = {{if and .MongoDeps (not .SQLDeps)}}req.Id{{else}}int(req.Id){{end}} payload.Field = req.Field if err := h.validator.ValidateDocument("{{cleanPathModule .ModuleName}}/save", payload); err != nil { return nil, status.Errorf(codes.InvalidArgument, err.Error()) @@ -157,7 +157,7 @@ func (h *GRPCHandler) Delete{{upper (camel .ModuleName)}}(ctx context.Context, r // tokenClaim := candishared.ParseTokenClaimFromContext(ctx) // must using GRPCBearerAuth in middleware for this handler - if err := h.uc.{{upper (camel .ModuleName)}}().Delete{{upper (camel .ModuleName)}}(ctx, {{if and .MongoDeps (not .SQLDeps)}}req.ID{{else}}int(req.ID){{end}}); err != nil { + if err := h.uc.{{upper (camel .ModuleName)}}().Delete{{upper (camel .ModuleName)}}(ctx, {{if and .MongoDeps (not .SQLDeps)}}req.Id{{else}}int(req.Id){{end}}); err != nil { return nil, status.Errorf(codes.FailedPrecondition, err.Error()) } @@ -180,46 +180,46 @@ service {{upper (camel .ModuleName)}}Handler { } message Meta { - int64 Limit=1; - int64 Page=2; - int64 TotalRecords=3; - int64 TotalPages=4; + int64 limit=1; + int64 page=2; + int64 totalRecords=3; + int64 totalPages=4; } message GetAll{{upper (camel .ModuleName)}}Request { - int64 Limit=1; - int64 Page=2; - string Search=3; - string OrderBy=4; - string Sort=5; - bool ShowAll=6; - string StartDate=7; - string EndDate=8; + int64 limit=1; + int64 page=2; + string search=3; + string orderBy=4; + string sort=5; + bool showAll=6; + string startDate=7; + string endDate=8; } message GetAll{{upper (camel .ModuleName)}}Response { - Meta Meta=1; - repeated {{upper (camel .ModuleName)}}Model Data=2; + Meta meta=1; + repeated {{upper (camel .ModuleName)}}Model data=2; } message GetDetail{{upper (camel .ModuleName)}}Request { - {{if and .MongoDeps (not .SQLDeps)}}string{{else}}int64{{end}} ID=1; + {{if and .MongoDeps (not .SQLDeps)}}string{{else}}int64{{end}} id=1; } message Request{{upper (camel .ModuleName)}}Model { - {{if and .MongoDeps (not .SQLDeps)}}string{{else}}int64{{end}} ID=1; - string Field=2; + {{if and .MongoDeps (not .SQLDeps)}}string{{else}}int64{{end}} id=1; + string field=2; } message {{upper (camel .ModuleName)}}Model { - {{if and .MongoDeps (not .SQLDeps)}}string{{else}}int64{{end}} ID=1; - string Field=2; - string CreatedAt=3; - string UpdatedAt=4; + {{if and .MongoDeps (not .SQLDeps)}}string{{else}}int64{{end}} id=1; + string field=2; + string createdAt=3; + string updatedAt=4; } message BaseResponse { - string Message=1; + string message=1; } ` ) diff --git a/go.mod b/go.mod index baf17ee..19f6347 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( go.mongodb.org/mongo-driver v1.15.0 go.uber.org/zap v1.27.0 google.golang.org/grpc v1.63.2 - google.golang.org/protobuf v1.33.0 + google.golang.org/protobuf v1.34.0 ) require ( diff --git a/go.sum b/go.sum index 079b668..984768a 100644 --- a/go.sum +++ b/go.sum @@ -223,8 +223,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be h1: google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= +google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=