pub trait Client<T>
where Self: Sized + Client<T> + ClientConnect<T>, T: Send + Clone,
{ type Data; type Object; type UpdateObject; type List; type Response; // Required methods fn get_by_id<'life0, 'async_trait>( &'life0 self, request: Id ) -> Pin<Box<dyn Future<Output = Result<Response<Self::Object>, Status>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn insert<'life0, 'async_trait>( &'life0 self, request: Self::Data ) -> Pin<Box<dyn Future<Output = Result<Response<Self::Response>, Status>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn update<'life0, 'async_trait>( &'life0 self, request: Self::UpdateObject ) -> Pin<Box<dyn Future<Output = Result<Response<Self::Response>, Status>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn delete<'life0, 'async_trait>( &'life0 self, 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: AdvancedSearchFilter ) -> Pin<Box<dyn Future<Output = Result<Response<Self::List>, Status>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn is_ready<'life0, 'async_trait>( &'life0 self, request: ReadyRequest ) -> Pin<Box<dyn Future<Output = Result<Response<ReadyResponse>, Status>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; }
Expand description

Generic gRPC object traits to provide wrappers for simple Resource functions

Required Associated Types§

source

type Data

The type expected for Data structs.

source

type Object

The type expected for Object structs.

source

type UpdateObject

The type expected for UpdateObject structs.

source

type List

The type expected for List structs.

source

type Response

The type expected for Response structs.

Required Methods§

source

fn get_by_id<'life0, 'async_trait>( &'life0 self, request: Id ) -> Pin<Box<dyn Future<Output = Result<Response<Self::Object>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns a tonic::Response containing the Object

Takes a Id and uses the provided id field to determine which object record to retrieve from the database.

Errors

Returns tonic::Status with tonic::Code::NotFound if the provided id is not found in the database. Returns tonic::Status with tonic::Code::Internal if the provided Id can not be converted to a uuid::Uuid. Returns tonic::Status with tonic::Code::Internal if any error is returned from the db search result. Returns tonic::Status with tonic::Code::Unknown if the server is not ready.

Examples
use lib_common::grpc::get_endpoint_from_env;
use svc_storage_client_grpc::prelude::*;

async fn example () -> Result<(), Box<dyn std::error::Error>> {
    let (host, port) = get_endpoint_from_env("SERVER_HOSTNAME", "SERVER_PORT_GRPC");
    let clients = Clients::new(host, port);
    let client = clients.flight_plan;
    let flight_plan_id = String::from("40ef6e51-c7db-4ce7-a806-a754d6baa641");

    client.get_by_id(Id { id: flight_plan_id }).await?;

    Ok(())
}
source

fn insert<'life0, 'async_trait>( &'life0 self, request: Self::Data ) -> Pin<Box<dyn Future<Output = Result<Response<Self::Response>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns a tonic::Response containing a Response object of the inserted record after saving the provided 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 Response. Any errors found during validation will be added to the ValidationResult.

Errors

Returns tonic::Status with tonic::Code::Internal if any error is returned from the db insert result. Returns tonic::Status with tonic::Code::Internal if the resulting tokio_postgres::Row data could not be converted into Data. Returns tonic::Status with tonic::Code::Unknown if the server is not ready.

Examples
use flight_plan::*;
use lib_common::grpc::get_endpoint_from_env;
use std::time::SystemTime;
use svc_storage_client_grpc::prelude::*;

async fn example () -> Result<(), Box<dyn std::error::Error>> {
    let (host, port) = get_endpoint_from_env("SERVER_HOSTNAME", "SERVER_PORT_GRPC");
    let clients = Clients::new(host, port);
    let client = clients.flight_plan;

    let vehicle_id = "62fb5d13-2cfe-45e2-b89a-16205d15e811".to_owned();
    let pilot_id = "a2093c5e-9bbe-4f0f-97ee-276b43fa3759".to_owned();
    let origin_vertipad_id = "53acfe06-dd9b-42e8-8cb4-12a2fb2fa693".to_owned();
    let target_vertipad_id = "db67da52-2280-4316-8b29-9cf1bff65931".to_owned();
    let data = Data {
        flight_status: FlightStatus::Draft as i32,
        vehicle_id,
        pilot_id,
        path: Some(GeoLineString { points: vec![] }),
        weather_conditions: Some("Cloudy, low wind".to_owned()),
        origin_vertipad_id,
        origin_vertiport_id: None,
        target_vertipad_id,
        target_vertiport_id: None,
        origin_timeslot_start: Some(Timestamp::from(SystemTime::now())),
        origin_timeslot_end: Some(Timestamp::from(SystemTime::now())),
        target_timeslot_start: Some(Timestamp::from(SystemTime::now())),
        target_timeslot_end: Some(Timestamp::from(SystemTime::now())),
        actual_departure_time: None,
        actual_arrival_time: None,
        flight_release_approval: None,
        flight_plan_submitted: Some(Timestamp::from(SystemTime::now())),
        approved_by: None,
        carrier_ack: None,
        flight_priority: FlightPriority::Low as i32,
    };

    client.insert(data).await?;

    Ok(())
}
source

fn update<'life0, 'async_trait>( &'life0 self, request: Self::UpdateObject ) -> Pin<Box<dyn Future<Output = Result<Response<Self::Response>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns a tonic::Response containing a Response object of the updated record after saving the provided UpdateObject

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 tonic::Status with tonic::Code::Cancelled if the Request doesn’t contain any data. Returns tonic::Status with tonic::Code::Internal if any error is returned from a db call. Returns tonic::Status with tonic::Code::Internal if the provided Id can not be converted to a uuid::Uuid. Returns tonic::Status with tonic::Code::Internal if the resulting tokio_postgres::Row data could not be converted into Data. Returns tonic::Status with tonic::Code::Unknown if the server is not ready.

Examples
use lib_common::grpc::get_endpoint_from_env;
use svc_storage_client_grpc::prelude::*;
use flight_plan::*;

async fn example () -> Result<(), Box<dyn std::error::Error>> {
    let (host, port) = get_endpoint_from_env("SERVER_HOSTNAME", "SERVER_PORT_GRPC");
    let clients = Clients::new(host, port);
    let client = clients.flight_plan;

    let id = "53acfe06-dd9b-42e8-8cb4-12a2fb2fa693".to_owned();
    let response = match client.get_by_id(Id { id: id.clone() }).await {
        Ok(res) => {
          println!("RESPONSE Flight Plan By ID={:?}", res);
          res
        },
        Err(e) => {
            return Err(Box::new(e));
        }
    };

    let flight_plan = response.into_inner().data.unwrap();
    client.update(UpdateObject {
        id,
        data: Some(Data {
            flight_status: FlightStatus::InFlight as i32,
            ..flight_plan
        }),
        mask: Some(FieldMask {
            paths: vec!["flight_status".to_owned()],
        }),
    }).await?;

    Ok(())
}
source

fn delete<'life0, 'async_trait>( &'life0 self, request: Id ) -> Pin<Box<dyn Future<Output = Result<Response<()>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Takes an Id object to remove the associated records from the database.

Errors

Returns tonic::Status with tonic::Code::NotFound if no record is found in the database for the provided id field and value combination. Returns tonic::Status with tonic::Code::Internal if any error is returned from a db call. Returns tonic::Status with tonic::Code::Internal if the provided Id can not be converted to a uuid::Uuid. Returns tonic::Status with tonic::Code::Unknown if the server is not ready.

Examples
use lib_common::grpc::get_endpoint_from_env;
use svc_storage_client_grpc::prelude::*;
use flight_plan::*;

async fn example () -> Result<(), Box<dyn std::error::Error>> {
    let (host, port) = get_endpoint_from_env("SERVER_HOSTNAME", "SERVER_PORT_GRPC");
    let clients = Clients::new(host, port);
    let client = clients.flight_plan;

    let flight_plan_id = String::from("40ef6e51-c7db-4ce7-a806-a754d6baa641");
    client.delete(Id { id: flight_plan_id } ).await?;

    Ok(())
}
source

fn search<'life0, 'async_trait>( &'life0 self, request: AdvancedSearchFilter ) -> Pin<Box<dyn Future<Output = Result<Response<Self::List>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Search database records using an advanced filter

This method supports paged results.

Errors

Returns tonic::Status with tonic::Code::Internal if any error is returned from the db search result. Returns tonic::Status with tonic::Code::Internal if the resulting Vec<tokio_postgres::Row> data could not be converted into List. Returns tonic::Status with tonic::Code::Unknown if the server is not ready.

Examples
use lib_common::grpc::get_endpoint_from_env;
use svc_storage_client_grpc::prelude::*;
use flight_plan::*;

async fn example () -> Result<(), Box<dyn std::error::Error>> {
    let (host, port) = get_endpoint_from_env("SERVER_HOSTNAME", "SERVER_PORT_GRPC");
    let clients = Clients::new(host, port);
    let client = clients.flight_plan;

    let pilot_id = "a2093c5e-9bbe-4f0f-97ee-276b43fa3759".to_owned();
    let filter = AdvancedSearchFilter::search_equals("pilot_id".to_owned(), pilot_id)
        .and_is_not_null("origin_timeslot_start".to_owned());

    client.search(filter).await?;

    Ok(())
}
source

fn is_ready<'life0, 'async_trait>( &'life0 self, request: ReadyRequest ) -> Pin<Box<dyn Future<Output = Result<Response<ReadyResponse>, Status>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns a tonic::Response containing a ReadyResponse Takes an ReadyRequest

Errors

Returns tonic::Status with tonic::Code::Unknown if the server is not ready.

Examples
use lib_common::grpc::get_endpoint_from_env;
use svc_storage_client_grpc::prelude::*;

async fn example () -> Result<(), Box<dyn std::error::Error>> {
    let (host, port) = get_endpoint_from_env("SERVER_HOSTNAME", "SERVER_PORT_GRPC");
    let clients = Clients::new(host, port);
    clients.flight_plan.is_ready(ReadyRequest {}).await?;

    Ok(())
}

Object Safety§

This trait is not object safe.

Implementors§