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"))
}
}