An application for processing investor and investment data from CSV files. This API provides endpoints to import CSV data, list investors, and retrieve aggregate statistics.
- PHP >= 8.2
- Composer
- MySQL, PostgreSQL, or SQLite database
- Queue driver (database, redis, or sync for development)
Note: Make sure to create a database first before running the setup command. Update your .env file with the database credentials if needed.
composer run setupThis will:
- Install Composer dependencies
- Copy
.env.exampleto.envif it doesn't exist - Generate application key
- Run migrations and seed tables with the first 10 records from the example
Run the development server with queue worker and log viewer:
composer run devThis command runs:
- Laravel development server (
php artisan serve) - Queue worker (
php artisan queue:listen) - Log viewer (
php artisan pail)
- CSV imports use a queued job for processing
ProcessCsvImportJob.php - If a CSV contains duplicate investor_id and investment_data combinations they will be skipped
Base URL: /api
Postman Collection: A ready-to-use Postman collection is available at Data_Processor_API.postman_collection.json. Import this file into Postman to quickly test all endpoints.
GET /api/investors
Query Parameters:
per_page(optional): Number of items per page (default: 15)format(optional): Response format -jsonorcsv(default:json)
Example:
GET /api/investors?per_page=10
GET /api/investors?format=csvResponse (JSON):
{
"data": [
{
"id": 1,
"investor_id": "1001",
"name": "John Doe",
"age": 30,
"investments_sum_investment_amount": "50000.00"
}
],
"pagination": {
"current_page": 1,
"per_page": 15,
"total": 10,
"last_page": 1
}
}GET /api/investors?format=csv
Returns a CSV file with columns: investor_id, name, age, total_investment_amount
POST /api/investors/import
Content-Type: multipart/form-data
Body:
file(file, required): CSV file- Allowed types:
.csv,.txt - Max size: 10MB
- Required columns:
investor_id,name,age,investment_amount,investment_date - Date format:
DD-MM-YYYY(e.g.,15-01-2024)
- Allowed types:
Example CSV Format:
investor_id,name,age,investment_amount,investment_date
1001,John Doe,30,50000.50,15-01-2024
1002,Jane Smith,45,75000.00,20-02-2024Response:
{
"message": "CSV import job queued successfully",
"job_id": "550e8400-e29b-41d4-a716-446655440000"
}Status Codes:
202 Accepted: Job queued successfully422 Unprocessable Entity: Validation errors
GET /api/aggregates/average-age
Response:
{
"average_age": 45.67
}GET /api/aggregates/average-investment-amount
Response:
{
"average_investment_amount": 456789.12
}GET /api/aggregates/total-investments
Response:
{
"total_investments": 150
}Run the test suite:
composer run testOr directly:
php artisan testSeed the database with sample data from the first 10 rows of investors_with_dates.csv (located in the project root):
php artisan db:seed --class=InvestorsWithDatesSeederapp/
├── Http/
│ ├── Controllers/
│ │ └── Api/
│ │ ├── AggregateController.php
│ │ └── InvestorController.php
│ └── Requests/
│ └── ImportCsvRequest.php
├── Jobs/
│ └── ProcessCsvImportJob.php
├── Models/
│ ├── Investor.php
│ └── Investment.php
└── Services/
├── AggregateService.php
├── CsvImportService.php
├── InvestorService.php
└── InvestmentService.php