blatherskite

a toy discord-like chat app backend written for a swe class
Log | Files | Refs | README

commit c8446e0d548ae1c1241d3ac34fe9051f726aa700
parent 2f23276543271606865c80d5f2cc299d2f2ab850
Author: quantumish <freifeld.david@gmail.com>
Date:   Fri, 23 Sep 2022 20:34:47 -0700

Add search/message requests, document all responses

Diffstat:
Mscuttlebutt/src/main.rs | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 78 insertions(+), 4 deletions(-)

diff --git a/scuttlebutt/src/main.rs b/scuttlebutt/src/main.rs @@ -37,6 +37,14 @@ struct Channel { members: Vec<i64>, } +#[derive(Object)] +struct Message { + id: i64, + channel: i64, + author: i64, + content: String, +} + // type ServerKey = Hmac<Sha256>; // /// ApiKey authorization @@ -143,6 +151,49 @@ enum GenericResponse { NotFound(PlainText<String>), } +#[derive(ApiResponse)] +enum MessagesResponse { + /// Returns the messages requested + #[oai(status = 200)] + Messages(Json<Vec<Message>>), + /// Invalid ID, or no messages found. Content specifies which error occured. + #[oai(status = 404)] + NotFound(PlainText<String>), + /// Offset or number of messages requested is bad. Content specifies which error occured. + #[oai(status = 400)] + BadRequest(PlainText<String>), +} + +#[derive(ApiResponse)] +enum MembersResponse { + /// Returns the members of current channel/group + #[oai(status = 200)] + Messages(Json<Vec<User>>), + /// Invalid ID + #[oai(status = 404)] + NotFound, +} + +#[derive(ApiResponse)] +enum GroupsResponse { + /// Returns the groups the user is a memmber of + #[oai(status = 200)] + Messages(Json<Vec<Group>>), + /// Invalid user ID + #[oai(status = 404)] + NotFound, +} + +#[derive(ApiResponse)] +enum ChannelsResponse { + /// Returns the channels in a group + #[oai(status = 200)] + Messages(Json<Vec<Channel>>), + /// Invalid group ID + #[oai(status = 404)] + NotFound, +} + #[OpenApi] impl Api { #[oai(path = "/user", method = "get")] @@ -185,7 +236,7 @@ impl Api { #[oai(path = "/user/groups", method = "get")] /// Gets all groups accessible to a user - async fn get_groups(&self, id: Query<i64>) -> Json<Vec<Group>> { + async fn get_groups(&self, id: Query<i64>) -> GroupsResponse { todo!() } @@ -221,7 +272,7 @@ impl Api { #[oai(path = "/group/members", method = "get")] /// Gets the members of the specified group - async fn get_group_members(&self, id: Query<i64>) -> Json<Vec<User>> { + async fn get_group_members(&self, id: Query<i64>) -> MembersResponse { todo!() } @@ -239,7 +290,7 @@ impl Api { #[oai(path = "/group/channels", method = "get")] /// Gets all channels in a group that are accessible to a user - async fn get_channels(&self, gid: Query<i64>, uid: Query<i64>) -> Json<Vec<Channel>> { + async fn get_channels(&self, gid: Query<i64>, uid: Query<i64>) -> ChannelsResponse { todo!() } @@ -263,7 +314,7 @@ impl Api { #[oai(path = "/channel/members", method = "get")] /// Gets the members that can access a channel - async fn get_channel_members(&self, id: Query<i64>) -> Json<Vec<User>> { + async fn get_channel_members(&self, id: Query<i64>) -> MembersResponse { todo!() } @@ -278,6 +329,29 @@ impl Api { async fn remove_channel_member(&self, cid: Query<i64>, uid: Query<i64>) -> DeleteResponse { todo!() } + + #[oai(path = "/channel/message", method = "get")] + /// Returns batch of messages in channel containing "term" starting at offset + async fn search_channel( + &self, + cid: Query<i64>, + term: Query<String>, + off: Query<u64>, + ) -> MessagesResponse { + todo!() + } + + #[oai(path = "/channel/messages", method = "get")] + /// Returns batch of messages in channel. Do not use for small batches. + /// + /// For small batches, use `chatterbox`, the websocket service for messaging, instead. + async fn get_channel_messages( + &self, + cid: Query<i64>, + num_msgs: Query<u64>, + ) -> MessagesResponse { + todo!() + } } #[tokio::main]