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
Before running the application, you may install the project requirements using pip
:
pip install -r requirements.txt
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.
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!
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!
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!
App supports REST. You can access the following URLs:
/api/department/
for managing departments/api/employee/
for managing employees
-
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 departmentdescription
- the department's description
- The created department will be returned to you if one has been created successfully.
- Specify the next data:
-
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 departmentdescription
- 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.
- Specify the next data:
-
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 departmentdescription
(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.
- Specify the next data:
-
Send a DELETE request to
/api/department/<dep_id>
to DELETE the department with id<dep_id>
.
-
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 idborn-on
(optional) - employees born on thedd/mm/yyyy
dateborn-from
(optional) - employees born after or on thedd/mm/yyyy
dateborn-to
(optional) - employees born before or on thedd/mm/yyyy
date
- Specify the next filters:
-
Send a POST request to
/api/employee/
to CREATE an employee.- Specify the next data:
name
- the name of the employeedepartment_id
- the id of the department of the employeejob
- the job of the employeebirth_date
- the birth_date of the employee indd/mm/yyyy
formatsalary
- the salary of the employee
- The created employee will be returned to you if one has been created successfully.
- Specify the next data:
-
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 employeedepartment_id
- the id of the department of the employeejob
- the job of the employeebirth_date
- the birth_date of the employee indd/mm/yyyy
formatsalary
- 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.
- Specify the next data:
-
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 employeedepartment_id
(optional) - the id of the department of the employeejob
(optional) - the job of the employeebirth_date
(optional) - the birth_date of the employee indd/mm/yyyy
formatsalary
(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.
- Specify the next data:
-
Send a DELETE request to
/api/employee/<emp_id>
to DELETE the employee with id<emp_id>
.
The index page of the app is located in the root of the host.
- 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
- 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