Mini library backend service with Django
- User role (Student, Librarian)
- Register user
- User login
- Book List
- Borrow book
- Return book
- Renew book due date
- User borrowed history
- Python 3.8+
- Docker
-
clone source code from github
-
go to project directory
cd library-backend-django
-
create your own project env
python3 -m venv env
-
activate your project env
source env/bin/activate
-
go to your project directory and install requirement.txt
pip install -r requirement.txt
-
run docker compose
docker compose up -d
-
migrate all models to database.
python3 manage.py migrate
-
then run the apps.
python3 manage.py runserver
-
create dummy users for testing. default password is
password123
python3 manage.py generate_users
Username Role student1 student librarian1 librarian -
create dummy books for testing
python3 manage.py generate_books
-
run test case.
python3 manage.py test
the output should be like this:
Found 13 test(s). Creating test database for alias 'default'... System check identified no issues (0 silenced). ............. ---------------------------------------------------------------------- Ran 13 tests in 7.528s OK Destroying test database for alias 'default'...
-
run test coverage.
coverage run --source='.' manage.py test . coverage report
the output should be like this:
Found 13 test(s). Creating test database for alias 'default'... System check identified no issues (0 silenced). ............. ---------------------------------------------------------------------- Ran 13 tests in 8.033s OK Destroying test database for alias 'default'... Name Stmts Miss Cover ----------------------------------------------------------- manage.py 12 2 83% src/__init__.py 0 0 100% src/asgi.py 4 4 0% src/book/__init__.py 0 0 100% src/book/admin.py 1 0 100% src/book/apps.py 4 0 100% src/book/factory.py 9 0 100% src/book/migrations/0001_initial.py 5 0 100% src/book/migrations/__init__.py 0 0 100% src/book/models.py 7 0 100% src/book/serializers.py 21 0 100% src/book/tests.py 39 0 100% src/book/views.py 25 0 100% src/borrow/__init__.py 0 0 100% src/borrow/admin.py 1 0 100% src/borrow/apps.py 4 0 100% src/borrow/factory.py 13 0 100% src/borrow/migrations/0001_initial.py 7 0 100% src/borrow/migrations/__init__.py 0 0 100% src/borrow/models.py 14 0 100% src/borrow/serializers.py 47 0 100% src/borrow/tests.py 59 0 100% src/borrow/views.py 45 0 100% src/iam/__init__.py 0 0 100% src/iam/admin.py 1 0 100% src/iam/apps.py 4 0 100% src/iam/factory.py 15 0 100% src/iam/migrations/0001_initial.py 7 0 100% src/iam/migrations/__init__.py 0 0 100% src/iam/models.py 7 0 100% src/iam/permissions.py 12 0 100% src/iam/serializers.py 22 0 100% src/iam/tests.py 48 0 100% src/iam/views.py 38 0 100% src/settings.py 19 0 100% src/urls.py 8 0 100% src/wsgi.py 4 4 0% ----------------------------------------------------------- TOTAL 502 10 98%
You can try API with postman by import the collection and environment file