Skip to content

Latest commit

 

History

History
333 lines (260 loc) · 6.24 KB

README.md

File metadata and controls

333 lines (260 loc) · 6.24 KB

Employee-Management

🔗 Topics


📖 About

API for managing employees and for use with some frontend framework.


🛠️ Tools

  • Django
  • Django Signals
  • Django Rest Framework
  • Simple JWT for authentication system
  • Fast
  • Docker
  • Docker Compose
  • Postgresql as database
  • Redis as cache

🗄️ Database


🏷️ User - main fields

  • Id
  • Username
  • Password

🏷️ Department

  • Id
  • Name

🏷️ Employee

  • Id
  • Name
  • Email
  • Department FK
  • Salary
  • Birth date

Department like FK is better than charfield because it has more control


🎥 See the project

This project is divided in employee routes, jwt routes and admin routes


🔗 Routes for frontend



• /token


• /token/refresh


• /employees


• /employees/ID


• /departments


• /departments/ID


• /reports/employees/age


• /reports/employees/salary


🚀 Performance

This project has cache system using Redis, caching views after first access and updating cache when data changes


Local where show load time


View


🛡️ Custom admin system







📖 Project instructions



🎓 How to start

This project use docker for simulate production environment. You can use project without docker, deleting setting.CACHES and replacing postgresql for sqlite in settings.DATABASES


• Create virtual environment and use dependencies

Docker use requirements.txt for install dependencies


python3 -m venv venv
pip install -r requirements.txt
pip freeze > requirements.txt

• Make migrations

docker-compose run web python3 project/manage.py makemigrations
docker-compose run web python3 project/manage.py migrate

• Create admin user

docker-compose run web python3 project/manage.py createsuperuser

• Run project


Use when create or update dependencies

docker-compose up --build

Usually

docker-compose up

Without logs

docker-compose up -d

• Down project

docker-compose down

🎓 How to use



• Get your tokens in /token/





• Access any frontend router sending your access token in header




• Refresh your access token in /token/refresh/ when access token is expired




🔗 Routes

All routes and your main http methods



POST

/token/

Get refresh and access token




POST

/token/refresh/

Refresh your access token




GET | POST

/employees/

GET: List employees

POST: Create employee




GET | PUT | PATCH | DELETE

/employees/[ID]/

GET: See the employee data corresponding to the id parameter

PUT: Update employee data sending all fields

PATCH: Update employee data sending your selected fields

DELETE: delete employee




GET | POST

/departments/

GET: List departments

POST: Create department




GET | PUT | PATCH | DELETE

/departments/[ID]/

GET: See the department data corresponding to the id parameter

PUT: Update department data sending all fields

PATCH: Update department data sending your selected fields

DELETE: delete department




GET

/reports/employees/age/

See age report




GET

/reports/employees/salary/

See salary report



🧪 Tests


Usually

docker-compose run web python3.10 project/manage.py test backend --pattern="*_t.py"

When many changes or one change with a big impact

docker-compose run web python3.10 project/manage.py test backend --pattern="*_t.py" --failfast

❌ End