summaryrefslogtreecommitdiff
path: root/src/channel/routes.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-05 20:32:02 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-05 22:47:12 -0400
commit1fb26ad31d385ddc628e1b73d6a8764981ca6885 (patch)
treeda226cfc7e054ce93bf37da943a395dee226baa6 /src/channel/routes.rs
parent8edd5625ad5dde0ef1637d5c89e9901b3ee65d73 (diff)
Use `/api/boot` to bootstrap the client.
The client now takes an initial snapshot from the response to `/api/boot`, then picks up the event stream at the immediately-successive event to the moment the snapshot was taken. This commit removes the following unused endpoints: * `/api/channels` (GET) * `/api/channels/:channel/messages` (GET) The information therein is now part of the boot response. We can always add 'em back, but I wanted to clear the deck for designing something more capable, for dealing with client needs.
Diffstat (limited to 'src/channel/routes.rs')
-rw-r--r--src/channel/routes.rs89
1 files changed, 2 insertions, 87 deletions
diff --git a/src/channel/routes.rs b/src/channel/routes.rs
index 23c0602..5d67af8 100644
--- a/src/channel/routes.rs
+++ b/src/channel/routes.rs
@@ -2,56 +2,21 @@ use axum::{
extract::{Json, Path, State},
http::StatusCode,
response::{IntoResponse, Response},
- routing::{delete, get, post},
+ routing::{delete, post},
Router,
};
-use axum_extra::extract::Query;
use super::{app, Channel, Id};
-use crate::{
- app::App,
- clock::RequestedAt,
- error::Internal,
- event::{Instant, Sequence},
- login::Login,
- message::{self, app::SendError},
-};
+use crate::{app::App, clock::RequestedAt, error::Internal, login::Login, message::app::SendError};
#[cfg(test)]
mod test;
pub fn router() -> Router<App> {
Router::new()
- .route("/api/channels", get(list))
.route("/api/channels", post(on_create))
.route("/api/channels/:channel", post(on_send))
.route("/api/channels/:channel", delete(on_delete))
- .route("/api/channels/:channel/messages", get(messages))
-}
-
-#[derive(Default, serde::Deserialize)]
-struct ResumeQuery {
- resume_point: Option<Sequence>,
-}
-
-async fn list(
- State(app): State<App>,
- _: Login,
- Query(query): Query<ResumeQuery>,
-) -> Result<Channels, Internal> {
- let channels = app.channels().all(query.resume_point).await?;
- let response = Channels(channels);
-
- Ok(response)
-}
-
-struct Channels(Vec<Channel>);
-
-impl IntoResponse for Channels {
- fn into_response(self) -> Response {
- let Self(channels) = self;
- Json(channels).into_response()
- }
}
#[derive(Clone, serde::Deserialize)]
@@ -150,53 +115,3 @@ impl IntoResponse for ErrorResponse {
}
}
}
-
-async fn messages(
- State(app): State<App>,
- Path(channel): Path<Id>,
- _: Login,
- Query(query): Query<ResumeQuery>,
-) -> Result<Messages, ErrorResponse> {
- let messages = app
- .channels()
- .messages(&channel, query.resume_point)
- .await?;
- let response = Messages(
- messages
- .into_iter()
- .map(|message| MessageView {
- sent: message.sent,
- sender: message.sender,
- message: MessageInner {
- id: message.id,
- body: message.body,
- },
- })
- .collect(),
- );
-
- Ok(response)
-}
-
-struct Messages(Vec<MessageView>);
-
-#[derive(serde::Serialize)]
-struct MessageView {
- #[serde(flatten)]
- sent: Instant,
- sender: Login,
- message: MessageInner,
-}
-
-#[derive(serde::Serialize)]
-struct MessageInner {
- id: message::Id,
- body: String,
-}
-
-impl IntoResponse for Messages {
- fn into_response(self) -> Response {
- let Self(messages) = self;
- Json(messages).into_response()
- }
-}