pub struct GrpcServer {}
Expand description

parcelmodule including mock file Implementation of gRPC endpoints

Implementations§

source§

impl GrpcServer

source

pub fn get_name(&self) -> String

Get name string for service

Trait Implementations§

source§

impl Clone for GrpcServer

source§

fn clone(&self) -> GrpcServer

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for GrpcServer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for GrpcServer

source§

fn default() -> GrpcServer

Returns the “default value” for a type. Read more
source§

impl GrpcSimpleService for GrpcServer

§

type ResourceObject = ResourceObject<Data>

The type expected for the Self::ResourceObject<Self::Data> type. Must implement; ObjectType<Self::Data>, PsqlType, PsqlSearch, SimpleResource<Self::Data>, PsqlObjectType<Self::Data>, From<[Id]>, From<[Self::Data]>, From<[Self::UpdateObject]>, Clone, Sync, Send
§

type Data = Data

The type expected for Data structs. Must implement; GrpcDataObjectType, TryFrom<[Row]>
§

type Object = Object

The type expected for Object structs. Must implement; From<[Self::ResourceObject]>
§

type UpdateObject = UpdateObject

The type expected for UpdateObject structs. Must implement; Send
§

type List = List

The type expected for List structs. Must implement TryFrom<[Vec<Row>]>
§

type Response = Response

The type expected for Response structs. Must implement; From<[GenericResourceResult<Self::ResourceObject, Self::Data>]>
source§

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

Returns a tonic gRCP Response containing an object of provided type Self::Object. Self::Object will contain the record data found for the provided Id. Read more
Returns a tonic gRCP Response containing an object of provided type Self::Object. Self::Object(TryFrom<Vec<Row>>) will contain all records found in the database using the the provided AdvancedSearchFilter. Read more
source§

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

Returns a tonic gRCP Response containing an object of provided type Self::Object. Self::Response(From<GenericResourceResult<Self::ResourceObject, Self::Data>>) will contain the inserted record after saving the provided data Self::Data. Read more
source§

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

Returns a tonic gRCP Response containing an object of provided type Self::Object. Self::Response(From<GenericResourceResult<Self::ResourceObject, Self::Data>>) will contain the updated record after saving the provided data Self::Data. Read more
source§

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

Takes an Id to set the matching database record as deleted in the database. Read more
source§

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

Returns ready:true when service is available
source§

impl RpcService for GrpcServer

source§

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 gRCP Response containing an parcel Object

Errors

Returns tonic::Status with tonic::Code::NotFound if no record is returned from the database

Examples
use svc_storage::resources::Id;
use svc_storage::resources::parcel::{Object, GrpcServer, RpcService};

async fn example() -> Result<Object, tonic::Status> {
    let server = GrpcServer::default();

    let id = "53acfe06-dd9b-42e8-8cb4-12a2fb2fa693".to_string();
    let result = match server.get_by_id(tonic::Request::new(Id { id })).await
    {
        Ok(res) => res.into_inner(),
        Err(e) => {
            return Err(e);
        },
    };
    log::debug!("{:?}", result);

    Ok(result)
}
source§

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,

Takes an AdvancedSearchFilter object to search the database with the provided values.

This method supports paged results.

Examples
use svc_storage::resources::{AdvancedSearchFilter, FilterOption, PredicateOperator, Id};
use svc_storage::resources::parcel::{Object, List, GrpcServer, RpcService};

async fn example() -> Result<(), tonic::Status> {
    let server = GrpcServer::default();

    // Empty filter, but return paged results
    let mut filters = vec![];
    let advanced_filter = AdvancedSearchFilter {
        filters,
        page_number: 1,
        results_per_page: 10,
        order_by: vec![],
    };

    let result = match server.search(tonic::Request::new(advanced_filter)).await
    {
        Ok(res) => res.into_inner().list,
        Err(e) => {
            return Err(e);
        },
    };
    log::debug!("{:?}", result);

    Ok(())
}
source§

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,

Takes a parcel Data object to create a new parcel with the provided data.

A new Uuid will be generated by the database and returned as id as part of the returned Object.

Examples
use svc_storage::resources::Id;
use svc_storage::resources::parcel::{Data, Response, GrpcServer, RpcService};
use svc_storage::resources::parcel::mock;

const CAL_WORKDAYS_7AM_6PM: &str = "\
DTSTART:20221019T180000Z;DURATION:PT14H
RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR
DTSTART:20221021T000000Z;DURATION:PT24H
RRULE:FREQ=WEEKLY;BYDAY=SA,SU";

async fn example() -> Result<(), tonic::Status> {
    let server = GrpcServer::default();

    let result = match server.insert(tonic::Request::new(mock::get_data_obj())).await
    {
        Ok(res) => res.into_inner(),
        Err(e) => {
            return Err(e);
        },
    };
    log::debug!("{:?}", result);

    Ok(())
}
source§

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,

Takes a parcel UpdateObject to update the resource with new data in the database

A field mask can be provided to restrict updates to specific fields. Returns the updated Response on success.

Examples
use svc_storage::resources::Id;
use svc_storage::resources::parcel::{UpdateObject, Response, GrpcServer, RpcService};
use svc_storage::resources::parcel::mock;

async fn example() -> Result<(), tonic::Status> {
    let server = GrpcServer::default();

    let result = match server.update(tonic::Request::new(UpdateObject {
        id: "54acfe06-dd9b-42e8-8cb4-12a2fb2fa693".to_string(),
        data: Some(mock::get_data_obj()),
        mask: None
    })).await
    {
        Ok(res) => res.into_inner(),
        Err(e) => {
            return Err(e);
        },
    };
    log::debug!("{:?}", result);

    Ok(())
}
source§

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 parcel record as deleted in the database.

Examples
use svc_storage::resources::Id;
use svc_storage::resources::parcel::{GrpcServer, RpcService};

async fn example() -> Result<(), tonic::Status> {
    let server = GrpcServer::default();

    let id = "53acfe06-dd9b-42e8-8cb4-12a2fb2fa693".to_string();
    let result = match server.delete(tonic::Request::new(Id { id })).await
    {
        Ok(res) => res.into_inner(),
        Err(e) => {
            return Err(e);
        },
    };
    log::debug!("{:?}", result);

    Ok(())
}
source§

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,

Returns ready:true when service is available

source§

impl Copy for GrpcServer

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneAny for T
where T: Any + Clone + Send + Sync,

§

fn clone_any(&self) -> Box<dyn CloneAny>

§

fn clone_any_send(&self) -> Box<dyn CloneAny + Send>

§

fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync>

§

fn clone_any_send_sync(&self) -> Box<dyn CloneAny + Send + Sync>

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> DebugAny for T
where T: Any + Debug,

§

impl<T> UnsafeAny for T
where T: Any,