smk-chat/docs.md

3.0 KiB

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.