Skip to content

Commit

Permalink
update grpc delivery template
Browse files Browse the repository at this point in the history
  • Loading branch information
agungdwiprasetyo committed May 2, 2024
1 parent 2acc9a1 commit d7b4a6b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
56 changes: 28 additions & 28 deletions cmd/candi/template_delivery_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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())
Expand All @@ -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())
}
Expand All @@ -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;
}
`
)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit d7b4a6b

Please sign in to comment.