mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 22:34:47 +00:00
* Implement API v1 Imports controller - Add Api::V1::ImportsController with index, show, and create actions - Add Jbuilder views for index and show - Add integration tests - Implement row generation logic in create action - Update routes * Validate import account belongs to family - Add validation to Import model to ensure account belongs to the same family - Add regression test case in Api::V1::ImportsControllerTest * updating docs to be more detailed * Rescue StandardError instead of bare rescue in ImportsController * Optimize Imports API and fix documentation - Implement rows_count counter cache for Imports - Preload rows in Api::V1::ImportsController#show - Update documentation to show correct OAuth scopes * Fix formatting in ImportsControllerTest * Permit all import parameters and fix unknown attribute error * Restore API routes for auth, chats, and messages * removing pr summary * Fix trailing whitespace and configured? test failure - Update Import#configured? to use rows_count for performance and consistency - Mock rows_count in TransactionImportTest - Fix trailing whitespace in migration * Harden security and fix mass assignment in ImportsController - Handle type and account_id explicitly in create action - Rename import_params to import_config_params for clarity - Validate type against Import::TYPES * Fix MintImport rows_count update and migration whitespace - Update MintImport#generate_rows_from_csv to update rows_count counter cache - Fix trailing whitespace and final newline in AddRowsCountToImports migration * Implement full-screen Drag and Drop CSV import on Transactions page - Add DragAndDropImport Stimulus controller listening on document - Add full-screen overlay with icon and text to Transactions index - Update ImportsController to handle direct file uploads via create action - Add system test for drag and drop functionality * Implement Drag and Drop CSV upload on Import Upload page - Add drag-and-drop-import controller to import/uploads/show - Add full-screen overlay to import/uploads/show - Annotate upload form and input with drag-and-drop targets - Add PR_SUMMARY.md * removing pr summary * Add file validation to ImportsController - Validate file size (max 10MB) and MIME type in create action - Prevent memory exhaustion and invalid file processing - Defined MAX_CSV_SIZE and ALLOWED_MIME_TYPES in Import model * Refactor dragLeave logic with counter pattern to prevent flickering * Extract shared drag-and-drop overlay partial - Create app/views/imports/_drag_drop_overlay.html.erb - Update transactions/index and import/uploads/show to use the partial - Reduce code duplication in views * Update Brakeman and harden ImportsController security - Update brakeman to 7.1.2 - Explicitly handle type assignment in ImportsController#create to avoid mass assignment - Remove :type from permitted import parameters * Fix trailing whitespace in DragAndDropImportTest * Don't commit LLM comments as file * FIX add api validation --------- Co-authored-by: Carlos Adames <cj@Carloss-MacBook-Air.local> Co-authored-by: Juan José Mata <jjmata@jjmata.com> Co-authored-by: sokie <sokysrm@gmail.com>
102 lines
3.1 KiB
Markdown
102 lines
3.1 KiB
Markdown
# Imports API Documentation
|
|
|
|
The Imports API allows external applications to programmatically upload and process financial data from CSV files. This API supports creating transaction imports, configuring column mappings, and triggering the import process.
|
|
|
|
## Authentication requirements
|
|
|
|
All import endpoints require an OAuth2 access token or API key that grants the appropriate scope (`read` or `read_write`).
|
|
|
|
## Available endpoints
|
|
|
|
| Endpoint | Scope | Description |
|
|
| --- | --- | --- |
|
|
| `GET /api/v1/imports` | `read` | List imports with filtering and pagination. |
|
|
| `GET /api/v1/imports/{id}` | `read` | Retrieve a single import with configuration and statistics. |
|
|
| `POST /api/v1/imports` | `read_write` | Create a new import and optionally trigger processing. |
|
|
|
|
## Filtering options
|
|
|
|
The `GET /api/v1/imports` endpoint supports the following query parameters:
|
|
|
|
| Parameter | Type | Description |
|
|
| --- | --- | --- |
|
|
| `page` | integer | Page number (default: 1) |
|
|
| `per_page` | integer | Items per page (default: 25, max: 100) |
|
|
| `status` | string | Filter by status: `pending`, `importing`, `complete`, `failed`, `reverting`, `revert_failed` |
|
|
| `type` | string | Filter by import type: `TransactionImport`, `TradeImport`, etc. |
|
|
|
|
## Import object
|
|
|
|
An import response includes configuration and processing statistics:
|
|
|
|
```json
|
|
{
|
|
"data": {
|
|
"id": "uuid",
|
|
"type": "TransactionImport",
|
|
"status": "pending",
|
|
"created_at": "2024-01-15T10:30:00Z",
|
|
"updated_at": "2024-01-15T10:30:00Z",
|
|
"account_id": "uuid",
|
|
"configuration": {
|
|
"date_col_label": "date",
|
|
"amount_col_label": "amount",
|
|
"name_col_label": "name",
|
|
"category_col_label": "category",
|
|
"tags_col_label": "tags",
|
|
"notes_col_label": "notes",
|
|
"account_col_label": null,
|
|
"date_format": "%m/%d/%Y",
|
|
"number_format": "1,234.56",
|
|
"signage_convention": "inflows_positive"
|
|
},
|
|
"stats": {
|
|
"rows_count": 150,
|
|
"valid_rows_count": 150
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## Creating an import
|
|
|
|
When creating an import, you must provide the file content and the column mappings.
|
|
|
|
### Parameters
|
|
|
|
| Parameter | Type | Description |
|
|
| --- | --- | --- |
|
|
| `raw_file_content` | string | The raw CSV content as a string. |
|
|
| `file` | file | Alternatively, the CSV file can be uploaded as a multipart form-data part. |
|
|
| `account_id` | uuid | Optional. The ID of the account to import into. |
|
|
| `date_col_label` | string | The header name for the date column. |
|
|
| `amount_col_label` | string | The header name for the amount column. |
|
|
| `name_col_label` | string | The header name for the transaction name column. |
|
|
| `publish` | boolean | If `true`, the import will be automatically queued for processing if configuration is valid. |
|
|
|
|
Example request body:
|
|
|
|
```json
|
|
{
|
|
"raw_file_content": "date,amount,name\n01/01/2024,10.00,Test",
|
|
"date_col_label": "date",
|
|
"amount_col_label": "amount",
|
|
"name_col_label": "name",
|
|
"account_id": "uuid",
|
|
"publish": "true"
|
|
}
|
|
```
|
|
|
|
## Error responses
|
|
|
|
Errors conform to the shared `ErrorResponse` schema:
|
|
|
|
```json
|
|
{
|
|
"error": "error_code",
|
|
"message": "Human readable error message",
|
|
"errors": ["Optional array of validation errors"]
|
|
}
|
|
```
|
|
|