API
API
Main.py
create_employee(employee, db=Depends(get_db))
async
Create a new employee.
Parameters:
employee (EmployeeCreate):
The employee data to create.db (Session, optional):
Database session provided by dependency injection.
Returns:
- Employee:
The newly created employee's details.
Source code in myapp/api/main.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
delete_employee(employee_id, db=Depends(get_db))
async
Delete an employee by their unique ID.
Parameters:
employee_id (int):
The unique identifier of the employee to delete.db (Session, optional):
Database session provided by dependency injection.
Returns:
- dict:
A message confirming successful deletion.
Raises:
- `HTTPException:` If the employee is not found, raises a 404 error.
Source code in myapp/api/main.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
get_employee(employee_id, db=Depends(get_db))
async
Retrieve an employee by their unique ID.
Parameters:
employee_id (int):
The unique identifier of the employee.db (Session, optional):
Database session provided by dependency injection.
Returns:
- Employee:
The employee's details.
Raises:
- `HTTPException:` If the employee is not found, raises a 404 error.
Source code in myapp/api/main.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
update_employee(employee_id, updated_employee, db=Depends(get_db))
async
Update an existing employee's details.
Parameters:
employee_id (int):
The unique identifier of the employee to update.updated_employee (EmployeeCreate):
The new employee data.db (Session, optional):
Database session provided by dependency injection.
Returns:
- Employee:
The updated employee's details.
Raises:
- `HTTPException:` If the employee is not found, raises a 404 error.
Source code in myapp/api/main.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
Models.py
Database Models for the ETL Process.
This module defines the database models using SQLAlchemy for employees, customers, and products.
Modules:
Name | Description |
---|---|
- sqlalchemy |
For ORM and database schema definition. |
- pydantic |
For data validation (not used in these models). |
CustomerDB
Bases: Base
Represents a Customer in the database.
Attributes:
customer_id (int):
The unique identifier for the customer (auto-incremented).customer_name (str):
The name of the customer.address (str):
The address of the customer.city (str):
The city where the customer resides.zip_code (str):
The customer's postal code.
Source code in myapp/api/Database/models.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
EmployeeDB
Bases: Base
Represents an Employee in the database.
Attributes:
employee_id (int):
The unique identifier for the employee (auto-incremented).first_name (str):
The first name of the employee.last_name (str):
The last name of the employee.email (str):
The unique email address of the employee.salary (int):
The employee's salary.
Source code in myapp/api/Database/models.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
ProductDB
Bases: Base
Represents a Product in the database.
Attributes:
product_id (int):
The unique identifier for the product (auto-incremented).product_name (str):
The name of the product.price (float):
The price of the product.description (str):
A short description of the product.category (str):
The category the product belongs to.
Source code in myapp/api/Database/models.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|