shared/api/endpoints/
admin.rs

1use super::ApiEndpoint;
2use crate::domain::admin::{
3    AdminSchoolAccountPath, AdminSchoolsPath, AdminVerifySchoolPath, DeleteUserAccountPath,
4    GetAdminSchoolAccountResponse, ImportSchoolNamesPath, InviteSchoolUsersPath,
5    InviteSchoolUsersRequest, InviteSchoolUsersResponse, RemoveUserFromSchoolPath, SchoolNamesPath,
6    SearchSchoolsParams, SearchSchoolsResponse, SetAccountTierOverridePath,
7    SetInternalSchoolNamePath, UpdateSchoolNamePath, VerifySchoolRequest,
8};
9use crate::domain::billing::{PlanTier, SchoolName, SchoolNameId, SchoolNameValue};
10use crate::domain::user::UserId;
11use crate::domain::UpdateNullable;
12use crate::error::AccountError;
13use crate::{
14    api::Method,
15    domain::{
16        admin::{
17            AdminJigExportPath, AdminPlaylistExportPath, AdminUserExportPath,
18            AdminUserExportRequest,
19        },
20        billing::{SubscriptionPlanPath, UpdateSubscriptionPlansRequest},
21        session::{ImpersonatePath, NewSessionResponse},
22    },
23    error::EmptyError,
24};
25
26/// Impersonate another user.
27pub struct Impersonate;
28impl ApiEndpoint for Impersonate {
29    type Path = ImpersonatePath;
30    type Req = ();
31    type Res = NewSessionResponse;
32    type Err = EmptyError;
33    const METHOD: Method = Method::Post;
34}
35
36/// Export user data
37pub struct AdminUserExport;
38impl ApiEndpoint for AdminUserExport {
39    type Path = AdminUserExportPath;
40    type Req = AdminUserExportRequest;
41    type Res = ();
42    type Err = EmptyError;
43    const METHOD: Method = Method::Get;
44}
45
46/// Export jig data
47pub struct AdminJigExport;
48impl ApiEndpoint for AdminJigExport {
49    type Path = AdminJigExportPath;
50    type Req = ();
51    type Res = ();
52    type Err = EmptyError;
53    const METHOD: Method = Method::Get;
54}
55
56/// Export playlist data
57pub struct AdminPlaylistExport;
58impl ApiEndpoint for AdminPlaylistExport {
59    type Path = AdminPlaylistExportPath;
60    type Req = ();
61    type Res = ();
62    type Err = EmptyError;
63    const METHOD: Method = Method::Get;
64}
65
66/// Create or update a subscription plan
67pub struct CreateUpdateSubscriptionPlans;
68impl ApiEndpoint for CreateUpdateSubscriptionPlans {
69    type Path = SubscriptionPlanPath;
70    type Req = UpdateSubscriptionPlansRequest;
71    type Res = ();
72    type Err = EmptyError;
73    const METHOD: Method = Method::Post;
74}
75
76/// List school names
77pub struct SearchSchools;
78impl ApiEndpoint for SearchSchools {
79    type Path = AdminSchoolsPath;
80    type Req = SearchSchoolsParams;
81    type Res = SearchSchoolsResponse;
82    type Err = EmptyError;
83    const METHOD: Method = Method::Get;
84}
85
86/// Update a school names verification flag
87pub struct VerifySchool;
88impl ApiEndpoint for VerifySchool {
89    type Path = AdminVerifySchoolPath;
90    type Req = VerifySchoolRequest;
91    type Res = ();
92    type Err = EmptyError;
93    const METHOD: Method = Method::Patch;
94}
95
96/// Update a school names verification flag
97pub struct ImportSchoolNames;
98impl ApiEndpoint for ImportSchoolNames {
99    type Path = ImportSchoolNamesPath;
100    type Req = String;
101    type Res = Vec<String>;
102    type Err = EmptyError;
103    const METHOD: Method = Method::Post;
104}
105
106/// Invite users to a school
107pub struct InviteUsers;
108impl ApiEndpoint for InviteUsers {
109    type Path = InviteSchoolUsersPath;
110    type Req = InviteSchoolUsersRequest;
111    type Res = InviteSchoolUsersResponse;
112    type Err = EmptyError;
113    const METHOD: Method = Method::Post;
114}
115
116/// Get a school account for administration
117pub struct GetAdminSchoolAccount;
118impl ApiEndpoint for GetAdminSchoolAccount {
119    type Path = AdminSchoolAccountPath;
120    type Req = ();
121    type Res = GetAdminSchoolAccountResponse;
122    type Err = AccountError;
123    const METHOD: Method = Method::Get;
124}
125
126/// Set an accounts plan tier override
127pub struct SetAccountTierOverride;
128impl ApiEndpoint for SetAccountTierOverride {
129    type Path = SetAccountTierOverridePath;
130    type Req = UpdateNullable<PlanTier>;
131    type Res = ();
132    type Err = AccountError;
133    const METHOD: Method = Method::Patch;
134}
135
136/// Get a list of imported school names
137pub struct GetSchoolNames;
138impl ApiEndpoint for GetSchoolNames {
139    type Path = SchoolNamesPath;
140    type Req = ();
141    type Res = Vec<SchoolName>;
142    type Err = AccountError;
143    const METHOD: Method = Method::Get;
144}
145
146/// Update a school name
147pub struct UpdateSchoolName;
148impl ApiEndpoint for UpdateSchoolName {
149    type Path = UpdateSchoolNamePath;
150    type Req = SchoolNameValue;
151    type Res = ();
152    type Err = AccountError;
153    const METHOD: Method = Method::Patch;
154}
155
156/// Create a school name
157pub struct CreateSchoolName;
158impl ApiEndpoint for CreateSchoolName {
159    type Path = SchoolNamesPath;
160    type Req = SchoolNameValue;
161    type Res = SchoolNameId;
162    type Err = AccountError;
163    const METHOD: Method = Method::Post;
164}
165/// Set a school name for a school
166pub struct SetInternalSchoolName;
167impl ApiEndpoint for SetInternalSchoolName {
168    type Path = SetInternalSchoolNamePath;
169    type Req = SchoolNameId;
170    type Res = ();
171    type Err = AccountError;
172    const METHOD: Method = Method::Patch;
173}
174
175/// Delete a user account
176pub struct DeleteUserAccount;
177impl ApiEndpoint for DeleteUserAccount {
178    type Path = DeleteUserAccountPath;
179    type Req = ();
180    type Res = ();
181    type Err = AccountError;
182    const METHOD: Method = Method::Delete;
183}
184
185/// Set a school name for a school
186pub struct RemoveUserFromSchool;
187impl ApiEndpoint for RemoveUserFromSchool {
188    type Path = RemoveUserFromSchoolPath;
189    type Req = UserId;
190    type Res = ();
191    type Err = AccountError;
192    const METHOD: Method = Method::Post;
193}