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.
Follow the instructions on the branch docker to build the containers to run this project.
git clone https://github.com/Eadwulf/chat-room-apicd chat-room-apipipenv install && pipenv shellThe project uses a PostgreSQL database. Configured as follows
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': env('DATABASE_NAME'),
'HOST': env('DATABASE_HOST'),
'PORT': env('DATABASE_PORT'),
'USER': env('DATABASE_USER'),
'PASSWORD': env('DATABASE_PASSWORD'),
},
}psql -U postgres -d postgresCREATE DATABASE <database_name>;CREATE USER <username> WITH ENCRYPTED PASSWORD '<password>';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 ALL PRIVILEGES ON DATABASE <database_name> TO <username>;\qIn the root directory (chat-room-api/), create the .env file and add to it the following
DEBUG=<boolean_value>
SECRET_KEY=<your_django_api_key>
DATABASE_NAME=<your_database_name>
DATABASE_HOST=<your_database_host>
DATABASE_PORT=<your_database_port>
DATABASE_USER=<your_database_user>
DATABASE_PASSWORD=<your_database_password>python manage.py migrateI have created a total of 34 tests, that test the app api, chatrooms, and accounts.
python manage.py testIt 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.430s
OK
Destroying test database for alias 'default'...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.
The tests in the chatrooms app perform CRUD operations on Chatroom and Message models.
The test in the account app performs CRUD operations in the CustomUser model.
The project consists of a total of ten (10) endpoints, such endpoints provide functionalities for users, chatrooms, messages and more.
| 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 |
| HTTP METHOD | REQUIRED DATA | ACTION | STATUS CODE |
|---|---|---|---|
| GET | Retrieves the list of users | 200 | |
| POST | username, password | Creates a user | 201 |
| 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 |
| 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 |
| HTTP METHOD | REQUIRED DATA | ACTION | STATUS CODE |
|---|---|---|---|
| GET | Retrieves the list of messages | 200 | |
| POST | chatroom_id, sender_id, body | Creates a message | 201 |
| 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 |
| HTTP METHOD | REQUIRED DATA | ACTION | STATUS CODE |
|---|---|---|---|
| GET | Retrieves the list of chatrooms | 200 | |
| POST | name | Creates a chatroom | 201 |
| 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 |
| 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 |
| 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 |
| 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 |