net-component 0.1.0

This crate defines core traits and types for the components in net-timescale. The component in the context is a separate microservice which handles each own type of requests from net-gateway - rest server. Because of the amount of such services we decided to create a trait which defines the skeleton of each one to reduce the code duplicate.
Documentation
use std::sync::Arc;
use std::error::Error;
use std::collections::HashMap;

use sqlx::Pool;
use sqlx::Postgres;

use net_core_api::api::envelope::envelope::Envelope;

use super::network_service_handler::NetworkServiceHandler;

pub struct NetworkServiceHandlerManager {
    handlers: HashMap<String, Box<dyn NetworkServiceHandler>>,
}

impl NetworkServiceHandlerManager {
    pub fn new(
        handlers: HashMap<String, Box<dyn NetworkServiceHandler>>
    ) -> Self {
        Self {
            handlers
        }
    }

    pub async fn handle(
        &self,
        connection_pool: Arc<Pool<Postgres>>,
        enveloped_request: Envelope
    ) -> Result<Envelope, Box<dyn Error + Send + Sync>> {
        let handler = self.handlers.get(enveloped_request.get_envelope_type());
        if handler.is_none() {
            return Err("Error: Tere is no such request available".into());
        }
        let handler = handler.unwrap();

        handler.handle(connection_pool, enveloped_request).await
    }
}