library.proto 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // Copyright (c) 2015, Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.example.library.v1;
  16. import "google/api/annotations.proto";
  17. import "google/protobuf/empty.proto";
  18. option java_multiple_files = true;
  19. option java_outer_classname = "LibraryProto";
  20. option java_package = "com.google.example.library.v1";
  21. // This API represents a simple digital library. It lets you manage Shelf
  22. // resources and Book resources in the library. It defines the following
  23. // resource model:
  24. //
  25. // - The API has a collection of [Shelf][google.example.library.v1.Shelf]
  26. // resources, named `shelves/*`
  27. //
  28. // - Each Shelf has a collection of [Book][google.example.library.v1.Book]
  29. // resources, named `shelves/*/books/*`
  30. service LibraryService {
  31. // Creates a shelf, and returns the new Shelf.
  32. rpc CreateShelf(CreateShelfRequest) returns (Shelf) {
  33. option (google.api.http) = { post: "/v1/shelves" body: "shelf" };
  34. }
  35. // Gets a shelf. Returns NOT_FOUND if the shelf does not exist.
  36. rpc GetShelf(GetShelfRequest) returns (Shelf) {
  37. option (google.api.http) = { get: "/v1/{name=shelves/*}" };
  38. }
  39. // Lists shelves. The order is unspecified but deterministic. Newly created
  40. // shelves will not necessarily be added to the end of this list.
  41. rpc ListShelves(ListShelvesRequest) returns (ListShelvesResponse) {
  42. option (google.api.http) = { get: "/v1/shelves" };
  43. }
  44. // Deletes a shelf. Returns NOT_FOUND if the shelf does not exist.
  45. rpc DeleteShelf(DeleteShelfRequest) returns (google.protobuf.Empty) {
  46. option (google.api.http) = { delete: "/v1/{name=shelves/*}" };
  47. }
  48. // Merges two shelves by adding all books from the shelf named
  49. // `other_shelf_name` to shelf `name`, and deletes
  50. // `other_shelf_name`. Returns the updated shelf.
  51. // The book ids of the moved books may not be the same as the original books.
  52. //
  53. // Returns NOT_FOUND if either shelf does not exist.
  54. // This call is a no-op if the specified shelves are the same.
  55. rpc MergeShelves(MergeShelvesRequest) returns (Shelf) {
  56. option (google.api.http) = { post: "/v1/{name=shelves/*}:merge" body: "*" };
  57. }
  58. // Creates a book, and returns the new Book.
  59. rpc CreateBook(CreateBookRequest) returns (Book) {
  60. option (google.api.http) = { post: "/v1/{name=shelves/*}/books" body: "book" };
  61. }
  62. // Gets a book. Returns NOT_FOUND if the book does not exist.
  63. rpc GetBook(GetBookRequest) returns (Book) {
  64. option (google.api.http) = { get: "/v1/{name=shelves/*/books/*}" };
  65. }
  66. // Lists books in a shelf. The order is unspecified but deterministic. Newly
  67. // created books will not necessarily be added to the end of this list.
  68. // Returns NOT_FOUND if the shelf does not exist.
  69. rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) {
  70. option (google.api.http) = { get: "/v1/{name=shelves/*}/books" };
  71. }
  72. // Deletes a book. Returns NOT_FOUND if the book does not exist.
  73. rpc DeleteBook(DeleteBookRequest) returns (google.protobuf.Empty) {
  74. option (google.api.http) = { delete: "/v1/{name=shelves/*/books/*}" };
  75. }
  76. // Updates a book. Returns INVALID_ARGUMENT if the name of the book
  77. // is non-empty and does equal the previous name.
  78. rpc UpdateBook(UpdateBookRequest) returns (Book) {
  79. option (google.api.http) = { put: "/v1/{name=shelves/*/books/*}" body: "book" };
  80. }
  81. // Moves a book to another shelf, and returns the new book. The book
  82. // id of the new book may not be the same as the original book.
  83. rpc MoveBook(MoveBookRequest) returns (Book) {
  84. option (google.api.http) = { post: "/v1/{name=shelves/*/books/*}:move" body: "*" };
  85. }
  86. }
  87. // A single book in the library.
  88. message Book {
  89. // The resource name of the book.
  90. // Book names have the form `shelves/{shelf_id}/books/{book_id}`.
  91. // The name is ignored when creating a book.
  92. string name = 1;
  93. // The name of the book author.
  94. string author = 2;
  95. // The title of the book.
  96. string title = 3;
  97. // Value indicating whether the book has been read.
  98. bool read = 4;
  99. }
  100. // A Shelf contains a collection of books with a theme.
  101. message Shelf {
  102. // The resource name of the shelf.
  103. // Shelf names have the form `shelves/{shelf_id}`.
  104. // The name is ignored when creating a shelf.
  105. string name = 1;
  106. // The theme of the shelf
  107. string theme = 2;
  108. }
  109. // Request message for LibraryService.CreateShelf.
  110. message CreateShelfRequest {
  111. // The shelf to create.
  112. Shelf shelf = 1;
  113. }
  114. // Request message for LibraryService.GetShelf.
  115. message GetShelfRequest {
  116. // The name of the shelf to retrieve.
  117. string name = 1;
  118. }
  119. // Request message for LibraryService.ListShelves.
  120. message ListShelvesRequest {
  121. // Requested page size. Server may return fewer shelves than requested.
  122. // If unspecified, server will pick an appropriate default.
  123. int32 page_size = 1;
  124. // A token identifying a page of results the server should return.
  125. // Typically, this is the value of
  126. // [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token]
  127. // returned from the previous call to `ListShelves` method.
  128. string page_token = 2;
  129. }
  130. // Response message for LibraryService.ListShelves.
  131. message ListShelvesResponse {
  132. // The list of shelves.
  133. repeated Shelf shelves = 1;
  134. // A token to retrieve next page of results.
  135. // Pass this value in the
  136. // [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token]
  137. // field in the subsequent call to `ListShelves` method to retrieve the next
  138. // page of results.
  139. string next_page_token = 2;
  140. }
  141. // Request message for LibraryService.DeleteShelf.
  142. message DeleteShelfRequest {
  143. // The name of the shelf to delete.
  144. string name = 1;
  145. }
  146. // Describes the shelf being removed (other_shelf_name) and updated
  147. // (name) in this merge.
  148. message MergeShelvesRequest {
  149. // The name of the shelf we're adding books to.
  150. string name = 1;
  151. // The name of the shelf we're removing books from and deleting.
  152. string other_shelf_name = 2;
  153. }
  154. // Request message for LibraryService.CreateBook.
  155. message CreateBookRequest {
  156. // The name of the shelf in which the book is created.
  157. string name = 1;
  158. // The book to create.
  159. Book book = 2;
  160. }
  161. // Request message for LibraryService.GetBook.
  162. message GetBookRequest {
  163. // The name of the book to retrieve.
  164. string name = 1;
  165. }
  166. // Request message for LibraryService.ListBooks.
  167. message ListBooksRequest {
  168. // The name of the shelf whose books we'd like to list.
  169. string name = 1;
  170. // Requested page size. Server may return fewer books than requested.
  171. // If unspecified, server will pick an appropriate default.
  172. int32 page_size = 2;
  173. // A token identifying a page of results the server should return.
  174. // Typically, this is the value of
  175. // [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token].
  176. // returned from the previous call to `ListBooks` method.
  177. string page_token = 3;
  178. }
  179. // Response message for LibraryService.ListBooks.
  180. message ListBooksResponse {
  181. // The list of books.
  182. repeated Book books = 1;
  183. // A token to retrieve next page of results.
  184. // Pass this value in the
  185. // [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token]
  186. // field in the subsequent call to `ListBooks` method to retrieve the next
  187. // page of results.
  188. string next_page_token = 2;
  189. }
  190. // Request message for LibraryService.UpdateBook.
  191. message UpdateBookRequest {
  192. // The name of the book to update.
  193. string name = 1;
  194. // The book to update with. The name must match or be empty.
  195. Book book = 2;
  196. }
  197. // Request message for LibraryService.DeleteBook.
  198. message DeleteBookRequest {
  199. // The name of the book to delete.
  200. string name = 1;
  201. }
  202. // Describes what book to move (name) and what shelf we're moving it
  203. // to (other_shelf_name).
  204. message MoveBookRequest {
  205. // The name of the book to move.
  206. string name = 1;
  207. // The name of the destination shelf.
  208. string other_shelf_name = 2;
  209. }