Víctor Falcón
8a8d5962b5
refactor: Simplify transaction endpoints architecture ( #76 )
...
## Summary
Simplifies transaction endpoints by separating sync API (read-only) from
web routes (mutations). This creates clearer architectural boundaries
and fixes inconsistent label behavior.
## Architecture Changes
### Before
- Sync API handled both sync (GET) and mutations (POST/PATCH/DELETE)
- Frontend used sync API for all operations
- Bulk updates merged labels, single updates replaced them
### After
- **Sync API**: Read-only GET endpoint for IndexedDB sync
- **Web Routes**: All mutations (create, update, delete, bulk
operations)
- **Consistent behavior**: All label updates replace instead of merge
## Endpoint Mapping
| Operation | Old Endpoint | New Endpoint |
|-----------|-------------|--------------|
| Fetch/Sync | `GET /api/sync/transactions` | `GET
/api/sync/transactions` ✅ |
| Create | `POST /api/sync/transactions` | `POST /transactions` |
| Update | `PATCH /api/sync/transactions/{id}` | `PATCH
/transactions/{id}` |
| Delete | `DELETE /api/sync/transactions/{id}` | `DELETE
/transactions/{id}` |
| Bulk Update | `PATCH /transactions/bulk` | `PATCH /transactions/bulk`
✅ |
## Backend Changes
### TransactionSyncController
- ✅ Simplified to read-only `index()` method
- ✅ Removed `store()`, `update()`, `destroy()` methods
- ✅ Added docblock clarifying purpose
### TransactionController
- ✅ Fixed `store()` to return labels with `id, name, color`
- ✅ Fixed `update()` to return labels with `id, name, color`
- ✅ Changed `bulkUpdate()` to replace labels instead of merging
### Cleanup
- ✅ Removed `UpdateTransactionSyncRequest` (no longer needed)
- ✅ Updated `routes/api.php` to only have GET for sync
## Frontend Changes
### transaction-sync.ts
- ✅ Updated `create()` → `POST /transactions`
- ✅ Updated `update()` → `PATCH /transactions/{id}`
- ✅ Updated `delete()` → `DELETE /transactions/{id}`
- ✅ Replaced all `fetch()` calls with `axios`
- ✅ Removed manual CSRF token handling
## Test Changes
### TransactionSyncTest
- ✅ Removed create/update/delete tests
- ✅ Kept only read-only sync tests
- ✅ Added test for labels format
### BulkUpdateTransactionsTest
- ✅ Added test verifying label replacement behavior
## Test Results
All tests passing! ✅
```
Tests: 42 passed (235 assertions)
Duration: 6.17s
✓ TransactionTest: 29 tests
✓ TransactionSyncTest: 4 tests
✓ BulkUpdateTransactionsTest: 9 tests
```
## Benefits
1. **Clear separation of concerns**: Sync API is read-only, web routes
handle mutations
2. **Consistent label behavior**: All updates replace labels (not merge)
3. **Standardized HTTP client**: Axios everywhere, automatic CSRF
handling
4. **Reduced complexity**: Removed duplicate form request class
5. **Better architecture**: Aligns with intended design
## Breaking Changes
None - All changes are internal to how the frontend calls the backend.
The functionality remains the same from the user's perspective.
## Files Changed
- `app/Http/Controllers/Sync/TransactionSyncController.php`
- `app/Http/Controllers/TransactionController.php`
- `app/Http/Requests/UpdateTransactionSyncRequest.php` (deleted)
- `resources/js/services/transaction-sync.ts`
- `routes/api.php`
- `tests/Feature/Sync/TransactionSyncTest.php`
- `tests/Feature/BulkUpdateTransactionsTest.php`
2026-01-25 16:15:17 +01:00
Víctor Falcón
439ec86722
chore: Simplify IndexedDB sync by moving to Inertia shared props ( #63 )
...
This PR simplifies the IndexedDB synchronization mechanism by removing
individual sync controllers and services, and instead using Inertia.js
shared props to provide data globally across the application.
## Benefits
1. **Simplified Architecture**: Removed complex sync logic for
static/semi-static data (accounts, categories, banks, labels, automation
rules)
2. **Better Performance**: Data is now shared via Inertia props,
eliminating unnecessary API calls and IndexedDB operations
3. **Reduced Complexity**: Significantly reduced codebase size (~2000
lines removed)
4. **Better UX**: Data is immediately available on page load without
waiting for sync operations
5. **Maintainability**: Fewer moving parts means easier to maintain and
debug
## Migration Notes
- Transaction syncing still uses IndexedDB for offline support
- All other data (accounts, categories, banks, labels, automation rules)
is now fetched via Inertia shared props
- Components automatically receive updated data on navigation without
manual sync operations
2026-01-19 19:15:26 +01:00