6a19a9f70d
b4 of the multi-provider email roadmap. The manual/free-text correspondence entry path already existed (CorrespondenceController.Create) -- this slice was narrower than the roadmap wording suggests: tag every Correspondence row with which provider it came from (gmail | manual today; microsoft | imap once those providers grow an import-into-Correspondence path of their own), not build a new endpoint. - Correspondence.Provider (nullable string), reconciled via the existing EnsureColumn pattern (SQLite + MySQL). - Idempotent backfill: rows with an ExternalThreadId (historically only ever written by Gmail import) get 'gmail'; everything else gets 'manual'. - GmailController.ImportSingleMessageAsync now tags Provider = "gmail". - CorrespondenceController.Create now tags Provider = "manual". - Both write sites use a fixed literal, not request input -- no injection surface introduced. Backfill SQL is static, no interpolation. 148/148 green (147 existing + 1 new CorrespondenceControllerTests; the GmailController import test gained a Provider assertion in place). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
51 lines
2.3 KiB
C#
51 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace JobTrackerApi.Models
|
|
{
|
|
public class Correspondence
|
|
{
|
|
public int Id { get; set; }
|
|
public int JobApplicationId { get; set; }
|
|
|
|
[JsonIgnore]
|
|
public JobApplication JobApplication { get; set; } = null!;
|
|
public string From { get; set; } = ""; // "Me" or "Company"
|
|
public string? Direction { get; set; } // inbound, outbound, internal, unknown
|
|
public string? Subject { get; set; }
|
|
public string? Channel { get; set; } // e.g. Email, Call, Note
|
|
public string? ExternalMessageId { get; set; }
|
|
public string? ExternalThreadId { get; set; }
|
|
public string? ExternalFrom { get; set; }
|
|
public string? ExternalTo { get; set; }
|
|
public string? ExternalLabelsJson { get; set; }
|
|
public string? AttachmentMetadataJson { get; set; }
|
|
// Provider discriminator: "gmail" | "microsoft" | "imap" | "manual". Set at the write
|
|
// site (import controller or the manual-entry endpoint), not inferred from other fields,
|
|
// so it stays correct even for hand-entered rows that happen to carry external-looking data.
|
|
public string? Provider { get; set; }
|
|
public string Content { get; set; } = "";
|
|
public DateTime Date { get; set; } = DateTime.Now;
|
|
|
|
[JsonIgnore]
|
|
public IReadOnlyList<string> ExternalLabels => string.IsNullOrWhiteSpace(ExternalLabelsJson)
|
|
? Array.Empty<string>()
|
|
: (System.Text.Json.JsonSerializer.Deserialize<List<string>>(ExternalLabelsJson) ?? new List<string>());
|
|
|
|
[JsonIgnore]
|
|
public IReadOnlyList<CorrespondenceAttachmentMetadata> AttachmentMetadata => string.IsNullOrWhiteSpace(AttachmentMetadataJson)
|
|
? Array.Empty<CorrespondenceAttachmentMetadata>()
|
|
: (System.Text.Json.JsonSerializer.Deserialize<List<CorrespondenceAttachmentMetadata>>(AttachmentMetadataJson) ?? new List<CorrespondenceAttachmentMetadata>());
|
|
}
|
|
|
|
public sealed class CorrespondenceAttachmentMetadata
|
|
{
|
|
public string? FileName { get; set; }
|
|
public string? MimeType { get; set; }
|
|
public long? SizeBytes { get; set; }
|
|
public string? GmailAttachmentId { get; set; }
|
|
public bool Inline { get; set; }
|
|
}
|
|
}
|