Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
0b668ac
Set up project with django and install drf
APIYOJENNIFER Oct 23, 2023
3b6e2e4
Create user model
APIYOJENNIFER Oct 24, 2023
e8391bc
Register user model in admin
APIYOJENNIFER Oct 24, 2023
a632804
Create user signup api endpoint
APIYOJENNIFER Oct 24, 2023
b3f0bb2
Move routes inside api urls
APIYOJENNIFER Oct 24, 2023
eefaf64
Hash user password
APIYOJENNIFER Oct 24, 2023
7af683f
Merge pull request #5 from APIYOJENNIFER/feat/post-it-apis
APIYOJENNIFER Oct 26, 2023
04e39de
Re-arrange installed apps
APIYOJENNIFER Oct 24, 2023
86d996e
Create user sign in api
APIYOJENNIFER Oct 26, 2023
c654177
Set up postgresql database
APIYOJENNIFER Oct 27, 2023
3cc4102
Remove custom user model implementation
APIYOJENNIFER Oct 27, 2023
c0e1648
Merge pull request #6 from APIYOJENNIFER/feat/signin-api
ThatcherK Oct 27, 2023
b84744b
Merge pull request #6 from APIYOJENNIFER/feat/signin-api
ThatcherK Oct 27, 2023
33f0d53
Add comma after group app
APIYOJENNIFER Oct 30, 2023
f3cb384
Create broadcast groups
APIYOJENNIFER Oct 30, 2023
57f33c9
Update readme
APIYOJENNIFER Oct 31, 2023
4ea5780
Add lint tools, fix lint errors and warnings
APIYOJENNIFER Oct 31, 2023
9544e42
Add pylintrc file
APIYOJENNIFER Nov 6, 2023
685c9c6
Use key directly for development
APIYOJENNIFER Nov 8, 2023
9199d0e
Update readme with project setup instructions
APIYOJENNIFER Nov 8, 2023
d4a6068
Keep secret key in .env
APIYOJENNIFER Nov 13, 2023
5c4c8cc
Register the Group model
APIYOJENNIFER Nov 13, 2023
6fc3658
Merge pull request #7 from APIYOJENNIFER/feat/group-api
APIYOJENNIFER Nov 14, 2023
33c9433
Configure and setup docker
APIYOJENNIFER Jan 8, 2024
58f228e
Remove mkdir command
APIYOJENNIFER Jan 17, 2024
82e1261
Remove compose file from gitignore, add env_file
APIYOJENNIFER Jan 17, 2024
6df7df6
Remove variables from Dockerfile
APIYOJENNIFER Jan 18, 2024
ecc3e72
Move postgres password to env file
APIYOJENNIFER Jan 18, 2024
f63d100
Update docker-compose.dev file
APIYOJENNIFER Jan 18, 2024
e3129aa
Remove env_file
APIYOJENNIFER Jan 22, 2024
696b43c
Update to python 3.9
APIYOJENNIFER Feb 22, 2024
1bdcf80
Add explicit versions for requirements
APIYOJENNIFER Feb 22, 2024
047278b
Merge pull request #13 from APIYOJENNIFER/feat/docker-setup
APIYOJENNIFER Feb 22, 2024
0f2ec19
Create api to add users to a group
APIYOJENNIFER Nov 2, 2023
61f33a7
Fix lint warnings
APIYOJENNIFER Nov 14, 2023
527a30c
Create api to delete a group
APIYOJENNIFER Nov 14, 2023
f7a155f
Disable too many return statements lint rule
APIYOJENNIFER Nov 15, 2023
5b1a712
Create API to remove a user from a group
APIYOJENNIFER Nov 15, 2023
1636f56
Add all valid users and throw errors after
APIYOJENNIFER Nov 16, 2023
1243b69
Remove group id from path
APIYOJENNIFER Nov 20, 2023
68050ad
Change request method to PATCH
APIYOJENNIFER Nov 20, 2023
91be5f5
Move logic inside group try block
APIYOJENNIFER Nov 20, 2023
119a30a
Allow only group creator to add members
APIYOJENNIFER Nov 20, 2023
db84e4c
Remove group id from delete group url path
APIYOJENNIFER Nov 20, 2023
d7052a3
Move delete group logic inside try block
APIYOJENNIFER Nov 20, 2023
6482a47
Remove group and user id from path
APIYOJENNIFER Nov 20, 2023
0987f38
Move remove user logic inside try block
APIYOJENNIFER Nov 20, 2023
4332ff0
Modify API functions to use class based views
APIYOJENNIFER Nov 21, 2023
d2770aa
Update members list
APIYOJENNIFER Nov 22, 2023
3f8a643
Use one try block
APIYOJENNIFER Nov 22, 2023
de1ba3e
Remove Postit prefix in class name
APIYOJENNIFER Nov 23, 2023
77adf84
Rename path
APIYOJENNIFER Nov 23, 2023
c6de203
Abstract group and permission check
APIYOJENNIFER Nov 24, 2023
a652c52
Add get method to retrieve all groups
APIYOJENNIFER Nov 24, 2023
8759374
Disable unused-argument lint warning
APIYOJENNIFER Nov 24, 2023
979e1ca
Add get method to retrieve a single group
APIYOJENNIFER Nov 24, 2023
c110140
Fix lint warnings
APIYOJENNIFER Nov 24, 2023
5f79876
Return member objects in get method
APIYOJENNIFER Nov 30, 2023
62aa855
Add current user as member
APIYOJENNIFER Nov 30, 2023
7092d76
Fix lint warnings
APIYOJENNIFER Nov 30, 2023
29e8d81
Add migrations to gitignore
APIYOJENNIFER Dec 1, 2023
4cdf553
Use one serializer class
APIYOJENNIFER Jan 23, 2024
08adc75
Remove migration files from gitignore
APIYOJENNIFER Jan 23, 2024
6d16c81
Return user object without password in GET method
APIYOJENNIFER Jan 24, 2024
5e1cc6a
Add password in the user serializer field
APIYOJENNIFER Jan 24, 2024
2eaa4a9
Create a group with an empty members list
APIYOJENNIFER Jan 24, 2024
4598470
Change patch error status code to 304
APIYOJENNIFER Jan 25, 2024
27fb3dc
Custom serialize the members field
APIYOJENNIFER Jan 25, 2024
d6f3b7b
Move members IDs to a variable
APIYOJENNIFER Feb 5, 2024
d971a03
Modify error status code
APIYOJENNIFER Feb 5, 2024
e3673f0
Add pagination to list of groups
APIYOJENNIFER Feb 20, 2024
345445b
Fix arguments-differ pylint warning
APIYOJENNIFER Feb 21, 2024
95d8ff9
Compare using user and creator IDs
APIYOJENNIFER Feb 21, 2024
52fccfa
Remove duplicate members check
APIYOJENNIFER Feb 21, 2024
c155adb
Add member objects in bulk
APIYOJENNIFER Feb 22, 2024
d7b6c39
Remove duplicate check
APIYOJENNIFER Feb 22, 2024
0af1963
Merge pull request #8 from APIYOJENNIFER/feat/group-add-users-api
APIYOJENNIFER Feb 22, 2024
9be1fac
Fix conflicts
APIYOJENNIFER Nov 3, 2023
44c6040
Register message model
APIYOJENNIFER Feb 23, 2024
ba2e0f5
Modify POST method to a class based view
APIYOJENNIFER Feb 23, 2024
0fdbbbc
Fix lint warnings
APIYOJENNIFER Feb 23, 2024
f40ba31
Move message post method to separate view class
APIYOJENNIFER Feb 26, 2024
640d86b
Modify methods in user to class based views
APIYOJENNIFER Feb 27, 2024
80d4b57
Merge pull request #9 from APIYOJENNIFER/feat/post-messages-api
APIYOJENNIFER Feb 27, 2024
d28382b
Create api to add users to a group
APIYOJENNIFER Nov 2, 2023
34a7108
Create API to post messages to group
APIYOJENNIFER Nov 3, 2023
46cd678
Create API to retrieve messages in a group
APIYOJENNIFER Nov 3, 2023
55842ad
Modify get method to class based view
APIYOJENNIFER Feb 27, 2024
f48a7b3
Modify resource to use plural form
APIYOJENNIFER Feb 27, 2024
11e82d6
Modify message url
APIYOJENNIFER Feb 27, 2024
bf592b4
Test signup api
APIYOJENNIFER Feb 27, 2024
30c3c1b
Optimise query
APIYOJENNIFER Feb 29, 2024
df645e7
Add distinct URL patterns for POST and GET
APIYOJENNIFER Mar 1, 2024
5d029fd
Remove conftest file
APIYOJENNIFER Mar 4, 2024
495c4b4
Test user signin api
APIYOJENNIFER Mar 4, 2024
a3b1280
Remove pytest
APIYOJENNIFER Mar 4, 2024
bf05325
Separate test for signup and signin
APIYOJENNIFER Mar 4, 2024
ed3b644
Merge pull request #14 from APIYOJENNIFER/feat/test-signup-api
APIYOJENNIFER Mar 5, 2024
f7b37d2
Create separate detail class
APIYOJENNIFER Mar 18, 2024
dbfd3c6
Merge pull request #10 from APIYOJENNIFER/feat/retrieve-message-api
APIYOJENNIFER Mar 19, 2024
5699b2c
Add API documentation using swagger
APIYOJENNIFER Mar 12, 2024
2675ae3
Modify path name
APIYOJENNIFER Mar 25, 2024
8ef55f8
Merge pull request #16 from APIYOJENNIFER/api-documentation
APIYOJENNIFER Mar 26, 2024
c2fb6a1
Test create group api
APIYOJENNIFER Mar 4, 2024
6df8224
Modify function name for test create group
APIYOJENNIFER Mar 4, 2024
2ea75f9
Restructure test files
APIYOJENNIFER Mar 5, 2024
f18a638
Create conftest file and add reusable test functions
APIYOJENNIFER Mar 5, 2024
ee10814
Move tests for users api to root test folder
APIYOJENNIFER Mar 5, 2024
9397005
Test create group api
APIYOJENNIFER Mar 5, 2024
cb5c640
Fix pylint warnings and errors
APIYOJENNIFER Mar 5, 2024
b81b955
Test GET method for retrieving list of groups
APIYOJENNIFER Mar 5, 2024
29a7e48
Add default ordering to fix pytest pagination warning
APIYOJENNIFER Mar 5, 2024
5f4d329
Create test user and group
APIYOJENNIFER Mar 7, 2024
549eedf
Test successful group deletion
APIYOJENNIFER Mar 7, 2024
79f8363
Test for permission denied when deleting group
APIYOJENNIFER Mar 7, 2024
9227365
Test deletion if group is not existent
APIYOJENNIFER Mar 7, 2024
45b6b37
Rename test function name
APIYOJENNIFER Mar 7, 2024
f13416a
Test length of the list returned
APIYOJENNIFER Mar 7, 2024
4d67e63
Add coverage package for checking code coverage
APIYOJENNIFER Mar 11, 2024
eb9144c
Test successful members addition to group
APIYOJENNIFER Mar 11, 2024
5316c4d
Test for permission denied when adding new members to group
APIYOJENNIFER Mar 11, 2024
4cbb96e
Test for non existent user(s) when adding new members to group
APIYOJENNIFER Mar 11, 2024
a999349
Test addition of new members if group is not existent
APIYOJENNIFER Mar 11, 2024
9e8e5cf
Test for retrieval of a single group
APIYOJENNIFER Mar 11, 2024
647da0e
Test successful removal of a user(s) from group
APIYOJENNIFER Mar 12, 2024
7205d20
Test if only group creator can remove user(s) from group
APIYOJENNIFER Mar 12, 2024
ed752c2
Test if group creator cannot be removed from group
APIYOJENNIFER Mar 12, 2024
ebc80be
Add github workflow for linting and testing
APIYOJENNIFER Mar 13, 2024
4a2a28f
Fix indentation error
APIYOJENNIFER Mar 13, 2024
7aeb53d
Set working directory
APIYOJENNIFER Mar 13, 2024
6628d6e
Add flake8 configuration file
APIYOJENNIFER Mar 13, 2024
9206dc7
Ignore migrations files when running pylint
APIYOJENNIFER Mar 14, 2024
e7c799d
Remove working-directory
APIYOJENNIFER Mar 14, 2024
d6c316e
Run flake8 on user in a separate command
APIYOJENNIFER Mar 14, 2024
51b416c
Add dummy secret key
APIYOJENNIFER Mar 14, 2024
ce31fc0
Add other environment variables
APIYOJENNIFER Mar 14, 2024
75f6c94
Add postgres service to workflow
APIYOJENNIFER Mar 18, 2024
315c7c1
Move postgres password to github secrets
APIYOJENNIFER Mar 18, 2024
02b37eb
Merge pull request #15 from APIYOJENNIFER/feat/test-groups-api
APIYOJENNIFER Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .coverage
Binary file not shown.
15 changes: 15 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[flake8]
extend-ignore = E203
include =
user/*.py,
group/*.py
exclude =
.git,
__pycache__,
docs/source/conf.py,
old,
build,
dist,
user/migrations/*,
group/migrations/*
max-complexity = 10
54 changes: 54 additions & 0 deletions .github/workflows/run_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Lint, Test, and Generate Coverage report

on:
pull_request:
branches:
- develop
- main

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
version: ["3.9"]
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint with pylint and flake8
run: |
pylint --ignore=migrations group
pylint --ignore=migrations user
flake8 group
flake8 user
- name: Test with pytest
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
run: coverage run -m pytest -v -s
- name: Generate coverage report
run: coverage report -m
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__/
.env
env/
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.9

WORKDIR /postit

COPY requirements.txt .

RUN pip install -r requirements.txt

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
12 changes: 12 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "*"

[dev-packages]

[requires]
python_version = "3.7"
54 changes: 54 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@
# post-it-backend

PostIt ​is a simple application that allows friends and colleagues to create groups for notifications. This way one person can post notifications to everyone by sending a message once. The application allows people to create accounts, create groups add registered users to the groups, and then send messages to these groups whenever they want.

# Project Setup

1. After cloning the repo, set up a virtual environment
`python3 -m venv .venv`

2. Activate the virtual environment
`. .venv/bin/activate`

3. Install the dependencies in requirements.txt
`pip install -r requirements.txt`

4. Configure PostgresSQL
i) Open the PostgresSQL command line interface
`psql postgres`

ii) From your terminal, create a database
`CREATE DATABASE postit;`

iii) Create a user, feel free to replace the username and password
`CREATE USER admin WITH PASSWORD 'password';`

iv) Modify the connection parameters for the created user
`ALTER ROLE admin SET client_encoding TO 'utf8';`
`ALTER ROLE admin SET default_transaction_isolation TO 'read committed';`
`ALTER ROLE admin SET timezone TO 'UTC';`

v) Grant the user access rights to the database
`GRANT ALL PRIVILEGES ON DATABASE postit TO admin;`

vi) Exit the postgres command line
`\q`

5. Create a .env file at the root of the project and set the database configurations there
`SECRET_KEY=your_secret_key`
`DB_NAME=postit`
`DB_USER=admin`
`DB_PASSWORD=your_password`
`DB_HOST=localhost`
`DB_PORT=5432`

6. Make migrations
`python manage.py makemigrations`

7. Migrate to create tables
`python manage.py migrate`

8. Create a superuser
`python manage.py createsuperuser`

9. Start the server
`python manage.py runserver`
Empty file added api/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions api/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions api/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ApiConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api'
Empty file added api/migrations/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions api/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
6 changes: 6 additions & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.urls import path, include

urlpatterns = [
path('users/', include('user.urls')),
path('groups/', include('group.urls')),
]
3 changes: 3 additions & 0 deletions api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
26 changes: 26 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
db:
image: postgres
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
env_file:
- .env
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/postit
ports:
- "8000:8000"
depends_on:
- db
environment:
- SECRET_KEY=${SECRET_KEY}
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_HOST=${DB_HOST}
- DB_PORT=${DB_PORT}
env_file:
- .env
tty: true
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
db:
image: postgres
environment:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/postit
ports:
- "8000:8000"
depends_on:
- db
environment:
- SECRET_KEY=${SECRET_KEY}
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- DB_HOST=${DB_HOST}
- DB_PORT=${DB_PORT}
tty: true
Empty file added group/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions group/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Register the Group model to see it in Django admin"""
from django.contrib import admin
from .models import Group, Message

admin.site.register(Group)
admin.site.register(Message)
8 changes: 8 additions & 0 deletions group/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Apps module"""
from django.apps import AppConfig


class GroupConfig(AppConfig):
"""App class configuration"""
default_auto_field = 'django.db.models.BigAutoField'
name = 'group'
26 changes: 26 additions & 0 deletions group/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.6 on 2023-10-30 08:26

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Group',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True)),
('creator', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='groups_created', to=settings.AUTH_USER_MODEL)),
('members', models.ManyToManyField(related_name='groups_joined', to=settings.AUTH_USER_MODEL)),
],
),
]
26 changes: 26 additions & 0 deletions group/migrations/0002_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.6 on 2023-11-02 09:41

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('group', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Message',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('post', models.TextField()),
('created_at', models.DateTimeField(auto_now_add=True)),
('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='messages', to='group.group')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='messages_authored', to=settings.AUTH_USER_MODEL)),
],
),
]
Empty file added group/migrations/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions group/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Models module"""
from django.db import models
from django.contrib.auth.models import User


class Group(models.Model):
"""Group class model"""
name = models.CharField(max_length=255, unique=True)
members = models.ManyToManyField(User, related_name='groups_joined')
creator = models.ForeignKey(User, on_delete=models.CASCADE,
related_name='groups_created')

def __str__(self) -> str:
return str(self.name)


class Message(models.Model):
"""A model to define the structure of messages"""
post = models.TextField()
group = models.ForeignKey(Group, on_delete=models.CASCADE,
related_name='messages')
user = models.ForeignKey(User, on_delete=models.CASCADE,
related_name='messages_authored')
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f'{self.user.username}: {self.post}'
Loading