-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary_service.bal
More file actions
79 lines (71 loc) · 2.44 KB
/
library_service.bal
File metadata and controls
79 lines (71 loc) · 2.44 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import ballerina/grpc;
listener grpc:Listener ep = new (9090);
@grpc:Descriptor {value: INTERFACE_DESC}
isolated service "Library" on ep {
private Database db = new ();
remote function addBook(Book value) returns ISBN|error {
lock{
return self.db.addBook(value.clone());
}
}
remote function updateBook(Book value) returns Message|error {
lock{
return self.db.updateBook(value.clone());
}
}
remote function removeBook(ISBN value) returns ListOfBooks|error {
lock{
return self.db.removeBook(value.clone());
}
}
remote function listAvailableBooks(Empty value) returns ListOfBooks|error {
lock{
return self.db.listAvailableBooks();
}
}
remote function locateBook(ISBN value) returns BookEnquiryResponse|error {
lock{
return self.db.locateBook(value.clone());
}
}
remote function borrowBook(BorrowingInformation value) returns Message|error {
lock{
return self.db.borrowBook(value.clone());
}
}
remote function listBorrowedBooks(Empty value) returns ListOfBooks|error {
lock{
return self.db.listBorrowedBooks();
}
}
remote function returnBook(BorrowingInformation value) returns Message|error {
lock{
return self.db.returnBook(value.clone());
}
}
remote function searchBookByTitle(Message value) returns ListOfBooks|error {
lock{
return self.db.searchBookByTitle(value.message.toString());
}
}
remote function searchBookByAuthor(Message value) returns ListOfBooks|error {
lock{
return self.db.searchBookByAuthor(value.message.toString());
}
}
remote function searchBookByISBN(Message value) returns ListOfBooks|error {
lock{
return self.db.searchBookByISBN(value.message.toString());
}
}
remote function createUsers(stream<User, grpc:Error?> clientStream) returns Message|error {
string response = "";
grpc:Error? forEach = clientStream.forEach(function (User user){
response += "\n" + (self.db.createUser(user));
});
if forEach is grpc:Error {
return error("Internal Server Error");
}
return {message: response};
}
}