The Parcel Handling System is designed to manage and process parcels based on their weight and value. The system is divided into two main features:
- Parcels with a weight up to 1 kg are handled by the "Mail" department.
- Parcels with a weight up to 10 kg are handled by the "Regular" department.
- Parcels with a weight over 10 kg are handled by the "Heavy" department.
- Parcels with a value of over €1000 need to be signed off by the "Insurance" department before being processed by the other departments.
- FastAPI: A modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.
- Pydantic: Data validation and settings management using Python type annotations.
- Uvicorn: A lightning-fast ASGI server implementation, using
uvloop
andhttptools
.
- Vue.js: A progressive JavaScript framework for building user interfaces.
- TypeScript: A strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.
- Vite: A build tool that aims to provide a faster and leaner development experience for modern web projects.
- Axios: A promise-based HTTP client for the browser and Node.js.
- shadcn/ui: A library of components for building modern web applications.
- TailwindCSS: A utility-first CSS framework for rapidly building custom designs.
- pnpm: A fast, disk space efficient package manager.
- api.py: The main FastAPI application file that defines the API endpoints and business logic.
- parcel_handler folder: Contains the
ParcelHandler
andDepartmentFactory
classes that handle the parsing and processing of parcels, and of course theDepartment
classes.
- src/constants/tableColumns.ts: Defines the table columns for displaying parcel data.
- src/pages/home/home.vue: The main Vue component for displaying the parcel data in a table format.
- src/types/table.ts: Defines the TypeScript types for the table columns.
The choosing of factory pattern was made for the following reasons:
- Encapsulation: The factory pattern encapsulates the logic for creating department objects based on parcel weight and value. This makes the code more modular and easier to maintain.
- Scalability: As business rules change or new departments are added, the factory pattern allows us to easily extend the system without modifying existing code.
- Separation of Concerns: By using the factory pattern, we separate the logic for determining the appropriate department from the actual processing logic. This makes the code more readable and easier to test.
- Install the required dependencies:
pip install fastapi pydantic uvicorn
- Run the FastAPI application:
or
uvicorn parcel_handling_system.api:app --reload
python3 api.py
- Install the required dependencies:
pnpm install
- Run the development server:
pnpm dev
- GET /parcels: Retrieves the list of parcels, processes them according to the business rules, and returns the processed parcels.
curl -X GET http://localhost:8000/parcels
{
"parcels": [
{
"name": "Parcel 1",
"weight": 0.5,
"value": 500,
"department": "MailDepartment"
},
{
"name": "Parcel 2",
"weight": 5,
"value": 1500,
"department": "InsuranceDepartment"
}
]
}