diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-10-05 22:42:43 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-10-05 22:47:12 -0400 |
| commit | 6a10fcaf64938da52b326ea80013d9f30ed62a6c (patch) | |
| tree | 08a3860b68391514390f42872ccc1cb4c6e6afd2 /src/login/routes.rs | |
| parent | 1fb26ad31d385ddc628e1b73d6a8764981ca6885 (diff) | |
Separate `/api/boot` into its own module.
Diffstat (limited to 'src/login/routes.rs')
| -rw-r--r-- | src/login/routes.rs | 90 |
1 files changed, 2 insertions, 88 deletions
diff --git a/src/login/routes.rs b/src/login/routes.rs index b0e3fee..6579ae6 100644 --- a/src/login/routes.rs +++ b/src/login/routes.rs @@ -2,19 +2,15 @@ use axum::{ extract::{Json, State}, http::StatusCode, response::{IntoResponse, Response}, - routing::{get, post}, + routing::post, Router, }; -use futures::stream::{self, StreamExt as _, TryStreamExt as _}; use crate::{ app::App, - channel::Channel, clock::RequestedAt, error::{Internal, Unauthorized}, - event::Instant, - login::{Login, Password}, - message::{self, Message}, + login::Password, token::{app, extract::IdentityToken}, }; @@ -23,92 +19,10 @@ mod test; pub fn router() -> Router<App> { Router::new() - .route("/api/boot", get(boot)) .route("/api/auth/login", post(on_login)) .route("/api/auth/logout", post(on_logout)) } -async fn boot(State(app): State<App>, login: Login) -> Result<Boot, Internal> { - let resume_point = app.logins().boot_point().await?; - let channels = app.channels().all(resume_point.into()).await?; - let channels = stream::iter(channels) - .then(|channel| async { - app.messages() - .in_channel(&channel.id, resume_point.into()) - .await - .map(|messages| BootChannel::new(channel, messages)) - }) - .try_collect() - .await?; - - Ok(Boot { - login, - resume_point: resume_point.to_string(), - channels, - }) -} - -#[derive(serde::Serialize)] -struct Boot { - login: Login, - resume_point: String, - channels: Vec<BootChannel>, -} - -#[derive(serde::Serialize)] -struct BootChannel { - #[serde(flatten)] - channel: Channel, - messages: Vec<BootMessage>, -} - -impl BootChannel { - fn new(channel: Channel, messages: impl IntoIterator<Item = Message>) -> Self { - Self { - channel, - messages: messages.into_iter().map(BootMessage::from).collect(), - } - } -} - -#[derive(serde::Serialize)] -struct BootMessage { - #[serde(flatten)] - sent: Instant, - sender: Login, - message: BootMessageBody, -} - -impl From<Message> for BootMessage { - fn from(message: Message) -> Self { - let Message { - sent, - channel: _, - sender, - id, - body, - } = message; - - Self { - sent, - sender, - message: BootMessageBody { id, body }, - } - } -} - -#[derive(serde::Serialize)] -struct BootMessageBody { - id: message::Id, - body: String, -} - -impl IntoResponse for Boot { - fn into_response(self) -> Response { - Json(self).into_response() - } -} - #[derive(serde::Deserialize)] struct LoginRequest { name: String, |
