2026-07-13 13:22:12 -03:00
|
|
|
using Api.SeaHavenIndustries.Options;
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2026-07-13 13:22:12 -03:00
|
|
|
using Microsoft.Extensions.Options;
|
2026-07-24 17:35:34 -03:00
|
|
|
using SeaHaven.Services.Interfaces;
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
|
|
|
|
|
namespace Api.SeaHavenIndustries.Controllers
|
|
|
|
|
{
|
2026-07-13 13:22:12 -03:00
|
|
|
[Authorize(Roles = "Admin")]
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
public class SyncController : Controller
|
|
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
private readonly ISyncService _syncService;
|
2026-07-13 13:22:12 -03:00
|
|
|
private readonly SyncOptions _syncOptions;
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
|
2026-07-24 17:35:34 -03:00
|
|
|
public SyncController(ISyncService syncService, IOptions<SyncOptions> syncOptions)
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
{
|
2026-07-24 17:35:34 -03:00
|
|
|
_syncService = syncService;
|
2026-07-13 13:22:12 -03:00
|
|
|
_syncOptions = syncOptions.Value;
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
}
|
|
|
|
|
|
2026-07-13 13:22:12 -03:00
|
|
|
private IActionResult? SyncDisabledResult()
|
|
|
|
|
{
|
|
|
|
|
if (_syncOptions.Enabled)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
return StatusCode(StatusCodes.Status503ServiceUnavailable, new
|
|
|
|
|
{
|
|
|
|
|
message = "DynamoDB sync bridge is disabled. Use POST /api/workorders/ingest."
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
[HttpPost("WorkOrders")]
|
2026-07-24 17:35:34 -03:00
|
|
|
public async Task<IActionResult> SyncWorkOrders(CancellationToken cancellationToken)
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
{
|
2026-07-13 13:22:12 -03:00
|
|
|
if (SyncDisabledResult() is { } disabled)
|
|
|
|
|
return disabled;
|
2026-04-16 18:42:58 -04:00
|
|
|
|
2026-07-24 17:35:34 -03:00
|
|
|
var result = await _syncService.SyncWorkOrdersAsync(cancellationToken);
|
|
|
|
|
return Ok(result);
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("Comments")]
|
2026-07-24 17:35:34 -03:00
|
|
|
public async Task<IActionResult> SyncComments(CancellationToken cancellationToken)
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
{
|
2026-07-13 13:22:12 -03:00
|
|
|
if (SyncDisabledResult() is { } disabled)
|
|
|
|
|
return disabled;
|
|
|
|
|
|
2026-07-24 17:35:34 -03:00
|
|
|
var result = await _syncService.SyncCommentsAsync(cancellationToken);
|
|
|
|
|
return Ok(result);
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
}
|
|
|
|
|
|
2026-04-16 18:42:58 -04:00
|
|
|
[HttpPost("BackfillInternalWONumbers")]
|
2026-07-24 17:35:34 -03:00
|
|
|
public async Task<IActionResult> BackfillInternalWONumbers(CancellationToken cancellationToken)
|
2026-04-16 18:42:58 -04:00
|
|
|
{
|
2026-07-13 13:22:12 -03:00
|
|
|
if (SyncDisabledResult() is { } disabled)
|
|
|
|
|
return disabled;
|
|
|
|
|
|
2026-07-24 17:35:34 -03:00
|
|
|
var result = await _syncService.BackfillInternalWONumbersAsync(cancellationToken);
|
|
|
|
|
return Ok(result);
|
2026-04-16 18:42:58 -04:00
|
|
|
}
|
|
|
|
|
|
2026-04-17 14:01:03 -04:00
|
|
|
[HttpPost("BackfillDispatchNumbers")]
|
2026-07-24 17:35:34 -03:00
|
|
|
public async Task<IActionResult> BackfillDispatchNumbers(CancellationToken cancellationToken)
|
2026-04-17 14:01:03 -04:00
|
|
|
{
|
2026-07-13 13:22:12 -03:00
|
|
|
if (SyncDisabledResult() is { } disabled)
|
|
|
|
|
return disabled;
|
|
|
|
|
|
2026-07-24 17:35:34 -03:00
|
|
|
var result = await _syncService.BackfillDispatchNumbersAsync(cancellationToken);
|
|
|
|
|
return Ok(result);
|
2026-04-17 14:01:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("VendorReplies")]
|
2026-07-24 17:35:34 -03:00
|
|
|
public async Task<IActionResult> SyncVendorReplies(CancellationToken cancellationToken)
|
2026-04-17 14:01:03 -04:00
|
|
|
{
|
2026-07-13 13:22:12 -03:00
|
|
|
if (SyncDisabledResult() is { } disabled)
|
|
|
|
|
return disabled;
|
|
|
|
|
|
2026-07-24 17:35:34 -03:00
|
|
|
var result = await _syncService.SyncVendorRepliesAsync(cancellationToken);
|
|
|
|
|
return Ok(result);
|
2026-04-17 14:01:03 -04:00
|
|
|
}
|
|
|
|
|
|
2026-04-16 18:09:57 -04:00
|
|
|
[HttpPost("BackfillCommentTypes")]
|
2026-07-24 17:35:34 -03:00
|
|
|
public async Task<IActionResult> BackfillCommentTypes(CancellationToken cancellationToken)
|
2026-04-16 18:09:57 -04:00
|
|
|
{
|
2026-07-13 13:22:12 -03:00
|
|
|
if (SyncDisabledResult() is { } disabled)
|
|
|
|
|
return disabled;
|
|
|
|
|
|
2026-07-24 17:35:34 -03:00
|
|
|
var result = await _syncService.BackfillCommentTypesAsync(cancellationToken);
|
|
|
|
|
return Ok(result);
|
2026-04-16 18:09:57 -04:00
|
|
|
}
|
|
|
|
|
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
[HttpPost("All")]
|
2026-07-24 17:35:34 -03:00
|
|
|
public async Task<IActionResult> SyncAll(CancellationToken cancellationToken)
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
{
|
2026-07-13 13:22:12 -03:00
|
|
|
if (SyncDisabledResult() is { } disabled)
|
|
|
|
|
return disabled;
|
|
|
|
|
|
2026-07-24 17:35:34 -03:00
|
|
|
var result = await _syncService.SyncAllAsync(cancellationToken);
|
|
|
|
|
return Ok(result);
|
Add DynamoDB sync bridge for workorder-ingest pipeline
- Add ExternalWorkOrderId, Customer, SiteCode, Building, Severity,
DateReported, ScheduledStart, SourceEmailS3Key to WorkOrder model
- Add Commenter, RecordType, ExternalCommentId to Comments model
- Add AWSSDK.DynamoDBv2 package
- Create SyncController with endpoints:
- POST /api/Sync/WorkOrders — scans DynamoDB WorkOrders table, upserts into SQL
- POST /api/Sync/Comments — scans DynamoDB WorkOrderComments, creates Comments
- POST /api/Sync/All — runs both
- Auto-creates Locations from site_code/building/address during sync
- Maps DynamoDB status values to SHOC status strings
- Maps severity to SHOC priority format (Sev N)
- Deduplicates on ExternalWorkOrderId / ExternalCommentId
2026-04-16 17:29:52 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|