Trait svc_storage::grpc::server::vertipad::rpc_service_server::RpcService
source · pub trait RpcService: Send + Sync + 'static {
// Required methods
fn get_by_id<'life0, 'async_trait>(
&'life0 self,
request: Request<Id>
) -> Pin<Box<dyn Future<Output = Result<Response<Object>, Status>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn insert<'life0, 'async_trait>(
&'life0 self,
request: Request<Data>
) -> Pin<Box<dyn Future<Output = Result<Response<Response>, Status>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn update<'life0, 'async_trait>(
&'life0 self,
request: Request<UpdateObject>
) -> Pin<Box<dyn Future<Output = Result<Response<Response>, Status>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn delete<'life0, 'async_trait>(
&'life0 self,
request: Request<Id>
) -> Pin<Box<dyn Future<Output = Result<Response<()>, Status>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn search<'life0, 'async_trait>(
&'life0 self,
request: Request<AdvancedSearchFilter>
) -> Pin<Box<dyn Future<Output = Result<Response<List>, Status>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn is_ready<'life0, 'async_trait>(
&'life0 self,
request: Request<ReadyRequest>
) -> Pin<Box<dyn Future<Output = Result<Response<ReadyResponse>, Status>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
Generated trait containing gRPC methods that should be implemented for use with RpcServiceServer.
Required Methods§
sourcefn get_by_id<'life0, 'async_trait>(
&'life0 self,
request: Request<Id>
) -> Pin<Box<dyn Future<Output = Result<Response<Object>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn get_by_id<'life0, 'async_trait>(
&'life0 self,
request: Request<Id>
) -> Pin<Box<dyn Future<Output = Result<Response<Object>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns a [tonic::Response
] containing an vertipad Object
Takes an id
to find the right record to return.
Errors
Returns [tonic::Status
] with Code::NotFound
if no record is returned from the database
Examples
use svc_storage_client_grpc::{Id, VertipadClient, simple_service::Client};
async fn example () -> Result<(), Box<dyn std::error::Error>> {
let mut vertipad_client = VertipadClient::connect("http://localhost:50051").await?;
let id = "53acfe06-dd9b-42e8-8cb4-12a2fb2fa693".to_owned();
match vertipad_client
.get_by_id(tonic::Request::new(Id { id }))
.await
{
Ok(res) => {
println!("RESPONSE Vertipad By ID={:?}", res);
Ok(())
},
Err(e) => Err(Box::new(e))
}
}
sourcefn insert<'life0, 'async_trait>(
&'life0 self,
request: Request<Data>
) -> Pin<Box<dyn Future<Output = Result<Response<Response>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn insert<'life0, 'async_trait>(
&'life0 self,
request: Request<Data>
) -> Pin<Box<dyn Future<Output = Result<Response<Response>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns a [tonic::Response
] containing a vertipad Response
object
of the inserted record after saving the provided vertipad Data
The given data will be validated before insert.
A new UUID will be generated by the database and returned as id
as part of the returned vertipad Response
.
Any errors found during validation will be added to the ValidationResult
.
Errors
Returns Status
with Code::Internal
if the [tonic::Request
] doesn’t contain any data.
Returns Status
with Code::Internal
if any error is returned from a db call.
Examples
use svc_storage_client_grpc::{Id, VertipadClient, simple_service::Client};
use svc_storage_client_grpc::vertipad::Data;
const CAL_WORKDAYS_8AM_6PM: &str = "\
DTSTART:20221020T180000Z;DURATION:PT14H
RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR
DTSTART:20221022T000000Z;DURATION:PT24H
RRULE:FREQ=WEEKLY;BYDAY=SA,SU";
async fn example () -> Result<(), Box<dyn std::error::Error>> {
let mut vertipad_client = VertipadClient::connect("http://localhost:50051").await?;
let vertiport_id = "45a06a13-4b39-4820-aaa6-5781f3b70575".to_owned();
println!("Starting insert vertipad");
match vertipad_client
.insert(tonic::Request::new(Data {
vertiport_id: vertiport_id.clone(),
name: format!("First vertipad for {}", vertiport_id.clone()),
geo_location: Some(geo_types::Point::new(37.7746, -122.4194).into()),
enabled: true,
occupied: false,
schedule: Some(CAL_WORKDAYS_8AM_6PM.to_owned()),
created_at: None,
updated_at: None
}))
.await
{
Ok(res) => {
println!("RESPONSE Vertipad Insert={:?}", res);
Ok(())
},
Err(e) => Err(Box::new(e))
}
}
sourcefn update<'life0, 'async_trait>(
&'life0 self,
request: Request<UpdateObject>
) -> Pin<Box<dyn Future<Output = Result<Response<Response>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn update<'life0, 'async_trait>(
&'life0 self,
request: Request<UpdateObject>
) -> Pin<Box<dyn Future<Output = Result<Response<Response>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns a [tonic::Response
] containing a vertipad Response
object
of the updated record after saving the provided vertipad Data
The given data will be validated before insert.
Any errors found during validation will be added to the ValidationResult
.
A field [prost_types::FieldMask
] can be provided to restrict updates to specific fields.
Errors
Returns Status
with Code::Cancelled
if the Request
doesn’t contain any data.
Returns Status
with Code::Internal
if any error is returned from a db call.
Returns Status
with Code::Internal
if the provided Id can not be converted to a [uuid::Uuid
].
Returns Status
with Code::Internal
if the resulting Vec<tokio_postgres::Row> data could not be converted into List
.
Examples
use svc_storage_client_grpc::{FieldMask, Id, VertipadClient, simple_service::Client};
use svc_storage_client_grpc::vertipad::{Data, UpdateObject};
async fn example () -> Result<(), Box<dyn std::error::Error>> {
let mut vertipad_client = VertipadClient::connect("http://localhost:50051").await?;
let id = "53acfe06-dd9b-42e8-8cb4-12a2fb2fa693".to_owned();
let response = match vertipad_client
.get_by_id(tonic::Request::new(Id { id: id.clone() }))
.await
{
Ok(res) => {
println!("RESPONSE Vertipad By ID={:?}", res);
res
},
Err(e) => {
return Err(Box::new(e));
}
};
let vertipad = response.into_inner().data.unwrap();
match vertipad_client.update(tonic::Request::new(UpdateObject {
id,
data: Some(Data {
occupied: true,
..vertipad
}),
mask: Some(FieldMask {
paths: vec!["data.occupied".to_owned()],
}),
})).await
{
Ok(res) => {
println!("RESPONSE Vertipad Update={:?}", res);
Ok(())
},
Err(e) => Err(Box::new(e))
}
}
sourcefn delete<'life0, 'async_trait>(
&'life0 self,
request: Request<Id>
) -> Pin<Box<dyn Future<Output = Result<Response<()>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn delete<'life0, 'async_trait>(
&'life0 self,
request: Request<Id>
) -> Pin<Box<dyn Future<Output = Result<Response<()>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Takes an Id
to set the matching vertipad record as deleted in the database“
Errors
Returns Status
with Code::NotFound
if no record is returned from the database.
Returns Status
with Code::Internal
if any error is returned from a db call.
Examples
use svc_storage_client_grpc::{Id, VertipadClient, simple_service::Client};
async fn example () -> Result<(), Box<dyn std::error::Error>> {
let mut vertipad_client = VertipadClient::connect("http://localhost:50051").await?;
let id = "53acfe06-dd9b-42e8-8cb4-12a2fb2fa693".to_owned();
match vertipad_client.delete(tonic::Request::new(Id{id})).await
{
Ok(res) => {
println!("RESPONSE Vertipad Delete={:?}", res);
Ok(())
},
Err(e) => Err(Box::new(e))
}
}
sourcefn search<'life0, 'async_trait>(
&'life0 self,
request: Request<AdvancedSearchFilter>
) -> Pin<Box<dyn Future<Output = Result<Response<List>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn search<'life0, 'async_trait>(
&'life0 self,
request: Request<AdvancedSearchFilter>
) -> Pin<Box<dyn Future<Output = Result<Response<List>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Search vertipads using an advanced filter
This method supports paged results.
Errors
Returns Status
with Code::Internal
if any error is returned from the db search result.
Returns Status
with Code::Internal
if the resulting Vec<tokio_postgres::Row> data could not be converted into List
.
Examples
use svc_storage_client_grpc::{AdvancedSearchFilter, VertipadClient, simple_service::Client};
async fn example () -> Result<(), Box<dyn std::error::Error>> {
let mut vertipad_client = VertipadClient::connect("http://localhost:50051").await?;
let filter = AdvancedSearchFilter::search_between(
"latitude".to_owned(),
(-122.2).to_string(),
(-122.5).to_string(),
)
.and_between("longitude".to_owned(), 37.6.to_string(), 37.8.to_string())
.and_equals("occupied".to_owned(), false.to_string())
.page_number(1)
.results_per_page(50);
match vertipad_client
.search(tonic::Request::new(filter))
.await
{
Ok(res) => {
println!("RESPONSE Vertipad Search={:?}", res);
Ok(())
},
Err(e) => Err(Box::new(e))
}
}
sourcefn is_ready<'life0, 'async_trait>(
&'life0 self,
request: Request<ReadyRequest>
) -> Pin<Box<dyn Future<Output = Result<Response<ReadyResponse>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn is_ready<'life0, 'async_trait>(
&'life0 self,
request: Request<ReadyRequest>
) -> Pin<Box<dyn Future<Output = Result<Response<ReadyResponse>, Status>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Simple ready check to allow callers to validate the client connection status.