diff --git a/entproto/cmd/protoc-gen-entgrpc/template/method_list.tmpl b/entproto/cmd/protoc-gen-entgrpc/template/method_list.tmpl index 053233f89..d62b5910d 100644 --- a/entproto/cmd/protoc-gen-entgrpc/template/method_list.tmpl +++ b/entproto/cmd/protoc-gen-entgrpc/template/method_list.tmpl @@ -29,12 +29,13 @@ {{- template "field_to_ent" dict "Field" .G.FieldMap.ID "VarName" "pageToken" "Ident" "token" }} {{- else if .G.EntType.ID.IsUUID }} - pageToken, err := {{ qualify "github.com/google/uuid" "ParseBytes" }}(bytes) + token, err := {{ qualify "github.com/google/uuid" "ParseBytes" }}(bytes) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "page token is invalid") } + {{- template "field_to_ent" dict "Field" .G.FieldMap.ID "VarName" "pageToken" "Ident" "[]byte(token[:])" }} {{- else if .G.EntType.ID.IsString }} - pageToken := string(bytes) + {{- template "field_to_ent" dict "Field" .G.FieldMap.ID "VarName" "pageToken" "Ident" "bytes" }} {{- end }} listQuery = listQuery. Where({{ qualify (print (unquote .G.EntPackage.String) "/" .G.EntType.Package) "IDLTE" }}(pageToken)) diff --git a/entproto/internal/todo/ent/proto/entpb/entpb_attachment_service.go b/entproto/internal/todo/ent/proto/entpb/entpb_attachment_service.go index 407aa4756..a474940a2 100644 --- a/entproto/internal/todo/ent/proto/entpb/entpb_attachment_service.go +++ b/entproto/internal/todo/ent/proto/entpb/entpb_attachment_service.go @@ -203,10 +203,14 @@ func (svc *AttachmentService) List(ctx context.Context, req *ListAttachmentReque if err != nil { return nil, status.Errorf(codes.InvalidArgument, "page token is invalid") } - pageToken, err := uuid.ParseBytes(bytes) + token, err := uuid.ParseBytes(bytes) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "page token is invalid") } + var pageToken uuid.UUID + if err := (&pageToken).UnmarshalBinary([]byte(token[:])); err != nil { + return nil, status.Errorf(codes.InvalidArgument, "invalid argument: %s", err) + } listQuery = listQuery. Where(attachment.IDLTE(pageToken)) }