Skip to content

A simple web application for managing departments and employees.

License

Notifications You must be signed in to change notification settings

leirimnad/EPAMPython

Repository files navigation

EPAM Python Project

Coverage Status Build Status

Department managing app

A simple web application for managing departments and employees.

Description

The web application can:

  • display a list of departments
  • display the average salary (calculated automatically) for each department
  • display a list of employees in the departments
  • display the salary for each employee
  • search for employees born on a certain date or in the period between dates
  • change (add / edit / delete) the above data

Software requirements are stated in the SRS.md file

Running the app

Installing requirements

Before running the application, you may install the project requirements using pip:

pip install -r requirements.txt

Database configuration

For the application to run, the MySQL database should be set up.

Database credentials are read by the application from the environmental variables.

Before starting an app (manually or using Gunicorn), please set the next environmental variables:

  • MYSQL_DB_USER: MySQL user

  • MYSQL_DB_PASSWORD: MySQL password

  • MYSQL_DB_HOST: MySQL host (and port, separated by :)

  • MYSQL_DB_DATABASE: MySQL database name

The simplest way to specify the environmental variables is to insert the following before the bash commands:

MYSQL_DB_USER="Boss" MYSQL_DB_PASSWORD="MyPassword" MYSQL_DB_HOST="localhost" MYSQL_DB_DATABASE="my_database"

Another way to specify the environmental variables is to write them to .env file in the project root directory. See the .env.example file for an example.

Populating the database

To populate the database with the small amount of test data, run populate.py from help module.

python -m department_app.help.populate

Don't forget about the environmental variables!

Starting the app without using the WSGI

If you don't want to use WSGI, you can start an app by running:

python -m department_app.app

Don't forget about the environmental variables!

Starting the app using the WSGI

If you want to start an app using Gunicorn, try the following:

gunicorn department_app.app:app

Specify the amount of workers and the host as parameters:

-w 4 for using 4 workers

-b 127.0.0.1:7772 for starting an app on 127.0.0.1:7772

Still, don't forget about the environmental variables!

Using app's API

App supports REST. You can access the following URLs:

  • /api/department/ for managing departments
  • /api/employee/ for managing employees

Managing departments

  • Send a GET request to /api/department/ to GET the list of all the departments

  • Send a POST request to /api/department/ to CREATE a department.

    • Specify the next data:
      • name - the name of the department
      • description - the department's description
    • The created department will be returned to you if one has been created successfully.
  • Send a POST request to /api/department/<dep_id> to FULLY UPDATE the department with id <dep_id>.

    • Specify the next data:
      • name - the new name of the department
      • description - the department's new description
    • If any of the fields is not specified, an error will be returned
    • The updated department will be returned to you if one has been updated successfully.
  • Send a PATCH request to /api/department/<dep_id> to UPDATE SOME FIELDS of the department with id <dep_id>.

    • Specify the next data:
      • name (optional) - the new name of the department
      • description (optional) - the department's new description
    • If any of the fields is not specified, the corresponding field of the department will not be updated
    • The updated department will be returned to you if one has been updated successfully.
  • Send a DELETE request to /api/department/<dep_id> to DELETE the department with id <dep_id>.

Managing employees

  • Send a GET request to /api/employee/ to GET the list of all the employees

  • Send a GET request to /api/employee/ with parameters to GET the filtered list of all the employees

    • Specify the next filters:
      • department (optional) - employees' department id
      • born-on (optional) - employees born on the dd/mm/yyyy date
      • born-from (optional) - employees born after or on the dd/mm/yyyy date
      • born-to (optional) - employees born before or on the dd/mm/yyyy date
  • Send a POST request to /api/employee/ to CREATE an employee.

    • Specify the next data:
      • name - the name of the employee
      • department_id - the id of the department of the employee
      • job - the job of the employee
      • birth_date - the birth_date of the employee in dd/mm/yyyy format
      • salary - the salary of the employee
    • The created employee will be returned to you if one has been created successfully.
  • Send a POST request to /api/employee/<emp_id> to FULLY UPDATE the employee with id <emp_id>.

    • Specify the next data:
      • name - the name of the employee
      • department_id - the id of the department of the employee
      • job - the job of the employee
      • birth_date - the birth_date of the employee in dd/mm/yyyy format
      • salary - the salary of the employee
    • If any of the fields is not specified, an error will be returned
    • The updated employee will be returned to you if one has been updated successfully.
  • Send a PATCH request to /api/employee/<emp_id> to UPDATE SOME FIELDS of the employee with id <emp_id>.

    • Specify the next data:
      • name (optional) - the name of the employee
      • department_id (optional) - the id of the department of the employee
      • job (optional) - the job of the employee
      • birth_date (optional) - the birth_date of the employee in dd/mm/yyyy format
      • salary (optional) - the salary of the employee
    • If any of the fields is not specified, the corresponding field of the department will not be updated
    • The updated employee will be returned to you if one has been updated successfully.
  • Send a DELETE request to /api/employee/<emp_id> to DELETE the employee with id <emp_id>.

Using the web app

The index page of the app is located in the root of the host.

Departments

  • To view the departments, go to /department/
  • To create a department, go to /department/add
  • To edit a department, go to /department/<dep_id>/edit
  • To delete a department, go to /department/<dep_id>/delete

Employees

  • To view the employees, go to /employee/
  • To view the filtered list of employees, go to /employee/ and click "Filter"
  • To create an employee, go to /employee/add
  • To edit an employee, go to /employee/<emp_id>/edit
  • To delete an employee, go to /employee/<emp_id>/delete