You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The chat-room-api is an API developed with Django and Django Rest Framework in addition to other libraries and tools. The idea of this project is to serve as a back-end for a Chat Room (front-end web application) with similarities to Discord or similar platforms, in which registered users can join existing chat rooms or create their own and chat with peers. The chat-room-API allows for chat rooms, users, and messages to be filtered or searched by query parameters. The API supports token-based authenticated requests and, it's a must to ensure that all the permission and authorization functionalities are applied to the users based on their roles.
Installation
Docker Containers
Follow the instructions on the branch docker to build the containers to run this project.
💡 If you do not have an existing database and user to use with these settings, follow the
instructions below and create new ones.
Enter The PostgreSQL Prompt
psql -U postgres -d postgres
Create The Database
CREATE DATABASE <database_name>;
Create The User
CREATE USER <username> WITH ENCRYPTED PASSWORD '<password>';
Modifying Connection Parameters
ALTER ROLE <database_user>SET client_encoding TO 'utf8';
ALTER ROLE <database_user>SET default_transaction_isolation TO 'read committed';
ALTER ROLE <database_user>SET timezone TO 'UTC';
Grant Permissions To The User
GRANT ALL PRIVILEGES ON DATABASE <database_name> TO <username>;
Exit The Prompt
\q
Environment Variables
Create The Environment Variables File (.env)
In the root directory (chat-room-api/), create the .env file and add to it the following
💡 Be aware that django-environ is required. Such dependency should be installed
by running pipenv install
Apply the migrations
pythonmanage.pymigrate
Tests
I have created a total of 34 tests, that test the app api, chatrooms, and accounts.
Run the tests
python manage.py test
It should return an output such as
Found 34 test(s).Creating test database for alias 'default'...System check identified no issues (0 silenced)...................................----------------------------------------------------------------------Ran 34 tests in 13.430sOKDestroying test database for alias 'default'...
Tests in api app
A total of 30 tests were included. Each functionality of the endpoints in the API is tested.
The requests made in the tests to the API endpoints are token-based authenticated requests.
Tests in the chatrooms app
The tests in the chatrooms app perform CRUD operations on Chatroom and Message models.
Tests in the accounts app
The test in the account app performs CRUD operations in the CustomUser model.
API Endpoints
The project consists of a total of ten (10) endpoints, such endpoints provide functionalities for users, chatrooms, messages and more.
Endpoints list
URL
ALLOWED HTTP METHODS
api/users
GET, POST
api/users/{userId}
GET, PATCH, PUT, DELETE
api/users/{userId}/friends
GET, POST, DELETE
api/messages
GET, POST
api/messages/{messageId}
GET, PATCH, PUT, DELETE
api/chatrooms
GET, POST
api/chatrooms/{chatroomId}
GET, PATCH, PUT, DELETE
api/chatrooms/{chatroomId}/messages
GET, POST
api/chatrooms/{chatroomId}/Admins
GET, POST, DELETE
api/chatrooms/{chatroomId}/participants
GET, POST, DELETE
api/users
HTTP METHOD
REQUIRED DATA
ACTION
STATUS CODE
GET
Retrieves the list of users
200
POST
username, password
Creates a user
201
api/users/{userId}
HTTP METHOD
REQUIRED DATA
ACTION
STATUS CODE
GET
Retrieves the details of the user
200
PATCH
Any field
Partially updates the user data
200
PUT
All fields
Updates the user data
200
DELETE
Deletes the user
204
api/users/{userId}/friends
HTTP METHOD
REQUIRED DATA
ACTION
STATUS CODE
GET
Retrieves the user's friend list
200
POST
Adds a friend to the user's friend list
200
DELETE
Deletes a friend from the user's friend list
200
api/messages
HTTP METHOD
REQUIRED DATA
ACTION
STATUS CODE
GET
Retrieves the list of messages
200
POST
chatroom_id, sender_id, body
Creates a message
201
api/messages/{messageId}
HTTP METHOD
REQUIRED DATA
ACTION
STATUS CODE
GET
Retrieves the details of the message
200
PATCH
Any field
Partially updates the message data
200
PUT
All fields
Updates the message data
200
DELETE
Deletes the message
204
api/chatrooms
HTTP METHOD
REQUIRED DATA
ACTION
STATUS CODE
GET
Retrieves the list of chatrooms
200
POST
name
Creates a chatroom
201
api/chatrooms/{chatroomId}
HTTP METHOD
REQUIRED DATA
ACTION
STATUS CODE
GET
Retrieves the details of the chatroom
200
PATCH
Any field
Partially updates the chatroom data
200
PUT
All fields
Updates the chatroom data
200
DELETE
Deletes the chatroom
204
api/chatrooms/{chatroomId}/messages
HTTP METHOD
REQUIRED DATA
ACTION
STATUS CODE
GET
Retrieves the list of messages associated with the chatroom
200
POST
body
Creates a message and adds it to the chatroom
200
💡 The DELETE method can be called on the message object by using the api/messages/{messageId} endpoint.
api/chatrooms/{chatroomId}/admins
HTTP METHOD
REQUIRED DATA
ACTION
STATUS CODE
GET
Retrieves the list of admins associated with the chatroom
200
POST
id
Adds the admins to the chatroom
200
DELETE
id
Removes the admins from the chatroom
200
api/chatrooms/{chatroomId}/participants
HTTP METHOD
REQUIRED DATA
ACTION
STATUS CODE
GET
Retrieves the list of participants associated with the chatroom
200
POST
id
Adds the participant to the chatroom
200
DELETE
id
Removes the participant from the chatroom
200
About
A chat room API that features private and public chats with multiple participants