userlib/store/
organization_store.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use 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> {
        // todo address response
        get::<AddressRequest>(build_exp_link(USER_API, format!("/organization/addresses"))).await
    }

    pub async fn get_addresses_for_org(org_id: Uuid) -> Result<AddressRequest, String> {
        // todo address response
        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> {
        // todo start ???
        get::<Vec<OrganizationResponse>>(build_exp_link(
            USER_API,
            // format!("/organization/get100ForParentOrg/{start}")),
            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
    }
}