Skip to content

Commit

Permalink
Update protos to include idempotency
Browse files Browse the repository at this point in the history
  • Loading branch information
slavovojacek committed May 26, 2024
1 parent 244416a commit 1157f27
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
26 changes: 18 additions & 8 deletions internal/template/service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ service {{ title $resource }}Service {

// Request message for Create{{ title $resource }} method.
message Create{{ title $resource }}Request {
// UUID used to prevent duplicate requests.
optional string request_id = 1;
// The {{ $resource }} to be created.
{{ title $resource }} {{ $resource }} = 1;
{{ title $resource }} {{ $resource }} = 2;
}

// Response message for Create{{ title $resource }} method.
Expand All @@ -47,7 +49,7 @@ message Create{{ title $resource }}Response {
// Request message for Get{{ title $resource }} method.
message Get{{ title $resource }}Request {
// ID of the {{ $resource }} to retrieve.
string id = 1;
string {{ $resource }}_id = 1;
}

// Response message for Get{{ title $resource }} method.
Expand All @@ -59,11 +61,13 @@ message Get{{ title $resource }}Response {
// Request message for List{{ title $resources }} method.
message List{{ title $resources }}Request {
// The maximum number of {{ $resources }} to return.
int32 page_size = 1;
optional int32 page_size = 1;
// The token to retrieve the next page of results.
string page_token = 2;
// The ID of the parent resource.
string parent_id = 3;
optional string page_token = 2;
{{- if and $parent $parents }}
// ID of the {{ $parent }} to list {{ $resources }} for.
optional string {{ $parent }}_id = 3;
{{- end }}
}

// Response message for List{{ title $resources }} method.
Expand All @@ -78,10 +82,14 @@ message List{{ title $resources }}Response {

// Request message for Update{{ title $resource }} method.
message Update{{ title $resource }}Request {
// UUID used to prevent duplicate requests.
optional string request_id = 1;
// ID of the {{ $resource }} to update.
string {{ $resource }}_id = 2;
// The {{ $resource }} to be updated.
{{ title $resource }} {{ $resource }} = 1;
{{ title $resource }} {{ $resource }} = 3;
// The field mask specifying the fields to update.
google.protobuf.FieldMask update_mask = 2;
google.protobuf.FieldMask update_mask = 4;
}

// Response message for Update{{ title $resource }} method.
Expand Down Expand Up @@ -112,4 +120,6 @@ message {{ title $resource }} {
// ID of the {{ $parent }} of the {{ $resource }}.
string {{ $parent }}_id = 4;
{{- end }}
// Additional fields for the {{ $resource }}.
// TODO: Add fields here.
}
22 changes: 14 additions & 8 deletions proto/authorservice/v1alpha1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ service AuthorService {

// Request message for CreateAuthor method.
message CreateAuthorRequest {
// UUID used to prevent duplicate requests.
optional string request_id = 1;
// The author to be created.
Author author = 1;
Author author = 2;
}

// Response message for CreateAuthor method.
Expand All @@ -43,7 +45,7 @@ message CreateAuthorResponse {
// Request message for GetAuthor method.
message GetAuthorRequest {
// ID of the author to retrieve.
string id = 1;
string author_id = 1;
}

// Response message for GetAuthor method.
Expand All @@ -55,11 +57,9 @@ message GetAuthorResponse {
// Request message for ListAuthors method.
message ListAuthorsRequest {
// The maximum number of authors to return.
int32 page_size = 1;
optional int32 page_size = 1;
// The token to retrieve the next page of results.
string page_token = 2;
// The ID of the parent resource.
string parent_id = 3;
optional string page_token = 2;
}

// Response message for ListAuthors method.
Expand All @@ -74,10 +74,14 @@ message ListAuthorsResponse {

// Request message for UpdateAuthor method.
message UpdateAuthorRequest {
// UUID used to prevent duplicate requests.
optional string request_id = 1;
// ID of the author to update.
string author_id = 2;
// The author to be updated.
Author author = 1;
Author author = 3;
// The field mask specifying the fields to update.
google.protobuf.FieldMask update_mask = 2;
google.protobuf.FieldMask update_mask = 4;
}

// Response message for UpdateAuthor method.
Expand All @@ -104,4 +108,6 @@ message Author {
google.protobuf.Timestamp create_time = 2;
// When the author was last updated.
google.protobuf.Timestamp update_time = 3;
// Additional fields for the author.
// TODO: Add fields here.
}
24 changes: 16 additions & 8 deletions proto/bookservice/v1alpha1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ service BookService {

// Request message for CreateBook method.
message CreateBookRequest {
// UUID used to prevent duplicate requests.
optional string request_id = 1;
// The book to be created.
Book book = 1;
Book book = 2;
}

// Response message for CreateBook method.
Expand All @@ -43,7 +45,7 @@ message CreateBookResponse {
// Request message for GetBook method.
message GetBookRequest {
// ID of the book to retrieve.
string id = 1;
string book_id = 1;
}

// Response message for GetBook method.
Expand All @@ -55,11 +57,11 @@ message GetBookResponse {
// Request message for ListBooks method.
message ListBooksRequest {
// The maximum number of books to return.
int32 page_size = 1;
optional int32 page_size = 1;
// The token to retrieve the next page of results.
string page_token = 2;
// The ID of the parent resource.
string parent_id = 3;
optional string page_token = 2;
// ID of the author to list books for.
optional string author_id = 3;
}

// Response message for ListBooks method.
Expand All @@ -74,10 +76,14 @@ message ListBooksResponse {

// Request message for UpdateBook method.
message UpdateBookRequest {
// UUID used to prevent duplicate requests.
optional string request_id = 1;
// ID of the book to update.
string book_id = 2;
// The book to be updated.
Book book = 1;
Book book = 3;
// The field mask specifying the fields to update.
google.protobuf.FieldMask update_mask = 2;
google.protobuf.FieldMask update_mask = 4;
}

// Response message for UpdateBook method.
Expand Down Expand Up @@ -106,4 +112,6 @@ message Book {
google.protobuf.Timestamp update_time = 3;
// ID of the author of the book.
string author_id = 4;
// Additional fields for the book.
// TODO: Add fields here.
}

0 comments on commit 1157f27

Please sign in to comment.