-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9e4492
commit 4c0a6b5
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...rc/test/resources/declarations/service-listener/assert/service_listener_declaration_4.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import ballerina/grpc; | ||
|
||
configurable int port = 9090; | ||
|
||
type Book record { | ||
string id; | ||
string title; | ||
string author; | ||
float price; | ||
}; | ||
|
||
Book[] books = [ | ||
{id: "1", title: "Book One", author: "Author One", price: 29.99}, | ||
{id: "2", title: "Book Two", author: "Author Two", price: 19.99}, | ||
{id: "3", title: "Book Three", author: "Author Three", price: 39.99} | ||
]; | ||
|
||
service "Books" on new grpc:Listener(port) { | ||
remote function addBook(Book book) returns Book|error { | ||
books.push(book); | ||
return book; | ||
} | ||
|
||
remote function getBook(string id) returns Book|error { | ||
Book[] book = books.filter(b => b.id == id); | ||
if (book.length() == 0) { | ||
return error grpc:NotFoundError(string `Cannot find the album for ID ${id}`); | ||
} | ||
return book[0]; | ||
} | ||
|
||
remote function listBooks() returns stream<Book, error?>|error { | ||
return books.toStream(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...rc/test/resources/declarations/service-listener/source/service_listener_declaration_4.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import ballerina/grpc; | ||
|
||
|
||
configurable int port = 9090; | ||
|
||
type Book record { | ||
string id; | ||
string title; | ||
string author; | ||
float price; | ||
}; | ||
|
||
Book[] books = [ | ||
{id: "1", title: "Book One", author: "Author One", price: 29.99}, | ||
{id: "2", title: "Book Two", author: "Author Two", price: 19.99}, | ||
{id: "3", title: "Book Three", author: "Author Three", price: 39.99} | ||
]; | ||
|
||
service "Books" on new grpc:Listener(port) { | ||
remote function addBook(Book book) returns Book | error { | ||
books.push(book); | ||
return book; | ||
} | ||
remote function getBook(string id) returns Book | error { | ||
Book[] book = books.filter(b => b.id == id); | ||
if (book.length() == 0) { | ||
return error grpc:NotFoundError(string `Cannot find the album for ID ${id}`); | ||
} | ||
return book[0]; | ||
} | ||
|
||
|
||
|
||
remote function listBooks( ) returns stream<Book, error?> | error { | ||
return books.toStream(); | ||
} | ||
} |