xref: /aosp_15_r20/external/googleapis/google/example/library/v1/library.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2019 Google LLC.
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//
15
16syntax = "proto3";
17
18package google.example.library.v1;
19
20import "google/api/annotations.proto";
21import "google/api/client.proto";
22import "google/api/field_behavior.proto";
23import "google/api/resource.proto";
24import "google/protobuf/empty.proto";
25import "google/protobuf/field_mask.proto";
26
27option go_package = "google.golang.org/genproto/googleapis/example/library/v1;library";
28option java_multiple_files = true;
29option java_outer_classname = "LibraryProto";
30option java_package = "com.google.example.library.v1";
31option php_namespace = "Google\\Cloud\\Example\\Library\\V1";
32
33// This API represents a simple digital library. It lets you manage Shelf
34// resources and Book resources in the library. It defines the following
35// resource model:
36//
37// - The API has a collection of [Shelf][google.example.library.v1.Shelf]
38//   resources, named `shelves/*`
39//
40// - Each Shelf has a collection of [Book][google.example.library.v1.Book]
41//   resources, named `shelves/*/books/*`
42service LibraryService {
43  option (google.api.default_host) = "library-example.googleapis.com";
44
45  // Creates a shelf, and returns the new Shelf.
46  rpc CreateShelf(CreateShelfRequest) returns (Shelf) {
47    option (google.api.http) = {
48      post: "/v1/shelves"
49      body: "shelf"
50    };
51    option (google.api.method_signature) = "shelf";
52  }
53
54  // Gets a shelf. Returns NOT_FOUND if the shelf does not exist.
55  rpc GetShelf(GetShelfRequest) returns (Shelf) {
56    option (google.api.http) = {
57      get: "/v1/{name=shelves/*}"
58    };
59    option (google.api.method_signature) = "name";
60  }
61
62  // Lists shelves. The order is unspecified but deterministic. Newly created
63  // shelves will not necessarily be added to the end of this list.
64  rpc ListShelves(ListShelvesRequest) returns (ListShelvesResponse) {
65    option (google.api.http) = {
66      get: "/v1/shelves"
67    };
68  }
69
70  // Deletes a shelf. Returns NOT_FOUND if the shelf does not exist.
71  rpc DeleteShelf(DeleteShelfRequest) returns (google.protobuf.Empty) {
72    option (google.api.http) = {
73      delete: "/v1/{name=shelves/*}"
74    };
75    option (google.api.method_signature) = "name";
76  }
77
78  // Merges two shelves by adding all books from the shelf named
79  // `other_shelf_name` to shelf `name`, and deletes
80  // `other_shelf_name`. Returns the updated shelf.
81  // The book ids of the moved books may not be the same as the original books.
82  //
83  // Returns NOT_FOUND if either shelf does not exist.
84  // This call is a no-op if the specified shelves are the same.
85  rpc MergeShelves(MergeShelvesRequest) returns (Shelf) {
86    option (google.api.http) = {
87      post: "/v1/{name=shelves/*}:merge"
88      body: "*"
89    };
90    option (google.api.method_signature) = "name,other_shelf";
91  }
92
93  // Creates a book, and returns the new Book.
94  rpc CreateBook(CreateBookRequest) returns (Book) {
95    option (google.api.http) = {
96      post: "/v1/{parent=shelves/*}/books"
97      body: "book"
98    };
99    option (google.api.method_signature) = "parent,book";
100  }
101
102  // Gets a book. Returns NOT_FOUND if the book does not exist.
103  rpc GetBook(GetBookRequest) returns (Book) {
104    option (google.api.http) = {
105      get: "/v1/{name=shelves/*/books/*}"
106    };
107    option (google.api.method_signature) = "name";
108  }
109
110  // Lists books in a shelf. The order is unspecified but deterministic. Newly
111  // created books will not necessarily be added to the end of this list.
112  // Returns NOT_FOUND if the shelf does not exist.
113  rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) {
114    option (google.api.http) = {
115      get: "/v1/{parent=shelves/*}/books"
116    };
117    option (google.api.method_signature) = "parent";
118  }
119
120  // Deletes a book. Returns NOT_FOUND if the book does not exist.
121  rpc DeleteBook(DeleteBookRequest) returns (google.protobuf.Empty) {
122    option (google.api.http) = {
123      delete: "/v1/{name=shelves/*/books/*}"
124    };
125    option (google.api.method_signature) = "name";
126  }
127
128  // Updates a book. Returns INVALID_ARGUMENT if the name of the book
129  // is non-empty and does not equal the existing name.
130  rpc UpdateBook(UpdateBookRequest) returns (Book) {
131    option (google.api.http) = {
132      patch: "/v1/{book.name=shelves/*/books/*}"
133      body: "book"
134    };
135    option (google.api.method_signature) = "book,update_mask";
136  }
137
138  // Moves a book to another shelf, and returns the new book. The book
139  // id of the new book may not be the same as the original book.
140  rpc MoveBook(MoveBookRequest) returns (Book) {
141    option (google.api.http) = {
142      post: "/v1/{name=shelves/*/books/*}:move"
143      body: "*"
144    };
145    option (google.api.method_signature) = "name,other_shelf_name";
146  }
147}
148
149// A single book in the library.
150message Book {
151  option (google.api.resource) = {
152    type: "library-example.googleapis.com/Book",
153    pattern: "shelves/{shelf}/books/{book}"
154  };
155
156  // The resource name of the book.
157  // Book names have the form `shelves/{shelf_id}/books/{book_id}`.
158  // The name is ignored when creating a book.
159  string name = 1;
160
161  // The name of the book author.
162  string author = 2;
163
164  // The title of the book.
165  string title = 3;
166
167  // Value indicating whether the book has been read.
168  bool read = 4;
169}
170
171// A Shelf contains a collection of books with a theme.
172message Shelf {
173  option (google.api.resource) = {
174    type: "library-example.googleapis.com/Shelf",
175    pattern: "shelves/{shelf_id}"
176  };
177
178  // The resource name of the shelf.
179  // Shelf names have the form `shelves/{shelf_id}`.
180  // The name is ignored when creating a shelf.
181  string name = 1;
182
183  // The theme of the shelf
184  string theme = 2;
185}
186
187// Request message for LibraryService.CreateShelf.
188message CreateShelfRequest {
189  // The shelf to create.
190  Shelf shelf = 1 [(google.api.field_behavior) = REQUIRED];
191}
192
193// Request message for LibraryService.GetShelf.
194message GetShelfRequest {
195  // The name of the shelf to retrieve.
196  string name = 1 [
197    (google.api.field_behavior) = REQUIRED,
198    (google.api.resource_reference).type =
199        "library-example.googleapis.com/Shelf"
200  ];
201}
202
203// Request message for LibraryService.ListShelves.
204message ListShelvesRequest {
205  // Requested page size. Server may return fewer shelves than requested.
206  // If unspecified, server will pick an appropriate default.
207  int32 page_size = 1;
208
209  // A token identifying a page of results the server should return.
210  // Typically, this is the value of
211  // [ListShelvesResponse.next_page_token][google.example.library.v1.ListShelvesResponse.next_page_token]
212  // returned from the previous call to `ListShelves` method.
213  string page_token = 2;
214}
215
216// Response message for LibraryService.ListShelves.
217message ListShelvesResponse {
218  // The list of shelves.
219  repeated Shelf shelves = 1;
220
221  // A token to retrieve next page of results.
222  // Pass this value in the
223  // [ListShelvesRequest.page_token][google.example.library.v1.ListShelvesRequest.page_token]
224  // field in the subsequent call to `ListShelves` method to retrieve the next
225  // page of results.
226  string next_page_token = 2;
227}
228
229// Request message for LibraryService.DeleteShelf.
230message DeleteShelfRequest {
231  // The name of the shelf to delete.
232  string name = 1 [
233    (google.api.field_behavior) = REQUIRED,
234    (google.api.resource_reference).type =
235        "library-example.googleapis.com/Shelf"
236  ];
237}
238
239// Describes the shelf being removed (other_shelf_name) and updated
240// (name) in this merge.
241message MergeShelvesRequest {
242  // The name of the shelf we're adding books to.
243  string name = 1 [
244    (google.api.field_behavior) = REQUIRED,
245    (google.api.resource_reference).type =
246        "library-example.googleapis.com/Shelf"
247  ];
248
249  // The name of the shelf we're removing books from and deleting.
250  string other_shelf = 2 [
251    (google.api.field_behavior) = REQUIRED,
252    (google.api.resource_reference).type =
253        "library-example.googleapis.com/Shelf"
254  ];
255}
256
257// Request message for LibraryService.CreateBook.
258message CreateBookRequest {
259  // The name of the shelf in which the book is created.
260  string parent = 1 [
261    (google.api.field_behavior) = REQUIRED,
262    (google.api.resource_reference).type =
263        "library-example.googleapis.com/Shelf"
264  ];
265
266  // The book to create.
267  Book book = 2 [(google.api.field_behavior) = REQUIRED];
268}
269
270// Request message for LibraryService.GetBook.
271message GetBookRequest {
272  // The name of the book to retrieve.
273  string name = 1 [
274    (google.api.field_behavior) = REQUIRED,
275    (google.api.resource_reference).type = "library-example.googleapis.com/Book"
276  ];
277}
278
279// Request message for LibraryService.ListBooks.
280message ListBooksRequest {
281  // The name of the shelf whose books we'd like to list.
282  string parent = 1 [
283    (google.api.field_behavior) = REQUIRED,
284    (google.api.resource_reference).type =
285        "library-example.googleapis.com/Shelf"
286  ];
287
288  // Requested page size. Server may return fewer books than requested.
289  // If unspecified, server will pick an appropriate default.
290  int32 page_size = 2;
291
292  // A token identifying a page of results the server should return.
293  // Typically, this is the value of
294  // [ListBooksResponse.next_page_token][google.example.library.v1.ListBooksResponse.next_page_token].
295  // returned from the previous call to `ListBooks` method.
296  string page_token = 3;
297}
298
299// Response message for LibraryService.ListBooks.
300message ListBooksResponse {
301  // The list of books.
302  repeated Book books = 1;
303
304  // A token to retrieve next page of results.
305  // Pass this value in the
306  // [ListBooksRequest.page_token][google.example.library.v1.ListBooksRequest.page_token]
307  // field in the subsequent call to `ListBooks` method to retrieve the next
308  // page of results.
309  string next_page_token = 2;
310}
311
312// Request message for LibraryService.UpdateBook.
313message UpdateBookRequest {
314  // The name of the book to update.
315  Book book = 1 [(google.api.field_behavior) = REQUIRED];
316
317  // Required. Mask of fields to update.
318  google.protobuf.FieldMask update_mask = 2
319      [(google.api.field_behavior) = REQUIRED];
320}
321
322// Request message for LibraryService.DeleteBook.
323message DeleteBookRequest {
324  // The name of the book to delete.
325  string name = 1 [
326    (google.api.field_behavior) = REQUIRED,
327    (google.api.resource_reference).type = "library-example.googleapis.com/Book"
328  ];
329}
330
331// Describes what book to move (name) and what shelf we're moving it
332// to (other_shelf_name).
333message MoveBookRequest {
334  // The name of the book to move.
335  string name = 1 [
336    (google.api.field_behavior) = REQUIRED,
337    (google.api.resource_reference).type = "library-example.googleapis.com/Book"
338  ];
339
340  // The name of the destination shelf.
341  string other_shelf_name = 2 [
342    (google.api.field_behavior) = REQUIRED,
343    (google.api.resource_reference).type =
344        "library-example.googleapis.com/Shelf"
345  ];
346}
347