ocpi 0.3.5

Unofficial, in progress, OCPI implementation
Documentation
//! 9. Sessions module
//!
//! Module Identifier: sessions
//! Data owner: CPO
//! Type: Functional Module
//!
//! The Session object describes one charging session.
//! The Session object is owned by the CPO back-end system,
//! and can be GET from the CPO system, or pushed by the CPO to another system.
//!
//!
//! # 9. Sessions module
//!
//! * Module Identifier: sessions
//! * Data owner: CPO
//! * Type: Functional Module
//!
//! The Session object describes one charging session.
//! The Session object is owned by the CPO back-end system,
//! and can be GET from the CPO system,
//! or pushed by the CPO to another system.
//!

use crate::{
    types::{self, Paginated},
    CommandsHandler, Context, Cpo, Error, Result, SessionsStore,
};
use async_trait::async_trait;

#[async_trait]
pub trait SessionsModule {
    async fn sessions_get(
        &self,
        ctx: Context,
        date_from: types::DateTime,
        date_to: Option<types::DateTime>,
        offset: Option<usize>,
        limit: Option<usize>,
    ) -> Result<Paginated<types::Session>>;

    async fn sessions_put(
        &self,
        ctx: Context,
        session_id: types::CiString<36>,
        charging_preferences: types::ChargingPreferences,
    ) -> Result<()>;
}

#[async_trait]
impl<DB, CH> SessionsModule for Cpo<DB, CH>
where
    DB: SessionsStore,
    CH: CommandsHandler,
{
    async fn sessions_get(
        &self,
        ctx: Context,
        date_from: types::DateTime,
        date_to: Option<types::DateTime>,
        offset: Option<usize>,
        limit: Option<usize>,
    ) -> Result<Paginated<types::Session>> {
        let party = self
            .db
            .get_authorized(ctx.credentials_token.clone())
            .await?
            .party()?;

        self.db
            .get_sessions(&party, date_from, date_to, offset, limit)
            .await
    }

    async fn sessions_put(
        &self,
        _ctx: Context,
        _session_id: types::CiString<36>,
        _charging_preferences: types::ChargingPreferences,
    ) -> Result<()> {
        Err(Error::server_generic("sessions PUT is not implemented"))
    }
}