use pib_client::{IsAuthenticated, PibClient};
use pib_service_api_types::{
Associated, ItemResponse, PagedResponse, 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,
};
#[async_trait::async_trait(?Send)]
pub trait Storage {
fn is_authenticated(&self) -> bool;
async fn get_me_profile(&self) -> anyhow::Result<Profile>;
async fn update_me_profile(&self, update_profile: UpdateProfile) -> anyhow::Result<Profile>;
async fn get_body(
&self,
body_id_or_alias: BodyIdOrAlias,
associated: Associated,
) -> anyhow::Result<DataItem<(), BodyId, Body>>;
async fn get_bodies(
&self,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<(), BodyId, Body>>;
async fn create_body(&self, new_body: Body) -> anyhow::Result<DataItem<(), BodyId, Body>>;
async fn update_body(
&self,
body_id_or_alias: BodyIdOrAlias,
update_body: UpdateBody,
) -> anyhow::Result<DataItem<(), BodyId, Body>>;
async fn get_user(
&self,
user_id: UserId,
associated: Associated,
) -> anyhow::Result<DataItem<(), UserId, User>>;
async fn get_users(
&self,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<(), UserId, User>>;
async fn get_meeting(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
associated: Associated,
) -> anyhow::Result<DataItem<meeting::ParentId, MeetingId, Meeting>>;
async fn get_meetings(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<meeting::ParentId, MeetingId, Meeting>>;
async fn create_meeting(
&self,
body_id_or_alias: BodyIdOrAlias,
new_meeting: EditableMeeting,
) -> anyhow::Result<DataItem<meeting::ParentId, MeetingId, Meeting>>;
async fn update_meeting(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
update_meeting: UpdateMeeting,
) -> anyhow::Result<DataItem<meeting::ParentId, MeetingId, Meeting>>;
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>>;
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>>;
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>>;
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>>;
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>>;
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>>;
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>>;
async fn get_organization(
&self,
body_id_or_alias: BodyIdOrAlias,
organization_id: OrganizationId,
associated: Associated,
) -> anyhow::Result<DataItem<organization::ParentId, OrganizationId, Organization>>;
async fn get_organizations(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<organization::ParentId, OrganizationId, Organization>>;
async fn create_organization(
&self,
body_id_or_alias: BodyIdOrAlias,
new_organization: NewOrganization,
) -> anyhow::Result<DataItem<organization::ParentId, OrganizationId, Organization>>;
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>>;
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>>;
async fn get_person(
&self,
body_id_or_alias: BodyIdOrAlias,
person_id: PersonId,
associated: Associated,
) -> anyhow::Result<DataItem<person::ParentId, PersonId, Person>>;
async fn get_persons(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<person::ParentId, PersonId, Person>>;
async fn create_person(
&self,
body_id_or_alias: BodyIdOrAlias,
new_person: NewPerson,
) -> anyhow::Result<DataItem<person::ParentId, PersonId, Person>>;
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>>;
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>>;
async fn get_membership(
&self,
body_id_or_alias: BodyIdOrAlias,
membership_id: MembershipId,
associated: Associated,
) -> anyhow::Result<DataItem<membership::ParentId, MembershipId, Membership>>;
async fn get_memberships(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<membership::ParentId, MembershipId, Membership>>;
async fn create_membership(
&self,
body_id_or_alias: BodyIdOrAlias,
new_membership: Membership,
) -> anyhow::Result<DataItem<membership::ParentId, MembershipId, Membership>>;
async fn update_membership(
&self,
body_id_or_alias: BodyIdOrAlias,
membership_id: MembershipId,
update_membership: UpdateMembership,
) -> anyhow::Result<DataItem<membership::ParentId, MembershipId, Membership>>;
async fn get_location(
&self,
body_id_or_alias: BodyIdOrAlias,
location_id: LocationId,
associated: Associated,
) -> anyhow::Result<DataItem<location::ParentId, LocationId, Location>>;
async fn get_locations(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<location::ParentId, LocationId, Location>>;
async fn create_location(
&self,
body_id_or_alias: BodyIdOrAlias,
new_location: NewLocation,
) -> anyhow::Result<DataItem<location::ParentId, LocationId, Location>>;
async fn update_location(
&self,
body_id_or_alias: BodyIdOrAlias,
location_id: LocationId,
update_location: UpdateLocation,
) -> anyhow::Result<DataItem<location::ParentId, LocationId, Location>>;
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>>;
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>>;
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>>;
async fn location_remove_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
location_id: LocationId,
paper_location_id: PaperLocationId,
) -> anyhow::Result<()>;
async fn get_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
paper_id: PaperId,
associated: Associated,
) -> anyhow::Result<DataItem<paper::ParentId, PaperId, Paper>>;
async fn get_papers(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<paper::ParentId, PaperId, Paper>>;
async fn create_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
new_paper: NewPaper,
) -> anyhow::Result<DataItem<paper::ParentId, PaperId, Paper>>;
async fn update_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
paper_id: PaperId,
update_paper: UpdatePaper,
) -> anyhow::Result<DataItem<paper::ParentId, PaperId, Paper>>;
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>>;
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>>;
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>>;
async fn paper_remove_location(
&self,
body_id_or_alias: BodyIdOrAlias,
paper_id: PaperId,
paper_location_id: PaperLocationId,
) -> anyhow::Result<()>;
async fn get_body_permission(
&self,
body_id_or_alias: BodyIdOrAlias,
permission_id: BodyPermissionId,
associated: Associated,
) -> anyhow::Result<DataItem<permission::ParentId, BodyPermissionId, Permission>>;
async fn get_body_permissions(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<permission::ParentId, BodyPermissionId, Permission>>;
async fn create_body_permission(
&self,
body_id_or_alias: BodyIdOrAlias,
new_permission: NewPermission,
) -> anyhow::Result<DataItem<permission::ParentId, BodyPermissionId, Permission>>;
}
#[async_trait::async_trait(?Send)]
impl<C, E> Storage for C
where
C: PibClient<ClientError = E>,
E: std::error::Error + Sync + Send + 'static,
{
fn is_authenticated(&self) -> bool {
<Self as IsAuthenticated>::is_authenticated(self)
}
async fn get_me_profile(&self) -> anyhow::Result<Profile> {
let profile = <Self as PibClient>::me_profile_get(self).await?;
Ok(profile)
}
async fn update_me_profile(&self, update_profile: UpdateProfile) -> anyhow::Result<Profile> {
let profile = <Self as PibClient>::me_profile_patch(self, update_profile).await?;
Ok(profile)
}
async fn get_body(
&self,
body_id_or_alias: BodyIdOrAlias,
associated: Associated,
) -> anyhow::Result<DataItem<(), BodyId, Body>> {
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_get(self, body_id_or_alias, associated)
.await?;
Ok(value)
}
async fn get_bodies(
&self,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<(), BodyId, Body>> {
let bodies = <Self as PibClient>::body_get(self, pagination, search, associated).await?;
Ok(bodies.value)
}
async fn create_body(&self, new_body: Body) -> anyhow::Result<DataItem<(), BodyId, Body>> {
let body = <Self as PibClient>::body_post(self, new_body).await?;
Ok(body.value)
}
async fn update_body(
&self,
body_id_or_alias: BodyIdOrAlias,
update_body: UpdateBody,
) -> anyhow::Result<DataItem<(), BodyId, Body>> {
let body =
<Self as PibClient>::body_by_id_or_alias_patch(self, body_id_or_alias, update_body)
.await?;
Ok(body.value)
}
async fn get_user(
&self,
user_id: UserId,
associated: Associated,
) -> anyhow::Result<DataItem<(), UserId, User>> {
let user = <Self as PibClient>::user_by_id_get(self, user_id, associated).await?;
Ok(user.value)
}
async fn get_users(
&self,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<(), UserId, User>> {
let users = <Self as PibClient>::user_get(self, pagination, search, associated).await?;
Ok(users.value)
}
async fn get_meeting(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
associated: Associated,
) -> anyhow::Result<DataItem<meeting::ParentId, MeetingId, Meeting>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let meeting = <Self as PibClient>::body_by_id_or_alias_meeting_by_id_get(
self, body_id, meeting_id, associated,
)
.await?;
Ok(meeting.value)
}
async fn get_meetings(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<meeting::ParentId, MeetingId, Meeting>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let meetings = <Self as PibClient>::body_by_id_or_alias_meeting_get(
self, body_id, pagination, search, associated,
)
.await?;
Ok(meetings.value)
}
async fn create_meeting(
&self,
body_id_or_alias: BodyIdOrAlias,
new_meeting: EditableMeeting,
) -> anyhow::Result<DataItem<meeting::ParentId, MeetingId, Meeting>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let meeting =
<Self as PibClient>::body_by_id_or_alias_meeting_post(self, body_id, new_meeting)
.await?;
Ok(meeting.value)
}
async fn update_meeting(
&self,
body_id_or_alias: BodyIdOrAlias,
meeting_id: MeetingId,
update_meeting: UpdateMeeting,
) -> anyhow::Result<DataItem<meeting::ParentId, MeetingId, Meeting>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let meeting = <Self as PibClient>::body_by_id_or_alias_meeting_by_id_patch(
self,
body_id,
meeting_id,
update_meeting,
)
.await?;
Ok(meeting.value)
}
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>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let agenda_item =
<Self as PibClient>::body_by_id_or_alias_meeting_by_id_agenda_item_by_id_get(
self,
body_id,
meeting_id,
agenda_item_id,
associated,
)
.await?;
Ok(agenda_item.value)
}
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>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let agenda_items = <Self as PibClient>::body_by_id_or_alias_meeting_by_id_agenda_item_get(
self, body_id, meeting_id, pagination, search, associated,
)
.await?;
Ok(agenda_items.value)
}
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>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let agenda_item = <Self as PibClient>::body_by_id_or_alias_meeting_by_id_agenda_item_post(
self,
body_id,
meeting_id,
new_agenda_item,
)
.await?;
Ok(agenda_item.value)
}
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>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let agenda_item =
<Self as PibClient>::body_by_id_or_alias_meeting_by_id_agenda_item_by_id_patch(
self,
body_id,
meeting_id,
agenda_item_id,
update_agenda_item,
)
.await?;
Ok(agenda_item.value)
}
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>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let consultation =
<Self as PibClient>::body_by_id_or_alias_meeting_by_id_agenda_item_by_id_consultation_get(
self,
body_id,
meeting_id,
agenda_item_id,
associated
)
.await?;
Ok(consultation.value)
}
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>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse{ value, associated :_}=
<Self as PibClient>::body_by_id_or_alias_meeting_by_id_agenda_item_by_id_consultation_put(
self,
body_id,
meeting_id,
agenda_item_id,
new_consultation,
)
.await?;
Ok(value)
}
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>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse{ value, associated :_}=
<Self as PibClient>::body_by_id_or_alias_meeting_by_id_agenda_item_by_id_consultation_patch(
self,
body_id,
meeting_id,
agenda_item_id,
update_consultation,
)
.await?;
Ok(value)
}
async fn get_organization(
&self,
body_id_or_alias: BodyIdOrAlias,
organization_id: OrganizationId,
associated: Associated,
) -> anyhow::Result<DataItem<organization::ParentId, OrganizationId, Organization>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_organization_by_id_get(
self,
body_id,
organization_id,
associated,
)
.await?;
Ok(value)
}
async fn get_organizations(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<organization::ParentId, OrganizationId, Organization>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let PagedResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_organization_get(
self, body_id, pagination, search, associated,
)
.await?;
Ok(value)
}
async fn create_organization(
&self,
body_id_or_alias: BodyIdOrAlias,
new_organization: NewOrganization,
) -> anyhow::Result<DataItem<organization::ParentId, OrganizationId, Organization>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_organization_post(
self,
body_id,
new_organization,
)
.await?;
Ok(value)
}
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>>
{
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let PagedResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_organization_by_id_membership_get(
self,
body_id,
organization_id,
pagination,
search,
associated,
)
.await?;
Ok(value)
}
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>>
{
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_organization_by_id_membership_post(
self,
body_id,
organization_id,
new_membership,
)
.await?;
Ok(value)
}
async fn get_person(
&self,
body_id_or_alias: BodyIdOrAlias,
person_id: PersonId,
associated: Associated,
) -> anyhow::Result<DataItem<person::ParentId, PersonId, Person>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_person_by_id_get(
self, body_id, person_id, associated,
)
.await?;
Ok(value)
}
async fn get_persons(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<person::ParentId, PersonId, Person>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let PagedResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_person_get(
self, body_id, pagination, search, associated,
)
.await?;
Ok(value)
}
async fn create_person(
&self,
body_id_or_alias: BodyIdOrAlias,
new_person: NewPerson,
) -> anyhow::Result<DataItem<person::ParentId, PersonId, Person>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_person_post(self, body_id, new_person).await?;
Ok(value)
}
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>>
{
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let PagedResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_person_by_id_membership_get(
self, body_id, person_id, pagination, search, associated,
)
.await?;
Ok(value)
}
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>>
{
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_person_by_id_membership_post(
self,
body_id,
person_id,
new_membership,
)
.await?;
Ok(value)
}
async fn get_membership(
&self,
body_id_or_alias: BodyIdOrAlias,
membership_id: MembershipId,
associated: Associated,
) -> anyhow::Result<DataItem<membership::ParentId, MembershipId, Membership>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_membership_by_id_get(
self,
body_id,
membership_id,
associated,
)
.await?;
Ok(value)
}
async fn get_memberships(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<membership::ParentId, MembershipId, Membership>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let PagedResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_membership_get(
self, body_id, pagination, search, associated,
)
.await?;
Ok(value)
}
async fn create_membership(
&self,
body_id_or_alias: BodyIdOrAlias,
new_membership: Membership,
) -> anyhow::Result<DataItem<membership::ParentId, MembershipId, Membership>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_membership_post(self, body_id, new_membership)
.await?;
Ok(value)
}
async fn update_membership(
&self,
body_id_or_alias: BodyIdOrAlias,
membership_id: MembershipId,
update_membership: UpdateMembership,
) -> anyhow::Result<DataItem<membership::ParentId, MembershipId, Membership>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_membership_by_id_patch(
self,
body_id,
membership_id,
update_membership,
)
.await?;
Ok(value)
}
async fn get_location(
&self,
body_id_or_alias: BodyIdOrAlias,
location_id: LocationId,
associated: Associated,
) -> anyhow::Result<DataItem<location::ParentId, LocationId, Location>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_location_by_id_get(
self,
body_id,
location_id,
associated,
)
.await?;
Ok(value)
}
async fn get_locations(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<location::ParentId, LocationId, Location>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let PagedResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_location_get(
self, body_id, pagination, search, associated,
)
.await?;
Ok(value)
}
async fn create_location(
&self,
body_id_or_alias: BodyIdOrAlias,
new_location: NewLocation,
) -> anyhow::Result<DataItem<location::ParentId, LocationId, Location>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_location_post(self, body_id, new_location)
.await?;
Ok(value)
}
async fn update_location(
&self,
body_id_or_alias: BodyIdOrAlias,
location_id: LocationId,
update_location: UpdateLocation,
) -> anyhow::Result<DataItem<location::ParentId, LocationId, Location>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_location_by_id_patch(
self,
body_id,
location_id,
update_location,
)
.await?;
Ok(value)
}
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>>
{
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let PagedResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_location_by_id_paper_get(
self,
body_id,
location_id,
pagination,
search,
associated,
)
.await?;
Ok(value)
}
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>>
{
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_location_by_id_paper_by_id_get(
self,
body_id,
location_id,
paper_location_id,
associated,
)
.await?;
Ok(value)
}
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>>
{
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let new_paper = location::by_id::paper::NewPaperLocation { paper_id };
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_location_by_id_paper_post(
self,
body_id,
location_id,
new_paper,
)
.await?;
Ok(value)
}
async fn location_remove_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
location_id: LocationId,
paper_location_id: PaperLocationId,
) -> anyhow::Result<()> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
<Self as PibClient>::body_by_id_or_alias_location_by_id_paper_by_id_delete(
self,
body_id,
location_id,
paper_location_id,
)
.await?;
Ok(())
}
async fn get_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
paper_id: PaperId,
associated: Associated,
) -> anyhow::Result<DataItem<paper::ParentId, PaperId, Paper>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_paper_by_id_get(
self, body_id, paper_id, associated,
)
.await?;
Ok(value)
}
async fn get_papers(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<paper::ParentId, PaperId, Paper>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let PagedResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_paper_get(
self, body_id, pagination, search, associated,
)
.await?;
Ok(value)
}
async fn create_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
new_paper: NewPaper,
) -> anyhow::Result<DataItem<paper::ParentId, PaperId, Paper>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_paper_post(self, body_id, new_paper).await?;
Ok(value)
}
async fn update_paper(
&self,
body_id_or_alias: BodyIdOrAlias,
paper_id: PaperId,
update_paper: UpdatePaper,
) -> anyhow::Result<DataItem<paper::ParentId, PaperId, Paper>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_paper_by_id_patch(
self,
body_id,
paper_id,
update_paper,
)
.await?;
Ok(value)
}
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>>
{
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let PagedResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_paper_by_id_location_get(
self, body_id, paper_id, pagination, search, associated,
)
.await?;
Ok(value)
}
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>>
{
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_paper_by_id_location_by_id_get(
self,
body_id,
paper_id,
paper_location_id,
associated,
)
.await?;
Ok(value)
}
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>>
{
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let new_location = paper::by_id::location::NewPaperLocation { location_id };
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_paper_by_id_location_post(
self,
body_id,
paper_id,
new_location,
)
.await?;
Ok(value)
}
async fn paper_remove_location(
&self,
body_id_or_alias: BodyIdOrAlias,
paper_id: PaperId,
paper_location_id: PaperLocationId,
) -> anyhow::Result<()> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
<Self as PibClient>::body_by_id_or_alias_paper_by_id_location_by_id_delete(
self,
body_id,
paper_id,
paper_location_id,
)
.await?;
Ok(())
}
async fn get_body_permission(
&self,
body_id_or_alias: BodyIdOrAlias,
permission_id: BodyPermissionId,
associated: Associated,
) -> anyhow::Result<DataItem<permission::ParentId, BodyPermissionId, Permission>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_permission_by_id_get(
self,
body_id,
permission_id,
associated,
)
.await?;
Ok(value)
}
async fn get_body_permissions(
&self,
body_id_or_alias: BodyIdOrAlias,
pagination: Pagination,
search: Search,
associated: Associated,
) -> anyhow::Result<DataPage<permission::ParentId, BodyPermissionId, Permission>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let PagedResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_permission_get(
self, body_id, pagination, search, associated,
)
.await?;
Ok(value)
}
async fn create_body_permission(
&self,
body_id_or_alias: BodyIdOrAlias,
new_permission: NewPermission,
) -> anyhow::Result<DataItem<permission::ParentId, BodyPermissionId, Permission>> {
let body_id = self
.get_body(body_id_or_alias, Associated::default())
.await?
.id;
let ItemResponse {
value,
associated: _,
} = <Self as PibClient>::body_by_id_or_alias_permission_post(self, body_id, new_permission)
.await?;
Ok(value)
}
}