userlib/store/
organization_store.rs1use std::str::FromStr;
2
3use common::remote::services::USER_API;
4use common::store::build_exp_link;
5use common::store::{get, post, put};
6use uuid::Uuid;
7
8use crate::dto::address_request::AddressRequest;
9use crate::dto::organization_request::OrganizationRequest;
10use crate::dto::organization_response::OrganizationResponse;
11use crate::dto::organization_short_response::OrganizationShortResponse;
12
13pub struct OrganizationStore {}
14
15impl OrganizationStore {
16 pub async fn create(
17 new_organization: OrganizationRequest,
18 ) -> Result<OrganizationResponse, String> {
19 post::<_, OrganizationResponse>(
20 build_exp_link(USER_API, format!("/organization")),
21 new_organization,
22 )
23 .await
24 }
25
26 pub async fn get(org_id: Uuid) -> Result<OrganizationResponse, String> {
27 get::<OrganizationResponse>(build_exp_link(USER_API, format!("/organization/{org_id}")))
28 .await
29 }
30
31 pub async fn update(
32 new_organization: OrganizationRequest,
33 ) -> Result<OrganizationResponse, String> {
34 put::<_, OrganizationResponse>(
35 build_exp_link(USER_API, format!("/organization")),
36 new_organization,
37 )
38 .await
39 }
40
41 pub async fn get_child_ids_for_parent_org(parent_id: Uuid) -> Result<Vec<Uuid>, String> {
42 get::<Vec<Uuid>>(build_exp_link(
43 USER_API,
44 format!("/organization/getChildIdsForParentOrg/{parent_id}"),
45 ))
46 .await
47 }
48
49 pub async fn get_short_parent_org(
50 parent_id: Uuid,
51 ) -> Result<OrganizationShortResponse, String> {
52 get::<OrganizationShortResponse>(build_exp_link(
53 USER_API,
54 format!("/organization/getShortOrg/{parent_id}"),
55 ))
56 .await
57 }
58
59 pub async fn get_addresses() -> Result<AddressRequest, String> {
60 get::<AddressRequest>(build_exp_link(USER_API, format!("/organization/addresses"))).await
62 }
63
64 pub async fn get_addresses_for_org(org_id: Uuid) -> Result<AddressRequest, String> {
65 get::<AddressRequest>(build_exp_link(
67 USER_API,
68 format!("/organization/addressesForOrg/{org_id}"),
69 ))
70 .await
71 }
72
73 pub async fn set_syllabus(ep_id: Uuid) -> Result<OrganizationResponse, String> {
74 put::<_, OrganizationResponse>(
75 build_exp_link(USER_API, format!("/organization/setSyllabus/{ep_id}")),
76 serde_json::Value::from_str("{}").unwrap(),
77 )
78 .await
79 }
80
81 pub async fn set_academic_year(ay_id: Uuid) -> Result<OrganizationResponse, String> {
82 put::<_, OrganizationResponse>(
83 build_exp_link(USER_API, format!("/organization/setAcademicYear/{ay_id}")),
84 serde_json::Value::from_str("{}").unwrap(),
85 )
86 .await
87 }
88
89 pub async fn get_my_organizations() -> Result<OrganizationResponse, String> {
90 get::<OrganizationResponse>(build_exp_link(
91 USER_API,
92 format!("/organization/getMyOrganizations"),
93 ))
94 .await
95 }
96
97 pub async fn get_parent_org_list() -> Result<OrganizationResponse, String> {
98 get::<OrganizationResponse>(build_exp_link(
99 USER_API,
100 format!("/organization/getParentOrgList"),
101 ))
102 .await
103 }
104
105 pub async fn get_parent_org_ids() -> Result<Vec<Uuid>, String> {
106 get::<Vec<Uuid>>(build_exp_link(
107 USER_API,
108 format!("/organization/getParentOrgIds"),
109 ))
110 .await
111 }
112
113 pub async fn get_100_for_parent_org() -> Result<Vec<OrganizationResponse>, String> {
114 get::<Vec<OrganizationResponse>>(build_exp_link(
116 USER_API,
117 format!("/organization/get100ForParentOrg"),
119 ))
120 .await
121 }
122
123 pub async fn get_child_for_parent_org(
124 parent_org_id: Uuid,
125 ) -> Result<Vec<OrganizationResponse>, String> {
126 get::<Vec<OrganizationResponse>>(build_exp_link(
127 USER_API,
128 format!("/organization/getChildForParentOrg/{parent_org_id}"),
129 ))
130 .await
131 }
132
133 pub async fn get_org_and_children() -> Result<Vec<OrganizationResponse>, String> {
134 get::<Vec<OrganizationResponse>>(build_exp_link(
135 USER_API,
136 format!("/organization/getOrgAndChildren"),
137 ))
138 .await
139 }
140
141 pub async fn get_org_by_type(org_type: String) -> Result<Vec<OrganizationResponse>, String> {
142 get::<Vec<OrganizationResponse>>(build_exp_link(
143 USER_API,
144 format!("/organization/type/{org_type}"),
145 ))
146 .await
147 }
148
149 pub async fn get_child_organizations() -> Result<Vec<OrganizationResponse>, String> {
150 get::<Vec<OrganizationResponse>>(build_exp_link(
151 USER_API,
152 format!("/organization/getChildrenOrganizations"),
153 ))
154 .await
155 }
156
157 pub async fn get_org_by_name(name: String) -> Result<Vec<OrganizationResponse>, String> {
158 get::<Vec<OrganizationResponse>>(build_exp_link(
159 USER_API,
160 format!("/organization/byName/{name}"),
161 ))
162 .await
163 }
164}