From acc86cf759e2d35c1f5ae4fc796e26640bb45e78 Mon Sep 17 00:00:00 2001 From: Arafat Olayiwola Date: Mon, 1 Jul 2024 21:06:44 +0100 Subject: [PATCH 1/5] add makefile hosting commands --- Makefile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0f466eb --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +install-with-cache: + pip3 install -r requirements.txt + +install-with-no-cache: + pip3 install -r requirements.txt --no-cache + +runserver: + python3 manage.py runserver + +tests: + pytest + +makemigrations: + python3 manage.py makemigrations + +migrate: + python3 manage.py migrate + +createsuperuser: + python3 manage.py createsuperuser --email=admin@gmail.com From 7cf0de68ff10eb8695095d06810fd4ce4919bff4 Mon Sep 17 00:00:00 2001 From: Arafat Olayiwola Date: Mon, 1 Jul 2024 21:15:10 +0100 Subject: [PATCH 2/5] install requirements for the setup --- requirements.txt | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..67359f0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,39 @@ +django +djangorestframework==3.15.1 +Pillow==10.3.0 +pytest-django==4.8.0 +django-redis==5.4.0 + +whitenoise # https://github.com/evansd/whitenoise +redis # https://github.com/redis/redis-py +hiredis # https://github.com/redis/hiredis-py +celery # pyup: < 6.0 # https://github.com/celery/celery +django-celery-beat # https://github.com/celery/django-celery-beat +flower # https://github.com/mher/flower +# Django +# ------------------------------------------------------------------------------ +django-environ # https://github.com/joke2k/django-environ +django-redis # https://github.com/jazzband/django-redis +# Django REST Framework +django-cors-headers # https://github.com/adamchainz/django-cors-headers +pyotp # https://github.com/pyotp/pyotp +pydantic + +# Code quality +# ------------------------------------------------------------------------------ +flake8 # https://github.com/PyCQA/flake8 +flake8-isort # https://github.com/gforcada/flake8-isort +coverage # https://github.com/nedbat/coveragepy +black # https://github.com/psf/black +djlint # https://github.com/Riverside-Healthcare/djLint +pylint-django # https://github.com/PyCQA/pylint-django +pylint-celery # https://github.com/PyCQA/pylint-celery +pre-commit # https://github.com/pre-commit/pre-commit + + +gunicorn # https://github.com/benoitc/gunicorn + +# Monitoring +# ----------------------------------------------------------------------------- +sentry-sdk[django] # sentry-sdk[django] +six \ No newline at end of file From aae0b83109335cd11a3b56f80205ce545d562b15 Mon Sep 17 00:00:00 2001 From: Arafat Olayiwola Date: Mon, 1 Jul 2024 21:26:47 +0100 Subject: [PATCH 3/5] fix README --- Makefile | 5 +--- README.md | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 88 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 0f466eb..46f2e67 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,6 @@ -install-with-cache: +install: pip3 install -r requirements.txt -install-with-no-cache: - pip3 install -r requirements.txt --no-cache - runserver: python3 manage.py runserver diff --git a/README.md b/README.md index 4e82887..d2c80d2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,87 @@ -# drugstoc_inventory -Drugstoc BE Interview Technical Assessment +# Drugstoc Inventory Management APIs Assessment + +A simple Django backend for a inventory mananagement that manages users, products, orders and reports. It supports basic CRUD (Create, Read, Update, Delete) operations for all services. + +## Features + +- Endpoints for managing users authentication and authorization with RBAC +- Endpoints for products where only admin can make full CRUD operations +- Basic error handling +- Normal can create orders with list of products +- Reporting endpoints for sales and products stock management + +## Project Structure + +drugstoc_inventory/ +│ ├── init.py +│ ├── main.py +│ ├── crud/ +│ │ ├── init.py +│ │ ├── author.py +│ │ └── post.py +│ ├── models/ +│ │ ├── init.py +│ │ ├── author.py +│ │ └── post.py +│ ├── schemas/ +│ │ ├── init.py +│ │ ├── author.py +│ │ └── post.py +│ ├── db/ +│ │ ├── init.py +│ │ └── database.py +│ └── api/ +│ ├── init.py +│ ├── author.py +│ └── post.py +└── README.md +└── run_tests.sh +└── requirements.txt + + +## Getting Started + +### Prerequisites + +- Python 3.7+ install +- Make install + +### Installation + +1. **Clone the repository:** + + ```bash + git clone https://github.com/Horlawhyumy-dev/drugstoc_inventory.git + cd drugstoc_inventory + + +2. **Create Virtual Environment and Install Requirements** + ```bash + python3 -m venv env + source env/bin/activate # On Windows use `env\Scripts\activate` + make install + ``` + +3. **Run Migrations** + ```bash + make migrate + ``` + +4. **Run and Excute Tests Script** + + ``` + chmod +x run_tests.sh + ./run_tests.sh + ``` + +5. **Start Server** + + ```bash + make runserver + ``` + +## Internal API Endpoints Documentation + + ``` + ./api_doc.txt file + ``` \ No newline at end of file From c7f6ef1b6a5f25c08e1be2754765b3f8b4d9b8f8 Mon Sep 17 00:00:00 2001 From: Arafat Olayiwola Date: Mon, 1 Jul 2024 21:45:44 +0100 Subject: [PATCH 4/5] add test script and api doc file --- api_doc.txt | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++ run_tests.sh | 4 ++ 2 files changed, 105 insertions(+) create mode 100644 api_doc.txt create mode 100644 run_tests.sh diff --git a/api_doc.txt b/api_doc.txt new file mode 100644 index 0000000..4789ef5 --- /dev/null +++ b/api_doc.txt @@ -0,0 +1,101 @@ +API Descriptions: + +This application provides a RESTful API for Drugstoc Inventory Management. + +Endpoints: + +1. POST /authors/ + - Description: Create a new author + - Request Body: AuthorCreate schema + - Response: Author schema + +2. GET /authors/ + - Description: Retrieve a list of authors + - Query Parameters: + - skip (int, optional): Number of authors to skip (default: 0) + - limit (int, optional): Maximum number of authors to return (default: 10) + - Response: List of Author schemas + +3. GET /authors/{author_id} + - Description: Retrieve an author by ID + - Path Parameters: + - author_id (int): The ID of the author to retrieve + - Response: Author schema + - Exceptions: + - 404 Not Found: If the author is not found + +4. PATCH /authors/{author_id} + - Description: Update an existing author + - Path Parameters: + - author_id (int): The ID of the author to update + - Request Body: AuthorUpdate schema + - Response: Author schema + - Exceptions: + - 404 Not Found: If the author is not found + +5. DELETE /authors/{author_id} + - Description: Delete an author + - Path Parameters: + - author_id (int): The ID of the author to delete + - Response: 204 No Content + - Exceptions: + - 404 Not Found: If the author is not found + +Schemas: + +1. Author + - Properties: + - id (int): The unique identifier of the author + - name (str): The name of the author + +2. AuthorCreate + - Properties: + - name (str): The name of the author to create + +3. AuthorUpdate + - Properties: + - name (str): The updated name of the author + + +Post Endpoints: + +1. GET /posts/?author_id={author_id} + - Description: Retrieve a list of all posts for a specific author + - Query Parameters: + - author_id (int): The ID of the author to filter the posts by + - Response: List of Post schemas + +2. GET /posts/{post_id}/?author_id={author_id} + - Description: Retrieve a specific post by ID for a given author + - Path Parameters: + - post_id (int): The ID of the post to retrieve + - author_id (int): The ID of the author to filter the post by + - Response: Post schema + - Exceptions: + - 404 Not Found: If the post is not found for the given author + +3. POST /posts/?author_id={author_id} + - Description: Create a new post by a specific author + - Query Parameters: + - author_id (int): The ID of the author creating the post + - Request Body: PostCreate schema + - Response: Post schema + +4. PUT /posts/{post_id}/?author_id={author_id} + - Description: Update an existing post for a specific author + - Path Parameters: + - post_id (int): The ID of the post to update + - author_id (int): The ID of the author updating the post + - Request Body: PostCreate schema + - Response: Post schema + - Exceptions: + - 404 Not Found: If the post is not found for the given author + +5. DELETE /posts/{post_id}/?author_id={author_id} + - Description: Delete a post by a specific author + - Path Parameters: + - post_id (int): The ID of the post to delete + - author_id (int): The ID of the author deleting the post + - Response: 204 No Content + - Exceptions: + - 404 Not Found: If the post is not found for the given author \ No newline at end of file diff --git a/run_tests.sh b/run_tests.sh new file mode 100644 index 0000000..51cdc94 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,4 @@ +_#!/bin/bash +export PYTHONPATH=./ +rm -rf test.db +pytest \ No newline at end of file From 7b7e0bddc83fbf919283070104ca0049c10c970c Mon Sep 17 00:00:00 2001 From: Arafat Olayiwola Date: Mon, 1 Jul 2024 21:48:32 +0100 Subject: [PATCH 5/5] add env sample and remove virtual env folder --- .gitignore | 2 +- env_sample.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 env_sample.txt diff --git a/.gitignore b/.gitignore index 4fb3db3..3524850 100644 --- a/.gitignore +++ b/.gitignore @@ -296,7 +296,7 @@ celerybeat.pid .env .venv env/ -venv/ +venv ENV/ env.bak/ venv.bak/ diff --git a/env_sample.txt b/env_sample.txt new file mode 100644 index 0000000..2d8d9b2 --- /dev/null +++ b/env_sample.txt @@ -0,0 +1,2 @@ +SECRET_KEY= +DEBUG= \ No newline at end of file