-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary_server
More file actions
48 lines (37 loc) · 1.06 KB
/
library_server
File metadata and controls
48 lines (37 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import ballerina/grpc;
import ballerina/log;
import library.proto;
// Assuming library.proto defines the service
// consist of a stub//
const string ROOT_DESCRIPTOR = "library.BookService";
map<string> descriptorMap = {
"library.BookService": ROOT_DESCRIPTOR
};
@grpc:ServiceDescriptor {
descriptor: ROOT_DESCRIPTOR,
descMap descriptorMap
}
service "BookService" on new grpc:Listener(9090) {
remote function AddBook(Book request) returns BookId|error {
if (bookExists(request.isbn)) {
return error("Book already exists!");
}
var bookId = addBookToLibrary(request);
if (bookId is error) {
return bookId;
}
BookId response = {id: bookId};
return response;
}
}
// Utility function implementations
function bookExists(string isbn) returns boolean {
// Check if book exists
return false;
}
function addBookToLibrary(Book book) returns int|error {
// Logic to add book
return 5;
}
// Similarly implement other utils like updateBook,
// removeBook, getAvailability etc.