shared/api/endpoints/
admin.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use super::ApiEndpoint;
use crate::domain::admin::{
    AdminSchoolAccountPath, AdminSchoolsPath, AdminVerifySchoolPath, DeleteUserAccountPath,
    GetAdminSchoolAccountResponse, ImportSchoolNamesPath, InviteSchoolUsersPath,
    InviteSchoolUsersRequest, InviteSchoolUsersResponse, RemoveUserFromSchoolPath, SchoolNamesPath,
    SearchSchoolsParams, SearchSchoolsResponse, SetAccountTierOverridePath,
    SetInternalSchoolNamePath, UpdateSchoolNamePath, VerifySchoolRequest,
};
use crate::domain::billing::{PlanTier, SchoolName, SchoolNameId, SchoolNameValue};
use crate::domain::user::UserId;
use crate::domain::UpdateNullable;
use crate::error::AccountError;
use crate::{
    api::Method,
    domain::{
        admin::{
            AdminJigExportPath, AdminPlaylistExportPath, AdminUserExportPath,
            AdminUserExportRequest,
        },
        billing::{SubscriptionPlanPath, UpdateSubscriptionPlansRequest},
        session::{ImpersonatePath, NewSessionResponse},
    },
    error::EmptyError,
};

/// Impersonate another user.
pub struct Impersonate;
impl ApiEndpoint for Impersonate {
    type Path = ImpersonatePath;
    type Req = ();
    type Res = NewSessionResponse;
    type Err = EmptyError;
    const METHOD: Method = Method::Post;
}

/// Export user data
pub struct AdminUserExport;
impl ApiEndpoint for AdminUserExport {
    type Path = AdminUserExportPath;
    type Req = AdminUserExportRequest;
    type Res = ();
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// Export jig data
pub struct AdminJigExport;
impl ApiEndpoint for AdminJigExport {
    type Path = AdminJigExportPath;
    type Req = ();
    type Res = ();
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// Export playlist data
pub struct AdminPlaylistExport;
impl ApiEndpoint for AdminPlaylistExport {
    type Path = AdminPlaylistExportPath;
    type Req = ();
    type Res = ();
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// Create or update a subscription plan
pub struct CreateUpdateSubscriptionPlans;
impl ApiEndpoint for CreateUpdateSubscriptionPlans {
    type Path = SubscriptionPlanPath;
    type Req = UpdateSubscriptionPlansRequest;
    type Res = ();
    type Err = EmptyError;
    const METHOD: Method = Method::Post;
}

/// List school names
pub struct SearchSchools;
impl ApiEndpoint for SearchSchools {
    type Path = AdminSchoolsPath;
    type Req = SearchSchoolsParams;
    type Res = SearchSchoolsResponse;
    type Err = EmptyError;
    const METHOD: Method = Method::Get;
}

/// Update a school names verification flag
pub struct VerifySchool;
impl ApiEndpoint for VerifySchool {
    type Path = AdminVerifySchoolPath;
    type Req = VerifySchoolRequest;
    type Res = ();
    type Err = EmptyError;
    const METHOD: Method = Method::Patch;
}

/// Update a school names verification flag
pub struct ImportSchoolNames;
impl ApiEndpoint for ImportSchoolNames {
    type Path = ImportSchoolNamesPath;
    type Req = String;
    type Res = Vec<String>;
    type Err = EmptyError;
    const METHOD: Method = Method::Post;
}

/// Invite users to a school
pub struct InviteUsers;
impl ApiEndpoint for InviteUsers {
    type Path = InviteSchoolUsersPath;
    type Req = InviteSchoolUsersRequest;
    type Res = InviteSchoolUsersResponse;
    type Err = EmptyError;
    const METHOD: Method = Method::Post;
}

/// Get a school account for administration
pub struct GetAdminSchoolAccount;
impl ApiEndpoint for GetAdminSchoolAccount {
    type Path = AdminSchoolAccountPath;
    type Req = ();
    type Res = GetAdminSchoolAccountResponse;
    type Err = AccountError;
    const METHOD: Method = Method::Get;
}

/// Set an accounts plan tier override
pub struct SetAccountTierOverride;
impl ApiEndpoint for SetAccountTierOverride {
    type Path = SetAccountTierOverridePath;
    type Req = UpdateNullable<PlanTier>;
    type Res = ();
    type Err = AccountError;
    const METHOD: Method = Method::Patch;
}

/// Get a list of imported school names
pub struct GetSchoolNames;
impl ApiEndpoint for GetSchoolNames {
    type Path = SchoolNamesPath;
    type Req = ();
    type Res = Vec<SchoolName>;
    type Err = AccountError;
    const METHOD: Method = Method::Get;
}

/// Update a school name
pub struct UpdateSchoolName;
impl ApiEndpoint for UpdateSchoolName {
    type Path = UpdateSchoolNamePath;
    type Req = SchoolNameValue;
    type Res = ();
    type Err = AccountError;
    const METHOD: Method = Method::Patch;
}

/// Create a school name
pub struct CreateSchoolName;
impl ApiEndpoint for CreateSchoolName {
    type Path = SchoolNamesPath;
    type Req = SchoolNameValue;
    type Res = SchoolNameId;
    type Err = AccountError;
    const METHOD: Method = Method::Post;
}
/// Set a school name for a school
pub struct SetInternalSchoolName;
impl ApiEndpoint for SetInternalSchoolName {
    type Path = SetInternalSchoolNamePath;
    type Req = SchoolNameId;
    type Res = ();
    type Err = AccountError;
    const METHOD: Method = Method::Patch;
}

/// Delete a user account
pub struct DeleteUserAccount;
impl ApiEndpoint for DeleteUserAccount {
    type Path = DeleteUserAccountPath;
    type Req = ();
    type Res = ();
    type Err = AccountError;
    const METHOD: Method = Method::Delete;
}

/// Set a school name for a school
pub struct RemoveUserFromSchool;
impl ApiEndpoint for RemoveUserFromSchool {
    type Path = RemoveUserFromSchoolPath;
    type Req = UserId;
    type Res = ();
    type Err = AccountError;
    const METHOD: Method = Method::Post;
}