From 1158481cb9f2f77f24241fed4f9066a415151cb6 Mon Sep 17 00:00:00 2001 From: leca Date: Fri, 21 Jun 2024 13:03:14 +0300 Subject: [PATCH] There are docs for the chat. --- Docs.md | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Docs.md diff --git a/Docs.md b/Docs.md new file mode 100644 index 0000000..2da3489 --- /dev/null +++ b/Docs.md @@ -0,0 +1,76 @@ +# Docs for smk-chat +## API +### /api/getCredentialsById/:userId +IN: _userId_ (in route) + +OUT: _lastname_, _firstname_, _middlename_ +Return credentials of the user whose id is userId. +Return -1 if no such user exist. +Requires client to be logged in. + +### /api/getIdByCredentials +IN: _lastname_, _firstname_, _middlename_ +OUT: _UserID_ +Returns an ID of the user, whose lastname, firstname and middlename were passed. +Returns -1 if user does not exist. +Requires client to be logged in. + +### /api/getMessagesFromChat/by-amount +IN: _chatId_, _amount_ +OUT: array of objects that represent a message, like {"author_id": ..., time_sent: ..., content: ...} +Returns an array of last _amount_ ordered by date of described objects if everything is okay +Returns HTTP/1.1 400 "Chat with id _ID_ does not exist." if no chat with supplied id does not exist. +Returns HTTP/1.1 403 "You are not a member of this chat" if the statement is true ;) +Requires client to be logged in. + +### /api/getMessagesFromChat/by-time +IN: _chatId_, _fromTimestamp_, _toTimestamp_ +OUT: array of objects that represent a message, like {"author_id": ..., time_sent: ..., content: ...} +_fromTimestamp_ must be lower that _toTimestamp_, otherwise it might return nothing. +Returns an array of described objects if everything is okay +Returns HTTP/1.1 400 "Chat with id _ID_ does not exist." if no chat with supplied id does not exist. +Returns HTTP/1.1 200 and an empty string if no messages in chat are found /shrug. +Requires client to be logged in. + +### /api/getChats +IN: _UserID_ +OUT: Array of chat IDs +Returs an array with ids of chats which user with passed ID is member in. +Return empty string if user has no membership in any chat. +Requires client to be logged in. + +### /api/getChatInfo/:chatId +IN: _chatId_ (in route) +OUT: JSON describes a chat with id: {name: ..., admins: ..., members: ...} +Note: JSON does not include messages. You have to use __/api/getMessagesFromChat__ to query messages. +Returns aforementioned json if the chat exists and user is a member of this chat. +Returns -1 if chat does not exist +Return -2 if user is not a member of the chat +Requires client to be logged in. + +### /api/createChat +IN: _UserId_, array of UserIDs that are to be invited. +OUT: "Ok" if successful, "User with id _MEMBERID_ does not exist." +Return -1 if amout of users to invite is 0. +Requires client to be logged in + +### /api/logout +IN: none. +OUT: redirect to __/login__. +Removes client's session, thus unlogging a user. +Requires client to be logged in. + +### /api/register +IN: _lastname_, _firstname_, _middlename_, _password_ +OUT: redirect to __/__ +Checks if user exist. If so, returns 400 with response "Such user exists.". +Otherwise, registers a user with given data. +Requires clinet to be not logged in. + +### /api/login +IN: _lastname_, _firstname_, _middlename_, _password_ +OUT: redirect to __/__ +Checks if user exists. If not, returns 400 with response "No such user.". +Otherwise, compares passwords +If passwords match, creating session and redirects to __/__ +Requires client to be not logged in.