use std::rc::Rc;
use pib_service_api_types::{
Associated, Pagination, Search,
body::{
Body, UpdateBody,
by_id_or_alias::{
location::{self, Location, NewLocation, UpdateLocation},
meeting::{
self, EditableMeeting, Meeting, UpdateMeeting,
by_id::agenda_item::{
self, AgendaItem, UpdateAgendaItem,
by_id::consultation::{self, Consultation, UpdateConsultation},
},
},
membership::{self, Membership, UpdateMembership},
organization::{self, NewOrganization, Organization},
paper::{self, NewPaper, Paper, UpdatePaper},
paper_location::PaperLocation,
permission::{self, NewPermission, Permission},
person::{self, NewPerson, Person},
},
},
me::profile::{Profile, UpdateProfile},
user::User,
};
use pib_service_core_types::{
AgendaItemId, BodyId, BodyIdOrAlias, BodyPermissionId, DataItem, DataPage, LocationId,
MeetingId, MembershipId, OrganizationId, PaperId, PaperLocationId, PersonId, UserId,
};
use crate::Storage;
#[derive(Clone)]
pub struct StorageHandle {
storage: Rc<dyn Storage>,
}
impl StorageHandle {
pub fn new<S: Storage + 'static>(storage: S) -> Self {
Self {
storage: Rc::new(storage),
}
}
}
#[async_trait::async_trait(?Send)]
impl Storage for StorageHandle {
fn is_authenticated(&self) -> bool {
self.storage.is_authenticated()
}
async fn get_me_profile(&self) -> anyhow::Result<Profile> {
self.storage.get_me_profile().await
}
async fn update_me_profile(&self, update_profile: UpdateProfile) -> anyhow::Result<Profile> {
self.storage.update_me_profile(update_profile).await
}
async fn get_body(
&self,
body_id_or_alias: BodyIdOrAlias,
associated: Associated,
) -> anyhow::Result<DataItem<(), BodyId, Body>> {
self.storage.get_body(body_id_or_alias, associated).await
}
async fn get_bodies(
&self,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<(), BodyId, Body>> {
self.storage
.get_bodies(pagination, search, associated)
.await
}
async fn create_body(&self, new_body: Body) -> anyhow::Result<DataItem<(), BodyId, Body>> {
self.storage.create_body(new_body).await
}
async fn update_body(
&self,
body_id_or_alias: BodyIdOrAlias,
update_body: UpdateBody,
) -> anyhow::Result<DataItem<(), BodyId, Body>> {
self.storage
.update_body(body_id_or_alias, update_body)
.await
}
async fn get_user(
&self,
user_id: UserId,
associated: Associated,
) -> anyhow::Result<DataItem<(), UserId, User>> {
self.storage.get_user(user_id, associated).await
}
async fn get_users(
&self,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<(), UserId, User>> {
self.storage.get_users(pagination, search, associated).await
}
async fn get_meeting(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
associated: Associated,
) -> anyhow::Result<DataItem<meeting::ParentId, MeetingId, Meeting>> {
self.storage
.get_meeting(body_id_or_alias, meeting_id, associated)
.await
}
async fn get_meetings(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<meeting::ParentId, MeetingId, Meeting>> {
self.storage
.get_meetings(body_id_or_alias, pagination, search, associated)
.await
}
async fn create_meeting(
&self,
body_id_or_alias: BodyIdOrAlias,
new_meeting: EditableMeeting,
) -> anyhow::Result<DataItem<meeting::ParentId, MeetingId, Meeting>> {
self.storage
.create_meeting(body_id_or_alias, new_meeting)
.await
}
async fn update_meeting(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
update_meeting: UpdateMeeting,
) -> anyhow::Result<DataItem<meeting::ParentId, MeetingId, Meeting>> {
self.storage
.update_meeting(body_id_or_alias, meeting_id, update_meeting)
.await
}
async fn get_agenda_item(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
agenda_item_id: AgendaItemId,
associated: Associated,
) -> anyhow::Result<DataItem<agenda_item::ParentId, AgendaItemId, AgendaItem>> {
self.storage
.get_agenda_item(body_id_or_alias, meeting_id, agenda_item_id, associated)
.await
}
async fn get_agenda_items(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<agenda_item::ParentId, AgendaItemId, AgendaItem>> {
self.storage
.get_agenda_items(body_id_or_alias, meeting_id, pagination, search, associated)
.await
}
async fn create_agenda_item(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
new_agenda_item: AgendaItem,
) -> anyhow::Result<DataItem<agenda_item::ParentId, AgendaItemId, AgendaItem>> {
self.storage
.create_agenda_item(body_id_or_alias, meeting_id, new_agenda_item)
.await
}
async fn update_agenda_item(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
agenda_item_id: AgendaItemId,
update_agenda_item: UpdateAgendaItem,
) -> anyhow::Result<DataItem<agenda_item::ParentId, AgendaItemId, AgendaItem>> {
self.storage
.update_agenda_item(
body_id_or_alias,
meeting_id,
agenda_item_id,
update_agenda_item,
)
.await
}
async fn get_consultation(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
agenda_item_id: AgendaItemId,
associated: Associated,
) -> anyhow::Result<DataItem<consultation::ParentId, AgendaItemId, Consultation>> {
self.storage
.get_consultation(body_id_or_alias, meeting_id, agenda_item_id, associated)
.await
}
async fn place_consultation(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
agenda_item_id: AgendaItemId,
new_consultation: Consultation,
) -> anyhow::Result<DataItem<consultation::ParentId, AgendaItemId, Consultation>> {
self.storage
.place_consultation(
body_id_or_alias,
meeting_id,
agenda_item_id,
new_consultation,
)
.await
}
async fn update_consultation(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
agenda_item_id: AgendaItemId,
update_consultation: UpdateConsultation,
) -> anyhow::Result<DataItem<consultation::ParentId, AgendaItemId, Consultation>> {
self.storage
.update_consultation(
body_id_or_alias,
meeting_id,
agenda_item_id,
update_consultation,
)
.await
}
async fn get_organization(
&self,
body_id_or_alias: BodyIdOrAlias,
organization_id: OrganizationId,
associated: Associated,
) -> anyhow::Result<DataItem<organization::ParentId, OrganizationId, Organization>> {
self.storage
.get_organization(body_id_or_alias, organization_id, associated)
.await
}
async fn get_organizations(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<organization::ParentId, OrganizationId, Organization>> {
self.storage
.get_organizations(body_id_or_alias, pagination, search, associated)
.await
}
async fn create_organization(
&self,
body_id_or_alias: BodyIdOrAlias,
new_organization: NewOrganization,
) -> anyhow::Result<DataItem<organization::ParentId, OrganizationId, Organization>> {
self.storage
.create_organization(body_id_or_alias, new_organization)
.await
}
async fn get_organization_memberships(
&self,
body_id_or_alias: BodyIdOrAlias,
organization_id: OrganizationId,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<organization::by_id::membership::ParentId, MembershipId, Membership>>
{
self.storage
.get_organization_memberships(
body_id_or_alias,
organization_id,
pagination,
search,
associated,
)
.await
}
async fn create_organization_membership(
&self,
body_id_or_alias: BodyIdOrAlias,
organization_id: OrganizationId,
new_membership: organization::by_id::membership::NewMembership,
) -> anyhow::Result<DataItem<organization::by_id::membership::ParentId, MembershipId, Membership>>
{
self.storage
.create_organization_membership(body_id_or_alias, organization_id, new_membership)
.await
}
async fn get_person(
&self,
body_id_or_alias: BodyIdOrAlias,
person_id: PersonId,
associated: Associated,
) -> anyhow::Result<DataItem<person::ParentId, PersonId, Person>> {
self.storage
.get_person(body_id_or_alias, person_id, associated)
.await
}
async fn get_persons(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<person::ParentId, PersonId, Person>> {
self.storage
.get_persons(body_id_or_alias, pagination, search, associated)
.await
}
async fn create_person(
&self,
body_id_or_alias: BodyIdOrAlias,
new_person: NewPerson,
) -> anyhow::Result<DataItem<person::ParentId, PersonId, Person>> {
self.storage
.create_person(body_id_or_alias, new_person)
.await
}
async fn get_person_memberships(
&self,
body_id_or_alias: BodyIdOrAlias,
person_id: PersonId,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<person::by_id::membership::ParentId, MembershipId, Membership>>
{
self.storage
.get_person_memberships(body_id_or_alias, person_id, pagination, search, associated)
.await
}
async fn create_person_membership(
&self,
body_id_or_alias: BodyIdOrAlias,
person_id: PersonId,
new_membership: person::by_id::membership::NewMembership,
) -> anyhow::Result<DataItem<person::by_id::membership::ParentId, MembershipId, Membership>>
{
self.storage
.create_person_membership(body_id_or_alias, person_id, new_membership)
.await
}
async fn get_membership(
&self,
body_id_or_alias: BodyIdOrAlias,
membership_id: MembershipId,
associated: Associated,
) -> anyhow::Result<DataItem<membership::ParentId, MembershipId, Membership>> {
self.storage
.get_membership(body_id_or_alias, membership_id, associated)
.await
}
async fn get_memberships(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<membership::ParentId, MembershipId, Membership>> {
self.storage
.get_memberships(body_id_or_alias, pagination, search, associated)
.await
}
async fn create_membership(
&self,
body_id_or_alias: BodyIdOrAlias,
new_membership: Membership,
) -> anyhow::Result<DataItem<membership::ParentId, MembershipId, Membership>> {
self.storage
.create_membership(body_id_or_alias, new_membership)
.await
}
async fn update_membership(
&self,
body_id_or_alias: BodyIdOrAlias,
membership_id: MembershipId,
update_membership: UpdateMembership,
) -> anyhow::Result<DataItem<membership::ParentId, MembershipId, Membership>> {
self.storage
.update_membership(body_id_or_alias, membership_id, update_membership)
.await
}
async fn get_location(
&self,
body_id_or_alias: BodyIdOrAlias,
location_id: LocationId,
associated: Associated,
) -> anyhow::Result<DataItem<location::ParentId, LocationId, Location>> {
self.storage
.get_location(body_id_or_alias, location_id, associated)
.await
}
async fn get_locations(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<location::ParentId, LocationId, Location>> {
self.storage
.get_locations(body_id_or_alias, pagination, search, associated)
.await
}
async fn create_location(
&self,
body_id_or_alias: BodyIdOrAlias,
new_location: NewLocation,
) -> anyhow::Result<DataItem<location::ParentId, LocationId, Location>> {
self.storage
.create_location(body_id_or_alias, new_location)
.await
}
async fn update_location(
&self,
body_id_or_alias: BodyIdOrAlias,
location_id: LocationId,
update_location: UpdateLocation,
) -> anyhow::Result<DataItem<location::ParentId, LocationId, Location>> {
self.storage
.update_location(body_id_or_alias, location_id, update_location)
.await
}
async fn location_get_papers(
&self,
body_id_or_alias: BodyIdOrAlias,
location_id: LocationId,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<location::by_id::paper::ParentId, PaperLocationId, PaperLocation>>
{
self.storage
.location_get_papers(
body_id_or_alias,
location_id,
pagination,
search,
associated,
)
.await
}
async fn location_get_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
location_id: LocationId,
paper_location_id: PaperLocationId,
associated: Associated,
) -> anyhow::Result<DataItem<location::by_id::paper::ParentId, PaperLocationId, PaperLocation>>
{
self.storage
.location_get_paper(body_id_or_alias, location_id, paper_location_id, associated)
.await
}
async fn location_add_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
location_id: LocationId,
paper_id: PaperId,
) -> anyhow::Result<DataItem<location::by_id::paper::ParentId, PaperLocationId, PaperLocation>>
{
self.storage
.location_add_paper(body_id_or_alias, location_id, paper_id)
.await
}
async fn location_remove_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
location_id: LocationId,
paper_location_id: PaperLocationId,
) -> anyhow::Result<()> {
self.storage
.location_remove_paper(body_id_or_alias, location_id, paper_location_id)
.await
}
async fn get_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
paper_id: PaperId,
associated: Associated,
) -> anyhow::Result<DataItem<paper::ParentId, PaperId, Paper>> {
self.storage
.get_paper(body_id_or_alias, paper_id, associated)
.await
}
async fn get_papers(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<paper::ParentId, PaperId, Paper>> {
self.storage
.get_papers(body_id_or_alias, pagination, search, associated)
.await
}
async fn create_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
new_paper: NewPaper,
) -> anyhow::Result<DataItem<paper::ParentId, PaperId, Paper>> {
self.storage.create_paper(body_id_or_alias, new_paper).await
}
async fn update_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
paper_id: PaperId,
update_paper: UpdatePaper,
) -> anyhow::Result<DataItem<paper::ParentId, PaperId, Paper>> {
self.storage
.update_paper(body_id_or_alias, paper_id, update_paper)
.await
}
async fn paper_get_locations(
&self,
body_id_or_alias: BodyIdOrAlias,
paper_id: PaperId,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<paper::by_id::location::ParentId, PaperLocationId, PaperLocation>>
{
self.storage
.paper_get_locations(body_id_or_alias, paper_id, pagination, search, associated)
.await
}
async fn paper_get_location(
&self,
body_id_or_alias: BodyIdOrAlias,
paper_id: PaperId,
paper_location_id: PaperLocationId,
associated: Associated,
) -> anyhow::Result<DataItem<paper::by_id::location::ParentId, PaperLocationId, PaperLocation>>
{
self.storage
.paper_get_location(body_id_or_alias, paper_id, paper_location_id, associated)
.await
}
async fn paper_add_location(
&self,
body_id_or_alias: BodyIdOrAlias,
paper_id: PaperId,
location_id: LocationId,
) -> anyhow::Result<DataItem<paper::by_id::location::ParentId, PaperLocationId, PaperLocation>>
{
self.storage
.paper_add_location(body_id_or_alias, paper_id, location_id)
.await
}
async fn paper_remove_location(
&self,
body_id_or_alias: BodyIdOrAlias,
paper_id: PaperId,
paper_location_id: PaperLocationId,
) -> anyhow::Result<()> {
self.storage
.paper_remove_location(body_id_or_alias, paper_id, paper_location_id)
.await
}
async fn get_body_permission(
&self,
body_id_or_alias: BodyIdOrAlias,
permission_id: BodyPermissionId,
associated: Associated,
) -> anyhow::Result<DataItem<permission::ParentId, BodyPermissionId, Permission>> {
self.storage
.get_body_permission(body_id_or_alias, permission_id, associated)
.await
}
async fn get_body_permissions(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<permission::ParentId, BodyPermissionId, Permission>> {
self.storage
.get_body_permissions(body_id_or_alias, pagination, search, associated)
.await
}
async fn create_body_permission(
&self,
body_id_or_alias: BodyIdOrAlias,
new_permission: NewPermission,
) -> anyhow::Result<DataItem<permission::ParentId, BodyPermissionId, Permission>> {
self.storage
.create_body_permission(body_id_or_alias, new_permission)
.await
}
}