Skip to content

Commit bcc63a7

Browse files
authored
Merge pull request #18 from Real-Dev-Squad/develop
Dev to Main Sync
2 parents 3760f53 + 0cfedac commit bcc63a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2933
-2
lines changed

.coveragerc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[coverage:run]
2+
# This section tells coverage to ignore certain files or directories
3+
omit =
4+
*/__init__.py
5+
todo_project/wsgi.py
6+
manage.py
7+
*/tests/*

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ENV='DEVELOPMENT'
2+
SECRET_KEY='unique-secret'
3+
ALLOWED_HOSTS='localhost,127.0.0.1'
4+
MONGODB_URI='mongodb://localhost:27017'
5+
DB_NAME='todo-app'

.github/workflows/test.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Tests
2+
on:
3+
pull_request:
4+
branches:
5+
- "**"
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
services:
11+
db:
12+
image: mongo:latest
13+
ports:
14+
- 27017:27017
15+
16+
env:
17+
MONGODB_URI: mongodb://db:27017
18+
DB_NAME: todo-app
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v3
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.11.*'
28+
29+
- name: Install dependencies
30+
run: |
31+
python3.11 -m pip install -r requirements.txt
32+
33+
- name: Lint check
34+
run: |
35+
ruff check
36+
37+
- name: Run tests
38+
run: |
39+
python3.11 manage.py test

.gitignore

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
__pycache__
2+
*.py[cod]
3+
*$py.class
4+
5+
*.so
6+
7+
.Python
8+
build/
9+
develop-eggs/
10+
dist/
11+
downloads/
12+
eggs/
13+
.eggs/
14+
lib/
15+
lib64/
16+
parts/
17+
sdist/
18+
var/
19+
wheels/
20+
share/python-wheels/
21+
*.egg-info/
22+
.installed.cfg
23+
*.egg
24+
MANIFEST
25+
26+
*.manifest
27+
*.spec
28+
29+
pip-log.txt
30+
pip-delete-this-directory.txt
31+
32+
htmlcov/
33+
.tox/
34+
.nox/
35+
.coverage
36+
.coverage.*
37+
.cache
38+
nosetests.xml
39+
coverage.xml
40+
*.cover
41+
*.py,cover
42+
.hypothesis/
43+
.pytest_cache/
44+
cover/
45+
46+
*.mo
47+
*.pot
48+
49+
*.log
50+
local_settings.py
51+
db.sqlite3
52+
db.sqlite3-journal
53+
54+
instance/
55+
.webassets-cache
56+
57+
.scrapy
58+
59+
docs/_build/
60+
61+
.pybuilder/
62+
target/
63+
64+
.ipynb_checkpoints
65+
66+
profile_default/
67+
ipython_config.py
68+
69+
.pdm.toml
70+
.pdm-python
71+
.pdm-build/
72+
73+
__pypackages__/
74+
75+
celerybeat-schedule
76+
celerybeat.pid
77+
78+
*.sage.py
79+
80+
.env
81+
.venv
82+
env/
83+
venv/
84+
ENV/
85+
env.bak/
86+
venv.bak/
87+
88+
.spyderproject
89+
.spyproject
90+
91+
.ropeproject
92+
93+
/site
94+
95+
.mypy_cache/
96+
.dmypy.json
97+
dmypy.json
98+
99+
.pyre/
100+
101+
.pytype/
102+
103+
cython_debug/
104+
105+
.ruff_cache
106+
mongo_data
107+
logs

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11.5

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.12-slim-bookworm
3+
4+
# Set environment variables
5+
ENV PYTHONUNBUFFERED 1
6+
7+
# Set the working directory in the container
8+
WORKDIR /app
9+
10+
# Copy the requirements file into the container
11+
COPY requirements.txt /app/
12+
13+
# Install any needed packages specified in requirements.txt
14+
RUN pip install -r requirements.txt
15+
16+
# Copy the rest of the application code into the container
17+
COPY . /app/

README.md

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,96 @@
1-
# This is for backned service
2-
A template to create all public facing sites
1+
# TODO Backend
2+
3+
## Local development setup
4+
1. Install pyenv
5+
- For Mac/Linux - https://github.com/pyenv/pyenv?tab=readme-ov-file#installation
6+
- For Windows - https://github.com/pyenv-win/pyenv-win/blob/master/docs/installation.md#chocolatey
7+
2. Install the configured python version (3.12.7) using pyenv by running the command
8+
- For Mac/Linux
9+
```
10+
pyenv install
11+
```
12+
- For Windows
13+
```
14+
pyenv install 3.11.5
15+
```
16+
3. Create virtual environment by running the command
17+
- For Mac/Linux
18+
```
19+
pyenv virtualenv 3.11.5 venv
20+
```
21+
- For Windows
22+
```
23+
python -m pip install virtualenv
24+
python -m virtualenv venv
25+
```
26+
4. Activate the virtual environment by running the command
27+
- For Mac/Linux
28+
```
29+
pyenv activate venv
30+
```
31+
- For Windows
32+
```
33+
.\venv\Scripts\activate
34+
```
35+
5. Install the project dependencies by running the command
36+
```
37+
python -m pip install -r requirements.txt
38+
```
39+
6. Create a `.env` file in the root directory, and copy the content from the `.env.example` file to it
40+
7. Install [docker](https://docs.docker.com/get-docker/) and [docker compose](https://docs.docker.com/compose/install/)
41+
8. Start MongoDB using docker
42+
```
43+
docker-compose up -d db
44+
```
45+
9. Start the development server by running the command
46+
```
47+
python manage.py runserver
48+
```
49+
10. Go to http://127.0.0.1:8000/v1/health API to make sure the server it up. You should see this response
50+
```
51+
{
52+
"status": "UP",
53+
"components": {
54+
"db": {
55+
"status": "UP"
56+
}
57+
}
58+
}
59+
```
60+
61+
## To simply try out the app
62+
1. Install [docker](https://docs.docker.com/get-docker/) and [docker compose](https://docs.docker.com/compose/install/)
63+
2. Start Django application and MongoDB using docker
64+
```
65+
docker-compose up -d
66+
```
67+
3. Go to http://127.0.0.1:8000/v1/health API to make sure the server it up. You should see this response
68+
```
69+
{
70+
"status": "UP"
71+
}
72+
```
73+
4. On making changes to code and saving, live reload will work in this case as well
74+
75+
## Command reference
76+
1. To run the tests, run the following command
77+
```
78+
python manage.py test
79+
```
80+
2. To check test coverage, run the following command
81+
```
82+
coverage run --source='.' manage.py test
83+
coverage report
84+
```
85+
3. To run the formatter
86+
```
87+
ruff format
88+
```
89+
4. To run lint check
90+
```
91+
ruff check
92+
```
93+
5. To fix lint issues
94+
```
95+
ruff check --fix
96+
```

docker-compose.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: "3"
2+
3+
services:
4+
django-app:
5+
build: .
6+
container_name: todo-django-app
7+
command: python manage.py runserver 0.0.0.0:8000
8+
environment:
9+
MONGODB_URI: mongodb://db:27017
10+
DB_NAME: todo-app
11+
volumes:
12+
- .:/app
13+
ports:
14+
- "8000:8000"
15+
depends_on:
16+
- db
17+
18+
db:
19+
image: mongo:latest
20+
container_name: todo-mongo
21+
ports:
22+
- "27017:27017"
23+
volumes:
24+
- ./mongo_data:/data/db
25+
healthcheck:
26+
test: ["CMD", "mongosh", "--eval", "'db.runCommand({ping:1})'"]
27+
interval: 10s
28+
timeout: 5s
29+
retries: 5
30+
start_period: 15s
31+
32+
#to enable replica set, requirement for enabling transactions
33+
command: >
34+
sh -c "
35+
mongod --replSet rs0 --bind_ip_all --logpath /var/log/mongodb.log --logappend &
36+
sleep 5 &&
37+
mongosh --eval 'try { rs.initiate() } catch(e) { print(e) }' &&
38+
tail -f /var/log/mongodb.log
39+
"

manage.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
4+
import sys
5+
6+
from todo_project.settings.configure import configure_settings_module
7+
8+
9+
def main():
10+
"""Run administrative tasks."""
11+
configure_settings_module()
12+
13+
try:
14+
from django.core.management import execute_from_command_line
15+
except ImportError as exc:
16+
raise ImportError(
17+
"Couldn't import Django. Are you sure it's installed and "
18+
"available on your PYTHONPATH environment variable? Did you "
19+
"forget to activate a virtual environment?"
20+
) from exc
21+
execute_from_command_line(sys.argv)
22+
23+
24+
if __name__ == "__main__":
25+
main()

0 commit comments

Comments
 (0)