From 1157f27fc90b497f2606bbeb5345e654382e1511 Mon Sep 17 00:00:00 2001 From: Slavo Vojacek Date: Sun, 26 May 2024 11:23:02 +0100 Subject: [PATCH] Update protos to include idempotency --- internal/template/service.tmpl | 26 +++++++++++++++------- proto/authorservice/v1alpha1/service.proto | 22 +++++++++++------- proto/bookservice/v1alpha1/service.proto | 24 +++++++++++++------- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/internal/template/service.tmpl b/internal/template/service.tmpl index 2e7a8fb..3e9cdae 100644 --- a/internal/template/service.tmpl +++ b/internal/template/service.tmpl @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. } diff --git a/proto/authorservice/v1alpha1/service.proto b/proto/authorservice/v1alpha1/service.proto index 01a8777..4c880c0 100644 --- a/proto/authorservice/v1alpha1/service.proto +++ b/proto/authorservice/v1alpha1/service.proto @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. } diff --git a/proto/bookservice/v1alpha1/service.proto b/proto/bookservice/v1alpha1/service.proto index 139d53e..eebd507 100644 --- a/proto/bookservice/v1alpha1/service.proto +++ b/proto/bookservice/v1alpha1/service.proto @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. }