userlib/store/
organization_store.rsuse std::str::FromStr;
use common::remote::services::USER_API;
use common::store::build_exp_link;
use common::store::{get, post, put};
use uuid::Uuid;
use crate::dto::address_request::AddressRequest;
use crate::dto::organization_request::OrganizationRequest;
use crate::dto::organization_response::OrganizationResponse;
use crate::dto::organization_short_response::OrganizationShortResponse;
pub struct OrganizationStore {}
impl OrganizationStore {
pub async fn create(
new_organization: OrganizationRequest,
) -> Result<OrganizationResponse, String> {
post::<_, OrganizationResponse>(
build_exp_link(USER_API, format!("/organization")),
new_organization,
)
.await
}
pub async fn get(org_id: Uuid) -> Result<OrganizationResponse, String> {
get::<OrganizationResponse>(build_exp_link(USER_API, format!("/organization/{org_id}")))
.await
}
pub async fn update(
new_organization: OrganizationRequest,
) -> Result<OrganizationResponse, String> {
put::<_, OrganizationResponse>(
build_exp_link(USER_API, format!("/organization")),
new_organization,
)
.await
}
pub async fn get_child_ids_for_parent_org(parent_id: Uuid) -> Result<Vec<Uuid>, String> {
get::<Vec<Uuid>>(build_exp_link(
USER_API,
format!("/organization/getChildIdsForParentOrg/{parent_id}"),
))
.await
}
pub async fn get_short_parent_org(
parent_id: Uuid,
) -> Result<OrganizationShortResponse, String> {
get::<OrganizationShortResponse>(build_exp_link(
USER_API,
format!("/organization/getShortOrg/{parent_id}"),
))
.await
}
pub async fn get_addresses() -> Result<AddressRequest, String> {
get::<AddressRequest>(build_exp_link(USER_API, format!("/organization/addresses"))).await
}
pub async fn get_addresses_for_org(org_id: Uuid) -> Result<AddressRequest, String> {
get::<AddressRequest>(build_exp_link(
USER_API,
format!("/organization/addressesForOrg/{org_id}"),
))
.await
}
pub async fn set_syllabus(ep_id: Uuid) -> Result<OrganizationResponse, String> {
put::<_, OrganizationResponse>(
build_exp_link(USER_API, format!("/organization/setSyllabus/{ep_id}")),
serde_json::Value::from_str("{}").unwrap(),
)
.await
}
pub async fn set_academic_year(ay_id: Uuid) -> Result<OrganizationResponse, String> {
put::<_, OrganizationResponse>(
build_exp_link(USER_API, format!("/organization/setAcademicYear/{ay_id}")),
serde_json::Value::from_str("{}").unwrap(),
)
.await
}
pub async fn get_my_organizations() -> Result<OrganizationResponse, String> {
get::<OrganizationResponse>(build_exp_link(
USER_API,
format!("/organization/getMyOrganizations"),
))
.await
}
pub async fn get_parent_org_list() -> Result<OrganizationResponse, String> {
get::<OrganizationResponse>(build_exp_link(
USER_API,
format!("/organization/getParentOrgList"),
))
.await
}
pub async fn get_parent_org_ids() -> Result<Vec<Uuid>, String> {
get::<Vec<Uuid>>(build_exp_link(
USER_API,
format!("/organization/getParentOrgIds"),
))
.await
}
pub async fn get_100_for_parent_org() -> Result<Vec<OrganizationResponse>, String> {
get::<Vec<OrganizationResponse>>(build_exp_link(
USER_API,
format!("/organization/get100ForParentOrg"),
))
.await
}
pub async fn get_child_for_parent_org(
parent_org_id: Uuid,
) -> Result<Vec<OrganizationResponse>, String> {
get::<Vec<OrganizationResponse>>(build_exp_link(
USER_API,
format!("/organization/getChildForParentOrg/{parent_org_id}"),
))
.await
}
pub async fn get_org_and_children() -> Result<Vec<OrganizationResponse>, String> {
get::<Vec<OrganizationResponse>>(build_exp_link(
USER_API,
format!("/organization/getOrgAndChildren"),
))
.await
}
pub async fn get_org_by_type(org_type: String) -> Result<Vec<OrganizationResponse>, String> {
get::<Vec<OrganizationResponse>>(build_exp_link(
USER_API,
format!("/organization/type/{org_type}"),
))
.await
}
pub async fn get_child_organizations() -> Result<Vec<OrganizationResponse>, String> {
get::<Vec<OrganizationResponse>>(build_exp_link(
USER_API,
format!("/organization/getChildrenOrganizations"),
))
.await
}
pub async fn get_org_by_name(name: String) -> Result<Vec<OrganizationResponse>, String> {
get::<Vec<OrganizationResponse>>(build_exp_link(
USER_API,
format!("/organization/byName/{name}"),
))
.await
}
}