WIP(initial-implementation): parallel batch P2/P3/P5 — code complete, unreviewed
Snapshot of the parallel batch (Phases 2 + 3 + 5) at session pause. Solution does
NOT build cleanly yet — known cross-phase compile issues remain to be resolved
before review. See plans/initial-implementation/PLAN.md "Resume Notes" section
for the exact tomorrow-morning action list.
Phase 2 (Storage):
- Repository interfaces in Marathon.Application/Abstractions
- DateRange, ExportKind, StorageOptions in Marathon.Application/Storage
- EF Core 8 + SQLite (WAL) persistence: 7 entities + configurations + 4 repos
- Hand-written InitialCreate migration (dotnet ef blocked by parallel work)
- ClosedXML ExcelExporter with exact customer-spec wide columns
- PersistenceModule.AddMarathonPersistence DI extension
- Round-trip + export tests (cannot run yet — see cross-phase issues)
Phase 3 (Scraping):
- IOddsScraper, IBetPlacer in Marathon.Application/Abstractions
- ScrapingOptions in Marathon.Infrastructure/Configuration
- MarathonbetScraper with 4 parsers (Upcoming, Live, EventOdds, Results)
- Helpers: ServerTimeProvider, PeriodScopeMapper, OutcomeCodeMapper, MoscowDateParser
- UserAgentRotatorHandler + Polly v8 resilience pipeline
- ScrapingModule.AddMarathonScraping DI extension
- GlobalUsings.cs aliases for EventId / Configuration disambiguation
- Parser tests with trimmed HTML fixtures
- ScrapeResultsAsync interim no-op (Phase 8 will replace via watch-list polling)
Phase 5 (UI shell — killed mid-final-verify, assumed ~95%):
- Marathon.UI populated: MainLayout, App.razor, Pages (Home, Settings),
Components, Theme (MarathonTheme.cs + Tokens.cs + app.css), Resources
(SharedResource.{cs,ru.resx,en.resx}), Services (ISettingsWriter), wwwroot
- WPF host: App.xaml(.cs), MainWindow.xaml(.cs), Marathon.Hosts.WpfBlazor.csproj
with Microsoft.AspNetCore.Components.WebView.Wpf + MudBlazor + Serilog
- appsettings.json + appsettings.Development.json with all sections wired
- bUnit tests: MainLayoutTests, LocaleSwitcherTests, ThemeToggleTests,
JsonSettingsWriterTests + Support helpers
Cross-phase issues to resolve at next session:
1. Phase 2 repository classes are 'internal' — Phase 3's tests can't reference
them. Fix: add InternalsVisibleTo to Marathon.Infrastructure.csproj.
2. Phase 5: LocalizationOptions namespace ambiguity (AspNetCore vs Extensions).
3. Phase 5: WpfBlazor Serilog API mismatch.
Reviewer has NOT run on this batch. Move to Phase 4 only after build is green
and a combined parallel-batch reviewer passes.
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
using Marathon.Domain.Entities;
|
||||
using Marathon.Domain.Enums;
|
||||
using Marathon.Domain.ValueObjects;
|
||||
using Marathon.Infrastructure.Persistence.Entities;
|
||||
|
||||
namespace Marathon.Infrastructure.Persistence;
|
||||
|
||||
/// <summary>
|
||||
/// Mapping helpers that translate between domain objects and EF Core persistence entities.
|
||||
/// Domain invariants are enforced on the domain side; mapping is purely structural.
|
||||
/// </summary>
|
||||
internal static class Mapping
|
||||
{
|
||||
// ─── Event ───────────────────────────────────────────────────────────────
|
||||
|
||||
public static EventEntity ToEntity(Event domain) =>
|
||||
new()
|
||||
{
|
||||
EventCode = domain.Id.Value,
|
||||
SportCode = domain.Sport.Value,
|
||||
CountryCode = domain.CountryCode,
|
||||
LeagueId = domain.LeagueId,
|
||||
Category = domain.Category,
|
||||
ScheduledAt = domain.ScheduledAt.ToString("O"),
|
||||
Side1Name = domain.Side1Name,
|
||||
Side2Name = domain.Side2Name,
|
||||
};
|
||||
|
||||
public static Event ToDomain(EventEntity entity) =>
|
||||
new(
|
||||
Id: new EventId(entity.EventCode),
|
||||
Sport: new SportCode(entity.SportCode),
|
||||
CountryCode: entity.CountryCode,
|
||||
LeagueId: entity.LeagueId,
|
||||
Category: entity.Category,
|
||||
ScheduledAt: DateTimeOffset.Parse(entity.ScheduledAt),
|
||||
Side1Name: entity.Side1Name,
|
||||
Side2Name: entity.Side2Name);
|
||||
|
||||
// ─── OddsSnapshot ─────────────────────────────────────────────────────────
|
||||
|
||||
public static SnapshotEntity ToEntity(OddsSnapshot domain) =>
|
||||
new()
|
||||
{
|
||||
EventCode = domain.EventId.Value,
|
||||
CapturedAt = domain.CapturedAt.ToString("O"),
|
||||
Source = (int)domain.Source,
|
||||
Bets = domain.Bets.Select(ToEntity).ToList(),
|
||||
};
|
||||
|
||||
public static OddsSnapshot ToDomain(SnapshotEntity entity) =>
|
||||
new(
|
||||
eventId: new EventId(entity.EventCode),
|
||||
capturedAt: DateTimeOffset.Parse(entity.CapturedAt),
|
||||
source: (OddsSource)entity.Source,
|
||||
bets: entity.Bets.Select(ToDomain).ToList().AsReadOnly());
|
||||
|
||||
// ─── Bet ──────────────────────────────────────────────────────────────────
|
||||
|
||||
public static BetEntity ToEntity(Bet domain) =>
|
||||
new()
|
||||
{
|
||||
Scope = domain.Scope is MatchScope ? 0 : 1,
|
||||
PeriodNumber = domain.Scope is PeriodScope ps ? ps.Number : null,
|
||||
Type = (int)domain.Type,
|
||||
Side = (int)domain.Side,
|
||||
Value = domain.Value?.Value,
|
||||
Rate = domain.Rate.Value,
|
||||
};
|
||||
|
||||
public static Bet ToDomain(BetEntity entity)
|
||||
{
|
||||
var scope = entity.Scope switch
|
||||
{
|
||||
0 => (BetScope)MatchScope.Instance,
|
||||
1 => new PeriodScope(entity.PeriodNumber!.Value),
|
||||
_ => throw new InvalidOperationException(
|
||||
$"Unknown BetScope discriminator: {entity.Scope}"),
|
||||
};
|
||||
|
||||
var value = entity.Value.HasValue ? new OddsValue(entity.Value.Value) : null;
|
||||
var rate = new OddsRate(entity.Rate);
|
||||
var type = (BetType)entity.Type;
|
||||
var side = (Side)entity.Side;
|
||||
|
||||
return new Bet(scope, type, side, value, rate);
|
||||
}
|
||||
|
||||
// ─── EventResult ──────────────────────────────────────────────────────────
|
||||
|
||||
public static EventResultEntity ToEntity(EventResult domain) =>
|
||||
new()
|
||||
{
|
||||
EventCode = domain.EventId.Value,
|
||||
Side1Score = domain.Side1Score,
|
||||
Side2Score = domain.Side2Score,
|
||||
WinnerSide = (int)domain.WinnerSide,
|
||||
CompletedAt = domain.CompletedAt.ToString("O"),
|
||||
};
|
||||
|
||||
public static EventResult ToDomain(EventResultEntity entity) =>
|
||||
new(
|
||||
EventId: new EventId(entity.EventCode),
|
||||
Side1Score: entity.Side1Score,
|
||||
Side2Score: entity.Side2Score,
|
||||
WinnerSide: (Side)entity.WinnerSide,
|
||||
CompletedAt: DateTimeOffset.Parse(entity.CompletedAt));
|
||||
|
||||
// ─── Anomaly ──────────────────────────────────────────────────────────────
|
||||
|
||||
public static AnomalyEntity ToEntity(Anomaly domain) =>
|
||||
new()
|
||||
{
|
||||
Id = domain.Id.ToString(),
|
||||
EventCode = domain.EventId.Value,
|
||||
DetectedAt = domain.DetectedAt.ToString("O"),
|
||||
Kind = (int)domain.Kind,
|
||||
Score = domain.Score,
|
||||
EvidenceJson = domain.EvidenceJson,
|
||||
};
|
||||
|
||||
public static Anomaly ToDomain(AnomalyEntity entity) =>
|
||||
new(
|
||||
Id: Guid.Parse(entity.Id),
|
||||
EventId: new EventId(entity.EventCode),
|
||||
DetectedAt: DateTimeOffset.Parse(entity.DetectedAt),
|
||||
Kind: (AnomalyKind)entity.Kind,
|
||||
Score: entity.Score,
|
||||
EvidenceJson: entity.EvidenceJson);
|
||||
|
||||
// ─── Sport ────────────────────────────────────────────────────────────────
|
||||
|
||||
public static SportEntity ToEntity(Sport domain) =>
|
||||
new()
|
||||
{
|
||||
Code = domain.Code.Value,
|
||||
NameRu = domain.NameRu,
|
||||
NameEn = domain.NameEn,
|
||||
};
|
||||
|
||||
public static Sport ToDomain(SportEntity entity) =>
|
||||
new(
|
||||
Code: new SportCode(entity.Code),
|
||||
NameRu: entity.NameRu,
|
||||
NameEn: entity.NameEn);
|
||||
|
||||
// ─── League ───────────────────────────────────────────────────────────────
|
||||
|
||||
public static LeagueEntity ToEntity(League domain) =>
|
||||
new()
|
||||
{
|
||||
Id = domain.Id,
|
||||
SportCode = domain.Sport.Value,
|
||||
Country = domain.Country,
|
||||
NameRu = domain.NameRu,
|
||||
NameEn = domain.NameEn,
|
||||
Category = domain.Category,
|
||||
};
|
||||
|
||||
public static League ToDomain(LeagueEntity entity) =>
|
||||
new(
|
||||
Id: entity.Id,
|
||||
Sport: new SportCode(entity.SportCode),
|
||||
Country: entity.Country,
|
||||
NameRu: entity.NameRu,
|
||||
NameEn: entity.NameEn,
|
||||
Category: entity.Category);
|
||||
}
|
||||
Reference in New Issue
Block a user