1use std::sync::Arc;
8
9use aide::axum::{
10 ApiRouter,
11 routing::{get_with, post_with},
12};
13use axum::extract::{FromRef, FromRequestParts};
14use mas_matrix::HomeserverConnection;
15use mas_policy::PolicyFactory;
16use mas_storage::BoxRng;
17
18use super::call_context::CallContext;
19use crate::passwords::PasswordManager;
20
21mod compat_sessions;
22mod oauth2_sessions;
23mod policy_data;
24mod upstream_oauth_links;
25mod user_emails;
26mod user_registration_tokens;
27mod user_sessions;
28mod users;
29
30#[allow(clippy::too_many_lines)]
31pub fn router<S>() -> ApiRouter<S>
32where
33 S: Clone + Send + Sync + 'static,
34 Arc<dyn HomeserverConnection>: FromRef<S>,
35 PasswordManager: FromRef<S>,
36 Arc<PolicyFactory>: FromRef<S>,
37 BoxRng: FromRequestParts<S>,
38 CallContext: FromRequestParts<S>,
39{
40 ApiRouter::<S>::new()
41 .api_route(
42 "/compat-sessions",
43 get_with(self::compat_sessions::list, self::compat_sessions::list_doc),
44 )
45 .api_route(
46 "/compat-sessions/{id}",
47 get_with(self::compat_sessions::get, self::compat_sessions::get_doc),
48 )
49 .api_route(
50 "/oauth2-sessions",
51 get_with(self::oauth2_sessions::list, self::oauth2_sessions::list_doc),
52 )
53 .api_route(
54 "/oauth2-sessions/{id}",
55 get_with(self::oauth2_sessions::get, self::oauth2_sessions::get_doc),
56 )
57 .api_route(
58 "/policy-data",
59 post_with(self::policy_data::set, self::policy_data::set_doc),
60 )
61 .api_route(
62 "/policy-data/latest",
63 get_with(
64 self::policy_data::get_latest,
65 self::policy_data::get_latest_doc,
66 ),
67 )
68 .api_route(
69 "/policy-data/{id}",
70 get_with(self::policy_data::get, self::policy_data::get_doc),
71 )
72 .api_route(
73 "/users",
74 get_with(self::users::list, self::users::list_doc)
75 .post_with(self::users::add, self::users::add_doc),
76 )
77 .api_route(
78 "/users/{id}",
79 get_with(self::users::get, self::users::get_doc),
80 )
81 .api_route(
82 "/users/{id}/set-password",
83 post_with(self::users::set_password, self::users::set_password_doc),
84 )
85 .api_route(
86 "/users/by-username/{username}",
87 get_with(self::users::by_username, self::users::by_username_doc),
88 )
89 .api_route(
90 "/users/{id}/set-admin",
91 post_with(self::users::set_admin, self::users::set_admin_doc),
92 )
93 .api_route(
94 "/users/{id}/deactivate",
95 post_with(self::users::deactivate, self::users::deactivate_doc),
96 )
97 .api_route(
98 "/users/{id}/lock",
99 post_with(self::users::lock, self::users::lock_doc),
100 )
101 .api_route(
102 "/users/{id}/unlock",
103 post_with(self::users::unlock, self::users::unlock_doc),
104 )
105 .api_route(
106 "/user-emails",
107 get_with(self::user_emails::list, self::user_emails::list_doc)
108 .post_with(self::user_emails::add, self::user_emails::add_doc),
109 )
110 .api_route(
111 "/user-emails/{id}",
112 get_with(self::user_emails::get, self::user_emails::get_doc)
113 .delete_with(self::user_emails::delete, self::user_emails::delete_doc),
114 )
115 .api_route(
116 "/user-sessions",
117 get_with(self::user_sessions::list, self::user_sessions::list_doc),
118 )
119 .api_route(
120 "/user-sessions/{id}",
121 get_with(self::user_sessions::get, self::user_sessions::get_doc),
122 )
123 .api_route(
124 "/user-registration-tokens",
125 get_with(
126 self::user_registration_tokens::list,
127 self::user_registration_tokens::list_doc,
128 )
129 .post_with(
130 self::user_registration_tokens::add,
131 self::user_registration_tokens::add_doc,
132 ),
133 )
134 .api_route(
135 "/user-registration-tokens/{id}",
136 get_with(
137 self::user_registration_tokens::get,
138 self::user_registration_tokens::get_doc,
139 )
140 .put_with(
141 self::user_registration_tokens::update,
142 self::user_registration_tokens::update_doc,
143 ),
144 )
145 .api_route(
146 "/user-registration-tokens/{id}/revoke",
147 post_with(
148 self::user_registration_tokens::revoke,
149 self::user_registration_tokens::revoke_doc,
150 ),
151 )
152 .api_route(
153 "/user-registration-tokens/{id}/unrevoke",
154 post_with(
155 self::user_registration_tokens::unrevoke,
156 self::user_registration_tokens::unrevoke_doc,
157 ),
158 )
159 .api_route(
160 "/upstream-oauth-links",
161 get_with(
162 self::upstream_oauth_links::list,
163 self::upstream_oauth_links::list_doc,
164 )
165 .post_with(
166 self::upstream_oauth_links::add,
167 self::upstream_oauth_links::add_doc,
168 ),
169 )
170 .api_route(
171 "/upstream-oauth-links/{id}",
172 get_with(
173 self::upstream_oauth_links::get,
174 self::upstream_oauth_links::get_doc,
175 )
176 .delete_with(
177 self::upstream_oauth_links::delete,
178 self::upstream_oauth_links::delete_doc,
179 ),
180 )
181}