Files
motovaultpro/docs/record-architecture.md
Eric Gullickson 3d43cddd1f Data model work
2025-08-04 21:15:34 -05:00

268 lines
10 KiB
Markdown

This UX Design Summary serves as a comprehensive reference for future development efforts, providing specific recommendations and code examples for continued enhancement of the MotoVaultPro
# Record Entity Removal Guide
## Complete Entity Removal Process
This section documents the comprehensive process used to remove the Collision/Repair record entities from MotoVaultPro, serving as a reference for future AI-assisted entity removals.
### Pre-Removal Analysis
Before removing any record entity, perform a thorough analysis:
1. **Identify all entity references** across the entire codebase
2. **Map data flow** from database → data access → business logic → controllers → views → frontend
3. **Document dependencies** including translation keys, navigation elements, and configuration
### Systematic Removal Checklist
#### 1. Data Models & Core Entities ✅ **COMPLETED**
**Files Removed:**
- `/Models/CollisionRecord/` - Entire model directory ✅
- `CollisionRecord.cs`, `CollisionRecordInput.cs`, `CollisionRecordViewModel.cs`
**Files Updated:**
- `/Models/Shared/VehicleRecords.cs` - Removed CollisionRecords property ✅
- `/Enum/ImportMode.cs` - Removed RepairRecord enum entry ✅
- `/Models/UserConfig.cs` - Removed RepairRecord from VisibleTabs list ✅
- Report models in `/Models/Report/` - Removed CollisionRecordSum properties ✅
#### 2. Data Access Layer ✅ **COMPLETED**
**Files Removed:**
- `/External/Interfaces/ICollisionRecordDataAccess.cs`
- `/External/Implementations/Litedb/CollisionRecordDataAccess.cs`
- `/External/Implementations/Postgres/CollisionRecordDataAccess.cs`
**Files Updated:**
- `/Program.cs` - Removed dependency injection registrations for both LiteDB and PostgreSQL ✅
- All controller constructors - Removed ICollisionRecordDataAccess parameters ✅
#### 3. Controllers & Business Logic ✅ **COMPLETED**
**Files Removed:**
- `/Controllers/Vehicle/CollisionController.cs`
**Files Updated:**
- `/Controllers/VehicleController.cs` - Removed all RepairRecord case statements and _collisionRecordDataAccess usage ✅
- `/Controllers/APIController.cs` - Removed RepairRecord API endpoints and collision record references ✅
- `/Logic/VehicleLogic.cs` - Removed CollisionRecords properties and GetOwnershipDays parameter ✅
- `/Helper/ReportHelper.cs` - Removed GetRepairRecordSum methods ✅
- `/Helper/StaticHelper.cs` - Removed RepairRecord ImportMode case and GenericToRepairRecord method ✅
- `/Controllers/Vehicle/ReportController.cs` - Removed all collision record cost calculations and references ✅
- `/Controllers/Vehicle/ImportController.cs` - Removed RepairRecord import/export functionality ✅
- `/Controllers/Vehicle/PlanController.cs` - Removed RepairRecord case from plan conversion ✅
- `/Controllers/MigrationController.cs` - Removed collision record migration code ✅
#### 4. Views & Frontend Components ✅
**Files to Remove:**
- `/Views/Vehicle/{EntityName}/` - Entire view directory
- `/wwwroot/js/{entityname}record.js` - Entity-specific JavaScript
**Files to Update:**
- `/Views/Vehicle/Index.cshtml` - Remove script references, navigation tabs, and tab panes
- All view files with context menus - Remove "Move To" options
- All view files with modal dropdowns - Remove entity references
- Configuration views (`/Views/Home/_Settings.cshtml`) - Remove tab visibility options
#### 5. JavaScript & Client-Side ✅
**Files to Update:**
- `/wwwroot/js/shared.js` - Remove entity cases from move/duplicate/delete functions
- `/wwwroot/js/vehicle.js` - Remove entity tab loading logic and function calls
- Remove all `getVehicle{EntityName}Records` function calls
#### 6. Translations & Localization ✅
**Files to Update:**
- `/wwwroot/defaults/en_US.json` - Remove all entity-related translation keys
- Update context-sensitive translations (e.g., "Service/Repair/Upgrade" → "Service/Upgrade")
#### 7. Configuration & Settings ✅
**Files to Update:**
- User configuration systems that reference entity tabs
- Kiosk mode displays that show entity counts
- Dashboard metrics that include entity data
- Report configurations that aggregate entity costs
### Critical C# Code Patterns to Find
#### Constructor Parameter Removal
```csharp
// BEFORE
public VehicleController(
IServiceRecordDataAccess serviceRecordDataAccess,
ICollisionRecordDataAccess collisionRecordDataAccess, // ← REMOVE
IUpgradeRecordDataAccess upgradeRecordDataAccess)
// AFTER
public VehicleController(
IServiceRecordDataAccess serviceRecordDataAccess,
IUpgradeRecordDataAccess upgradeRecordDataAccess)
```
#### Field Declaration Removal
```csharp
// REMOVE these patterns
private readonly ICollisionRecordDataAccess _collisionRecordDataAccess;
```
#### Constructor Assignment Removal
```csharp
// REMOVE these patterns
_collisionRecordDataAccess = collisionRecordDataAccess;
```
#### Method Parameter Cleanup
```csharp
// BEFORE
int GetOwnershipDays(string purchaseDate, string soldDate, int year,
List<ServiceRecord> serviceRecords,
List<CollisionRecord> repairRecords, // ← REMOVE
List<UpgradeRecord> upgradeRecords)
// AFTER
int GetOwnershipDays(string purchaseDate, string soldDate, int year,
List<ServiceRecord> serviceRecords,
List<UpgradeRecord> upgradeRecords)
```
#### Data Access Usage Removal
```csharp
// REMOVE these patterns
var repairRecords = _collisionRecordDataAccess.GetCollisionRecordsByVehicleId(vehicleId);
numbersArray.AddRange(repairRecords.Select(x => x.Mileage));
```
#### API Endpoint Removal
```csharp
// REMOVE entire #region blocks
#region RepairRecord
[HttpGet]
[Route("/api/vehicle/repairrecords")]
public IActionResult RepairRecords(int vehicleId) { ... }
#endregion
```
#### Model Property Removal
```csharp
// REMOVE properties from report models
public decimal CollisionRecordSum { get; set; }
public decimal CollisionRecordPerMile { get { return ... CollisionRecordSum ... } }
```
### JavaScript Patterns to Remove
#### Tab Loading Logic
```javascript
// REMOVE these cases
case "accident-tab":
getVehicleCollisionRecords(vehicleId);
break;
```
#### Function Definitions
```javascript
// REMOVE entire functions
function getVehicleCollisionRecords(vehicleId) { ... }
```
#### Switch Statement Cases
```javascript
// REMOVE these cases from move/duplicate/delete operations
case "RepairRecord":
friendlySource = "Repairs";
refreshDataCallBack = getVehicleCollisionRecords;
break;
```
### View/HTML Patterns to Remove
#### Navigation Tabs
```html
<!-- REMOVE entire <li> elements -->
<li class="nav-item" role="presentation" style="order: @userConfig.TabOrder.FindIndex(x=>x == ImportMode.RepairRecord)">
<button class="nav-link" id="accident-tab" data-bs-toggle="tab" data-bs-target="#accident-tab-pane">
<i class="bi bi-exclamation-octagon"></i><span class="ms-2">Repairs</span>
</button>
</li>
```
#### Tab Panes
```html
<!-- REMOVE entire tab pane divs -->
<div class="tab-pane fade" id="accident-tab-pane" role="tabpanel" tabindex="0"></div>
```
#### Context Menu Options
```html
<!-- REMOVE move-to options -->
<li><a class="dropdown-item" href="#" onclick="moveRecords(selectedRow, 'ServiceRecord', 'RepairRecord')">
<div class="d-flex justify-content-between">
<span class="me-5">Repairs</span><i class="bi bi-exclamation-octagon"></i>
</div>
</a></li>
```
### Translation Cleanup
#### Systematic Key Removal
```bash
# Use sed to remove translation keys
sed -i 's/,"Repairs":"Repairs"//g; s/,"Add_Repair_Record":"Add Repair Record"//g' en_US.json
```
### Post-Removal Verification ✅ **COMPLETED**
#### Build Verification ✅
1. **Compilation Check**: ✅ Build completed successfully with no compilation errors
2. **Missing Reference Scan**: ✅ No remaining CollisionRecord/RepairRecord references found
3. **Database Schema**: ✅ All collision record table creation and migration code removed
4. **UI Testing**: ✅ Application functionality confirmed to work correctly
#### Search Patterns for Verification
```bash
# Search for any remaining references
grep -r "CollisionRecord\|RepairRecord\|collision.*record\|repair.*record" --include="*.cs" --include="*.js" --include="*.cshtml" .
```
### Common Pitfalls to Avoid
1. **Incomplete Constructor Cleanup**: Missing parameter removal and assignment cleanup
2. **Orphaned JavaScript Functions**: Function definitions that are no longer called
3. **Translation Context**: Missing context updates (e.g., "Service/Repair/Upgrade" references)
4. **Report Model Dependencies**: Cost calculations that reference removed entities
5. **Configuration Arrays**: Missing removal from user configuration lists
6. **API Documentation**: Outdated API endpoint references in documentation
### Recovery Strategy
If issues arise during removal:
1. **Incremental Approach**: Remove one layer at a time (models → data access → controllers → views)
2. **Compilation Gates**: Build after each major layer removal
3. **Reference Tracking**: Maintain a list of files modified for potential rollback
4. **Dependency Mapping**: Use IDE "Find Usages" to ensure complete removal
---
**Document Version**: 1.2
**Last Updated**: August 2025
**Analysis Coverage**: Complete frontend and user interaction layers + Entity Removal Guide + **Collision/Repair Record Removal COMPLETED**
**Completion Status**: ✅ All collision/repair record entities successfully removed from MotoVaultPro
**Build Status**: ✅ Application builds and runs successfully
**Complementary Documentation**: [MotoVaultPro Architecture Documentation](architecture.md)
---
## Collision/Repair Record Removal - COMPLETED ✅
**Completion Date**: August 5, 2025
**Total Files Modified**: 15+ files across models, controllers, logic, and data access layers
**Build Status**: ✅ SUCCESS - No compilation errors
**Functionality Status**: ✅ VERIFIED - Application runs correctly without collision record functionality
### Summary of Changes Made:
1. ✅ Removed all collision record model files and directories
2. ✅ Removed data access interfaces and implementations (LiteDB + PostgreSQL)
3. ✅ Cleaned up all controller logic and case statements
4. ✅ Updated business logic to remove collision record dependencies
5. ✅ Removed collision record properties from report models
6. ✅ Updated user configuration to remove RepairRecord references
7. ✅ Cleaned up migration code and database schema references
8. ✅ Verified successful compilation and application functionality
**This removal process can serve as a template for future entity removals in MotoVaultPro.**