From e460cd590570493d9129af110dc1407e7bb75b39 Mon Sep 17 00:00:00 2001 From: Gulum Date: Sun, 21 Jun 2026 21:57:40 +0200 Subject: [PATCH] feat(import): resolve color variety ID mappings mismatch, support unnamed parents in virtual litters, and implement SaleContract updates --- GerbilManager.Tests/GerbilStatusTests.cs | 16 +- GerbilManagerWebAPI/Contracts/ContractData.cs | 5 +- .../Contracts/ContractPdfGenerator.cs | 241 +++ GerbilManagerWebAPI/Dtos/ApiDtos.cs | 4 +- GerbilManagerWebAPI/Dtos/ContractDtos.cs | 4 +- .../Endpoints/ContractEndpoints.cs | 79 +- .../GerbilManagerWebAPI.csproj | 1 + .../Import/ImportDocxService.cs | 3 +- GerbilManagerWebAPI/Import/ImportService.cs | 10 +- .../Import/IngestResolvedService.cs | 9 +- ...3114528_MakeLitterDateNullable.Designer.cs | 1491 ++++++++++++++++ .../20260613114528_MakeLitterDateNullable.cs | 37 + ...3120908_AddContractAnimalPhoto.Designer.cs | 1494 +++++++++++++++++ .../20260613120908_AddContractAnimalPhoto.cs | 29 + .../ApplicationContextModelSnapshot.cs | 5 +- GerbilManagerWebAPI/Models/Litter.cs | 2 +- GerbilManagerWebAPI/Models/SaleContract.cs | 4 + .../Services/GerbilStatusService.cs | 2 +- gerbil-manager-web/src/api/contracts.ts | 7 + gerbil-manager-web/src/pages/GerbilsPage.tsx | Bin 14346 -> 15240 bytes .../src/pages/VertraegeListPage.tsx | 5 +- .../src/pages/VertragWizardPage.tsx | 75 +- .../src/pages/vertragWizard.css | 47 + gerbil-manager-web/src/strings/de.ts | 8 +- tools/import/extract.py | 7 +- tools/import/merge_and_resolve.py | 167 +- tools/import/output/review-report.md | 2 +- tools/import/resolve_import.py | 37 +- tools/import/test_extract.py | 59 + 29 files changed, 3783 insertions(+), 67 deletions(-) create mode 100644 GerbilManagerWebAPI/Contracts/ContractPdfGenerator.cs create mode 100644 GerbilManagerWebAPI/Migrations/20260613114528_MakeLitterDateNullable.Designer.cs create mode 100644 GerbilManagerWebAPI/Migrations/20260613114528_MakeLitterDateNullable.cs create mode 100644 GerbilManagerWebAPI/Migrations/20260613120908_AddContractAnimalPhoto.Designer.cs create mode 100644 GerbilManagerWebAPI/Migrations/20260613120908_AddContractAnimalPhoto.cs diff --git a/GerbilManager.Tests/GerbilStatusTests.cs b/GerbilManager.Tests/GerbilStatusTests.cs index 7101b33..173ca73 100644 --- a/GerbilManager.Tests/GerbilStatusTests.cs +++ b/GerbilManager.Tests/GerbilStatusTests.cs @@ -38,9 +38,9 @@ public class GerbilStatusTests Assert.Equal(GerbilStatus.GivenAway, status); } - // 3) Age > 7y, no death, not abgegeben → Deceased (presumed) + // 3) Age > 6y, no death, not abgegeben → Deceased (presumed) [Fact] - public void OlderThan7y_without_death_returns_Deceased() + public void OlderThan6y_without_death_returns_Deceased() { var dob = Today.AddYears(-GerbilStatusService.MaxAgeYears).AddDays(-1); // 1 day past threshold var status = GerbilStatusService.Derive( @@ -48,14 +48,14 @@ public class GerbilStatusTests Assert.Equal(GerbilStatus.Deceased, status); } - // Exactly 7 years old is NOT presumed dead (threshold is strictly >) + // Exactly 6 years old is NOT presumed dead (threshold is strictly >) [Fact] public void ExactlyMaxAge_is_not_Deceased() { - var dob = Today.AddYears(-GerbilStatusService.MaxAgeYears); // exactly 7y today + var dob = Today.AddYears(-GerbilStatusService.MaxAgeYears); // exactly 6y today var status = GerbilStatusService.Derive( GerbilStatus.Breeding, dob, dateOfDeath: null, isAbgegeben: false, Today); - // today >= dob.AddYears(7) → exactly equal → IS presumed dead + // today >= dob.AddYears(6) → exactly equal → IS presumed dead // (threshold = "older than" so >= means Deceased) Assert.Equal(GerbilStatus.Deceased, status); } @@ -70,11 +70,11 @@ public class GerbilStatusTests Assert.Equal(GerbilStatus.Breeding, status); } - // 3a) Age > 7y but Abgegeben → stays GivenAway (not Deceased) + // 3a) Age > 6y but Abgegeben → stays GivenAway (not Deceased) [Fact] - public void OlderThan7y_but_Abgegeben_stays_GivenAway() + public void OlderThan6y_but_Abgegeben_stays_GivenAway() { - var dob = Today.AddYears(-8); + var dob = Today.AddYears(-7); var status = GerbilStatusService.Derive( GerbilStatus.GivenAway, dob, dateOfDeath: null, isAbgegeben: true, Today); Assert.Equal(GerbilStatus.GivenAway, status); diff --git a/GerbilManagerWebAPI/Contracts/ContractData.cs b/GerbilManagerWebAPI/Contracts/ContractData.cs index 3c19e97..a18a6ba 100644 --- a/GerbilManagerWebAPI/Contracts/ContractData.cs +++ b/GerbilManagerWebAPI/Contracts/ContractData.cs @@ -13,11 +13,14 @@ public sealed record ContractBuyer( /// Deutscher Anzeigetext („Weiblich“/„Männlich“) — die /// Abbildung vom Gender-Enum passiert im Aufrufer (Phase B), der /// Generator bleibt frei von Modell-Abhängigkeiten. +/// Optionales Tierfoto (Rohbytes der Bilddatei) fürs Vertragsbild; +/// nur der PDF-Generator wertet es aus, der .docx-Generator ignoriert es. public sealed record ContractAnimal( string Name, string Geschlecht, DateOnly? Geburtsdatum = null, - string? Farbschlag = null); + string? Farbschlag = null, + byte[]? Photo = null); /// /// Alle Eingaben des Vertragsgenerators. Reines Daten-Objekt, keine EF-Typen. diff --git a/GerbilManagerWebAPI/Contracts/ContractPdfGenerator.cs b/GerbilManagerWebAPI/Contracts/ContractPdfGenerator.cs new file mode 100644 index 0000000..faa7e4b --- /dev/null +++ b/GerbilManagerWebAPI/Contracts/ContractPdfGenerator.cs @@ -0,0 +1,241 @@ +using System.Globalization; +using QuestPDF.Fluent; +using QuestPDF.Helpers; +using QuestPDF.Infrastructure; + +namespace GerbilManagerWebAPI.Contracts; + +/// +/// FEAT-13 (PDF): erzeugt den Abgabevertrag als druckfertiges PDF (A4) aus +/// — gleiche Daten wie der .docx-Generator, reiner +/// .NET-Code (QuestPDF), keine externen Konverter. Der Fließtext der Abschnitte +/// 4–8 entspricht dem Mustervertrag (Vorlage Abgabevertrag.docx). +/// +public static class ContractPdfGenerator +{ + static ContractPdfGenerator() + { + // QuestPDF Community License (kostenlos für Einzelpersonen / kleine Firmen). + QuestPDF.Settings.License = LicenseType.Community; + } + + private static readonly CultureInfo German = CultureInfo.GetCultureInfo("de-DE"); + private static string Price(decimal p) => p.ToString("N2", German) + " €"; + private static string D(DateOnly d) => d.ToString("dd.MM.yyyy", German); + private static string Or(string? v, string fallback = "—") => string.IsNullOrWhiteSpace(v) ? fallback : v!; + + private const string Accent = "#A85F2E"; + private const string Ink = "#3D2E23"; + private const string Line = "#D9CCB4"; + + public static byte[] Generate(ContractData data) + { + ArgumentNullException.ThrowIfNull(data); + + return Document.Create(doc => + { + doc.Page(page => + { + page.Size(PageSizes.A4); + page.Margin(1.8f, Unit.Centimetre); + page.DefaultTextStyle(x => x.FontSize(9.5f).FontColor(Ink).LineHeight(1.25f)); + + page.Header().PaddingBottom(8).Column(h => + { + h.Item().Text("Schutzvertrag / Kaufvertrag").FontSize(18).Bold().FontColor(Accent); + h.Item().Text("Mongolische Rennmäuse").FontSize(10).FontColor("#8C7F6E"); + }); + + page.Content().PaddingTop(6).Column(col => + { + col.Spacing(12); + Parties(col, data); + Animals(col, data); + Subject(col, data); + Clauses(col); + Signatures(col, data); + }); + + page.Footer().AlignCenter().Text(t => + { + t.DefaultTextStyle(x => x.FontSize(8).FontColor("#8C7F6E")); + t.Span("Seite "); + t.CurrentPageNumber(); + t.Span(" / "); + t.TotalPages(); + }); + }); + }).GeneratePdf(); + } + + private static void Heading(ColumnDescriptor col, string text) => + col.Item().PaddingTop(4).Text(text).FontSize(12).Bold().FontColor(Accent); + + private static void Kv(ColumnDescriptor col, string label, string value) => + col.Item().Row(r => + { + r.ConstantItem(150).Text(label).FontColor("#8C7F6E"); + r.RelativeItem().Text(value).SemiBold(); + }); + + private static void Bullet(ColumnDescriptor col, string text) => + col.Item().Row(r => + { + r.ConstantItem(14).Text("•").FontColor(Accent); + r.RelativeItem().Text(text); + }); + + private static void Parties(ColumnDescriptor col, ContractData data) + { + var s = data.Seller; + var b = data.Buyer; + Heading(col, "1. Vertragspartner"); + col.Item().Text("Verkäufer / Züchter").SemiBold(); + col.Item().Column(c => + { + c.Spacing(2); + Kv(c, "Zuchtname:", Or(s.ZuchtName)); + Kv(c, "Vor- und Nachname:", Or(s.Name)); + Kv(c, "Adresse:", Or(s.Address)); + Kv(c, "Telefon:", Or(s.Phone, "")); + Kv(c, "E-Mail:", Or(s.Email, "")); + Kv(c, "Homepage:", Or(s.Homepage, "")); + }); + col.Item().PaddingTop(4).Text("Käufer / Abnehmer").SemiBold(); + col.Item().Column(c => + { + c.Spacing(2); + Kv(c, "Vor- und Nachname:", Or(b.Name)); + Kv(c, "Adresse:", Or(b.Address)); + Kv(c, "Telefon:", Or(b.Phone, "")); + Kv(c, "E-Mail:", Or(b.Email, "")); + }); + } + + private static void Animals(ColumnDescriptor col, ContractData data) + { + Heading(col, "2. Angaben zu den Tieren"); + col.Item().Column(list => + { + list.Spacing(10); + foreach (var a in data.Animals) + { + // Ein Block je Tier: links das (optionale) Foto, rechts die Stammdaten — + // wie im Mustervertrag (das große Rechteck links). + list.Item().Border(1).BorderColor(Line).Row(row => + { + row.RelativeItem(2f).MinHeight(150).BorderRight(1).BorderColor(Line) + .Padding(4).Element(box => + { + if (a.Photo is { Length: > 0 } bytes) + box.AlignMiddle().Image(bytes).FitArea(); + else + box.AlignMiddle().AlignCenter().Text("Kein Foto") + .FontSize(8).FontColor("#B8AC97"); + }); + + row.RelativeItem(3f).Column(kv => + { + AnimalRow(kv, "Name:", Or(a.Name, "")); + AnimalRow(kv, "Tierart:", "Mongolische Rennmaus"); + AnimalRow(kv, "Geschlecht:", Or(a.Geschlecht)); + AnimalRow(kv, "Geburtsdatum:", a.Geburtsdatum is { } born ? D(born) : "—"); + AnimalRow(kv, "Farbschlag:", Or(a.Farbschlag, ""), last: true); + }); + }); + } + }); + } + + private static void AnimalRow(ColumnDescriptor col, string label, string value, bool last = false) + { + var cell = col.Item(); + if (!last) cell = cell.BorderBottom(1).BorderColor(Line); + cell.PaddingVertical(7).PaddingHorizontal(8).Row(r => + { + r.ConstantItem(100).Text(label).FontColor("#8C7F6E"); + r.RelativeItem().Text(value).SemiBold(); + }); + } + + private static void Subject(ColumnDescriptor col, ContractData data) + { + Heading(col, "3. Gegenstand des Vertrages"); + col.Item().Text( + $"Der Züchter verkauft dem Käufer mit Unterzeichnung des vorliegenden Vertrages die oben " + + $"erwähnten Tiere zu einem Kaufpreis von {Price(data.Price)}. Der Kaufpreis ist bei Übergabe " + + $"der Tiere vollständig bezahlt worden. Die Tiere wurden am {D(data.HandoverDate)} dem Käufer " + + $"von dem Züchter übergeben."); + } + + private static void Clauses(ColumnDescriptor col) + { + Heading(col, "4. Einverständniserklärung zur Erhebung personenbezogener Daten"); + col.Item().Text( + "Der Käufer stimmt der Erhebung und der Verarbeitung seiner oben aufgeführten Daten durch den " + + "Verkäufer zu. Diese werden von dem Züchter vertraulich im Rahmen seiner Zucht behandelt. Darüber " + + "hinaus benötigt es für jede weitere Datenerhebung die Zustimmung des Käufers. Der Abnehmer hat das " + + "Recht, diese Einwilligung jederzeit ohne Angabe einer Begründung zu widerrufen. Weiterhin können " + + "erhobene Daten bei Bedarf korrigiert, gelöscht oder deren Erhebung eingeschränkt werden."); + + Heading(col, "5. Pflichten des Käufers"); + col.Item().Text( + "Tiere sind keine Sache, sondern empfindungs- und leidensfähige Lebewesen. Der Abnehmer ist sich " + + "seiner hohen Verantwortung bewusst und übernimmt folgende Pflichten:"); + col.Item().Column(c => + { + c.Spacing(3); + Bullet(c, "Der Käufer verpflichtet sich, die Tiere artgerecht zu halten, zu füttern und zu pflegen. Er verpflichtet sich, die stets aktuellen Vorschriften des Tierschutzgesetzes einzuhalten. Die schriftlichen Anweisungen des Züchters über Haltung, Pflege und Unterkunft der Tiere sind zu befolgen."); + Bullet(c, "Der Abnehmer verpflichtet sich, die Tiere in Krankheitsfällen oder bei Anzeichen auf diese unverzüglich veterinärmedizinisch behandeln zu lassen. Die Tiere dürfen nicht ohne zwingende veterinärmedizinische Gründe euthanasiert werden."); + Bullet(c, "Dem Käufer ist eine Weitergabe der Tiere ohne die Zustimmung des Züchters nicht gestattet. Eine Abgabe an ein Tierheim oder eine Auffangstation ist ohne vorherige Absprache untersagt."); + Bullet(c, "Der Abnehmer verpflichtet sich, die Tiere niemals zu misshandeln, für Versuchszwecke oder als Zuchttier einzusetzen oder als Futtertier zu verwenden."); + Bullet(c, "Die Einzelhaltung der Tiere ist dem Käufer untersagt. Er verpflichtet sich im Falle eines einzelnen Tieres zur artgerechten Vergesellschaftung mit der Trenngitter-Methode."); + Bullet(c, "Der Käufer setzt den Verkäufer über das Versterben sowie die Todesursache der Tiere in Kenntnis."); + Bullet(c, "Ernsthafte Erkrankungen genetischer Ursache sind nach gestellter Diagnose unverzüglich dem Züchter zu melden."); + }); + + Heading(col, "6. Rechte des Käufers"); + col.Item().Column(c => + { + c.Spacing(3); + Bullet(c, "Der Käufer hat das Recht, den Züchter für die unentgeltliche Weitervermittlung der Tiere zu beauftragen. Dies schließt jedoch nicht die Aufnahme der Rennmäuse bei dem Züchter ein."); + Bullet(c, "Der Verkäufer steht dem Käufer für Fragen zur Tierhaltung zur Verfügung. Der Käufer kann diese Dienste in beschränktem Umfang unentgeltlich in Anspruch nehmen."); + Bullet(c, "Der Käufer hat das Recht, gegen Vorlage einer aktuellen negativen Kotuntersuchung den kostenpflichtigen Vergesellschaftungsservice für die Rennmaus in Anspruch zu nehmen."); + }); + + Heading(col, "7. Haftung / Zuwiderhandlung"); + col.Item().Column(c => + { + c.Spacing(3); + Bullet(c, "Bei Vertragsverstoß ist der Züchter berechtigt, den Vertrag fristlos zu kündigen."); + Bullet(c, "Im Falle des Verstoßes ist der Käufer zur entschädigungslosen Rückgabe der Tiere an den Züchter verpflichtet."); + Bullet(c, "Zur Sicherstellung der Käuferpflichten wird eine Vertragsstrafe in Höhe von 200,- € festgelegt."); + }); + + Heading(col, "8. Besondere Vereinbarungen / Bemerkungen"); + col.Item().Text( + "Mündliche Vereinbarungen haben keine Gültigkeit. Jede Änderung oder Ergänzung des Vertrages bedarf " + + "der Schriftform. Die Vertragsparteien verzichten auf jegliche Sachgewährleistungsansprüche. " + + "Gerichtsstand für beide Parteien ist der Wohnort des Züchters. Der Vertrag wird zweifach ausgefertigt " + + "und unterzeichnet. Käufer und Verkäufer erhalten je ein Exemplar. Mit der Unterschrift wird versichert, " + + "den Vertragsinhalt gelesen und akzeptiert zu haben und sich an diesen zu halten."); + } + + private static void Signatures(ColumnDescriptor col, ContractData data) + { + var ort = string.IsNullOrWhiteSpace(data.Seller.City) ? "" : data.Seller.City + ", "; + col.Item().PaddingTop(14).Text($"{ort}den {D(data.ContractDate ?? data.HandoverDate)}"); + col.Item().PaddingTop(28).Row(r => + { + r.RelativeItem().Column(c => + { + c.Item().BorderTop(1).BorderColor(Ink).PaddingTop(4).Text("Unterschrift des Verkäufers"); + }); + r.ConstantItem(40); + r.RelativeItem().Column(c => + { + c.Item().BorderTop(1).BorderColor(Ink).PaddingTop(4).Text("Unterschrift des Käufers"); + }); + }); + } +} diff --git a/GerbilManagerWebAPI/Dtos/ApiDtos.cs b/GerbilManagerWebAPI/Dtos/ApiDtos.cs index 55eda6a..74281f0 100644 --- a/GerbilManagerWebAPI/Dtos/ApiDtos.cs +++ b/GerbilManagerWebAPI/Dtos/ApiDtos.cs @@ -37,7 +37,7 @@ namespace GerbilManagerWebAPI.Dtos public record LitterDto( Guid Id, string Name, - DateOnly Date, + DateOnly? Date, int? TotalBorn, int? DeathsWithin8Weeks, Guid? FatherId, @@ -89,7 +89,7 @@ namespace GerbilManagerWebAPI.Dtos public record LitterInput( string Name, - DateOnly Date, + DateOnly? Date, int? TotalBorn, int? DeathsWithin8Weeks, Guid? FatherId, diff --git a/GerbilManagerWebAPI/Dtos/ContractDtos.cs b/GerbilManagerWebAPI/Dtos/ContractDtos.cs index c8998a0..afce2d6 100644 --- a/GerbilManagerWebAPI/Dtos/ContractDtos.cs +++ b/GerbilManagerWebAPI/Dtos/ContractDtos.cs @@ -19,7 +19,9 @@ namespace GerbilManagerWebAPI.Dtos List GerbilIds, decimal Price, DateOnly HandoverDate, - DateOnly? ContractDate); + DateOnly? ContractDate, + // Optionales Tierfoto je Tier (GerbilId -> GerbilPhoto-Id) fürs Vertragsbild. + Dictionary? AnimalPhotos = null); /// Zuchtprofil — Antwort UND Request-Body von /settings/breeder-profile. public record BreederProfileDto( diff --git a/GerbilManagerWebAPI/Endpoints/ContractEndpoints.cs b/GerbilManagerWebAPI/Endpoints/ContractEndpoints.cs index 9d49a99..6e0dbf7 100644 --- a/GerbilManagerWebAPI/Endpoints/ContractEndpoints.cs +++ b/GerbilManagerWebAPI/Endpoints/ContractEndpoints.cs @@ -23,6 +23,7 @@ namespace GerbilManagerWebAPI.Endpoints { private const string DocxContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; + private const string PdfContentType = "application/pdf"; public static IEndpointRouteBuilder MapContractEndpoints(this IEndpointRouteBuilder app) { @@ -50,6 +51,7 @@ namespace GerbilManagerWebAPI.Endpoints var errors = new Dictionary(); var gerbilIds = (input.GerbilIds ?? []).Distinct().ToList(); + var photoChoice = input.AnimalPhotos ?? []; if (gerbilIds.Count == 0) errors["gerbilIds"] = ["Mindestens ein Tier auswählen."]; if (input.Price < 0) @@ -100,7 +102,11 @@ namespace GerbilManagerWebAPI.Endpoints ContractDate = contractDate, FileName = fileName, CreatedAt = DateTimeOffset.UtcNow, - Animals = gerbilIds.Select(id => new SaleContractAnimal { GerbilId = id }).ToList(), + Animals = gerbilIds.Select(id => new SaleContractAnimal + { + GerbilId = id, + PhotoId = photoChoice.TryGetValue(id, out var pid) ? pid : null, + }).ToList(), }; db.SaleContracts.Add(entity); @@ -144,6 +150,49 @@ namespace GerbilManagerWebAPI.Endpoints return TypedResults.PhysicalFile(path, DocxContentType, download); }); + // GET /contracts/{id}/pdf — druckfertiges PDF, aus den (aktuellen) Daten regeneriert. + group.MapGet("/{id:guid}/pdf", async Task> ( + Guid id, ApplicationContext db, IConfiguration config, IWebHostEnvironment env) => + { + var c = await db.SaleContracts.AsNoTracking() + .Include(x => x.Contact) + .Include(x => x.Animals) + .FirstOrDefaultAsync(x => x.Id == id); + if (c is null || c.Contact is null) return TypedResults.NotFound(); + + var gerbilIds = c.Animals.Select(a => a.GerbilId).ToList(); + var gerbils = await db.Gerbils.AsNoTracking() + .Include(g => g.ColorVariety) + .Where(g => gerbilIds.Contains(g.Id)) + .ToListAsync(); + var settings = await db.BreederSettings.AsNoTracking() + .FirstOrDefaultAsync(s => s.Id == BreederSettings.SingletonId) + ?? new BreederSettings(); + + // Gewählte Vertragsfotos nachladen (Foto muss zum Tier gehören und die Datei + // existieren — sonst bleibt das Bild leer statt zu scheitern). + var photoByGerbil = c.Animals + .Where(a => a.PhotoId is not null) + .ToDictionary(a => a.GerbilId, a => a.PhotoId!.Value); + var photoBytes = await LoadAnimalPhotos(db, photoByGerbil, PhotoRoot(config, env)); + + var data = new ContractData( + Seller: ToSeller(settings), + Buyer: new ContractBuyer(c.Contact.Name, c.Contact.Address ?? "", c.Contact.Phone, c.Contact.Email), + Animals: gerbils + .Select(g => new ContractAnimal( + g.Name, GeschlechtText(g.Gender), g.DateOfBirth, g.ColorVariety?.Name, + photoBytes.GetValueOrDefault(g.Id))) + .ToList(), + Price: c.Price, + HandoverDate: c.HandoverDate, + ContractDate: c.ContractDate); + + var pdf = ContractPdfGenerator.Generate(data); + var download = $"Abgabevertrag_{c.ContractDate:yyyy-MM-dd}_{Sanitize(c.Contact.Name)}.pdf"; + return TypedResults.File(pdf, PdfContentType, download); + }); + // DELETE /contracts/{id} — Zeile + Datei; Tier-Status wird NICHT zurückgedreht // (das wäre Magie — Status korrigiert man am Tier selbst). group.MapDelete("/{id:guid}", async Task> ( @@ -166,6 +215,34 @@ namespace GerbilManagerWebAPI.Endpoints private static string ContractRoot(IConfiguration config, IWebHostEnvironment env) => config["Contracts:RootPath"] ?? Path.Combine(env.ContentRootPath, "contract-storage"); + /// Foto-Dateiroot (geteilt mit den Foto-Endpoints). + private static string PhotoRoot(IConfiguration config, IWebHostEnvironment env) => + config["Photos:RootPath"] ?? Path.Combine(env.ContentRootPath, "photo-storage"); + + /// Lädt die gewählten Vertragsfotos als Rohbytes (GerbilId -> Bytes). + /// Überspringt Fotos, die nicht zum Tier gehören oder deren Datei fehlt. + private static async Task> LoadAnimalPhotos( + ApplicationContext db, Dictionary photoByGerbil, string photoRoot) + { + var result = new Dictionary(); + if (photoByGerbil.Count == 0) return result; + + var photoIds = photoByGerbil.Values.ToList(); + var photos = await db.GerbilPhotos.AsNoTracking() + .Where(p => photoIds.Contains(p.Id)) + .ToListAsync(); + + foreach (var (gerbilId, photoId) in photoByGerbil) + { + var photo = photos.FirstOrDefault(p => p.Id == photoId && p.GerbilId == gerbilId); + if (photo is null) continue; + var path = Path.Combine(photoRoot, photo.FileName); + if (File.Exists(path)) + result[gerbilId] = await File.ReadAllBytesAsync(path); + } + return result; + } + private static BreederProfile ToSeller(BreederSettings s) => new() { ZuchtName = s.ZuchtName, diff --git a/GerbilManagerWebAPI/GerbilManagerWebAPI.csproj b/GerbilManagerWebAPI/GerbilManagerWebAPI.csproj index b9d9d35..8901b96 100644 --- a/GerbilManagerWebAPI/GerbilManagerWebAPI.csproj +++ b/GerbilManagerWebAPI/GerbilManagerWebAPI.csproj @@ -20,6 +20,7 @@ + diff --git a/GerbilManagerWebAPI/Import/ImportDocxService.cs b/GerbilManagerWebAPI/Import/ImportDocxService.cs index 96a00bf..f9d304e 100644 --- a/GerbilManagerWebAPI/Import/ImportDocxService.cs +++ b/GerbilManagerWebAPI/Import/ImportDocxService.cs @@ -81,7 +81,8 @@ namespace GerbilManagerWebAPI.Import .Select(l => new { l.Id, l.Date }) .ToListAsync(); var littersByDayNumber = littersInDb - .GroupBy(l => l.Date.DayNumber) + .Where(l => l.Date.HasValue) + .GroupBy(l => l.Date!.Value.DayNumber) .ToDictionary(g => g.Key, g => g.ToList()); // normalize(name)+litterDob → Gerbil snapshot (main-import enrich path) diff --git a/GerbilManagerWebAPI/Import/ImportService.cs b/GerbilManagerWebAPI/Import/ImportService.cs index db0b6fe..a97fd0c 100644 --- a/GerbilManagerWebAPI/Import/ImportService.cs +++ b/GerbilManagerWebAPI/Import/ImportService.cs @@ -83,7 +83,7 @@ namespace GerbilManagerWebAPI.Import var existingLitterData = await _db.Litters .Select(l => new { l.Name, l.Date, l.ExternalRef }).ToListAsync(); var existingLitterKeySet = existingLitterData - .Select(x => $"{x.Name}|{x.Date:yyyy-MM-dd}").ToHashSet(); + .Select(x => $"{x.Name}|{(x.Date.HasValue ? x.Date.Value.ToString("yyyy-MM-dd") : "")}").ToHashSet(); var existingLitterExtRefSet = existingLitterData .Where(x => x.ExternalRef != null) .Select(x => x.ExternalRef!).ToHashSet(); @@ -307,13 +307,13 @@ namespace GerbilManagerWebAPI.Import var litterByParentsDate = new Dictionary(); foreach (var l in existingLitterRows) { - litterByParentsDate[$"{l.FatherId}|{l.MotherId}|{l.Date:yyyy-MM-dd}"] = l.Id; + litterByParentsDate[$"{l.FatherId}|{l.MotherId}|{(l.Date.HasValue ? l.Date.Value.ToString("yyyy-MM-dd") : "")}"] = l.Id; litterParents[l.Id] = (l.FatherId, l.MotherId); } foreach (var sl in synthLitters.Values.ToList()) { - var reuseKey = $"{sl.Father}|{sl.Mother}|{sl.Date:yyyy-MM-dd}"; + var reuseKey = $"{sl.Father}|{sl.Mother}|{(sl.Date.HasValue ? sl.Date.Value.ToString("yyyy-MM-dd") : "")}"; if (litterByParentsDate.TryGetValue(reuseKey, out var existingId)) { // remap offspring to the existing litter; don't create a duplicate. @@ -329,8 +329,8 @@ namespace GerbilManagerWebAPI.Import _db.Litters.Add(new Litter { Id = sl.Id, - Name = $"Wurf (aus Diagramm) {sl.Date:yyyy-MM-dd}".Trim(), - Date = sl.Date ?? default, + Name = $"Wurf (aus Diagramm) {(sl.Date.HasValue ? sl.Date.Value.ToString("yyyy-MM-dd") : "")}".Trim(), + Date = sl.Date, FatherId = null, // deferred — applied after gerbils SaveChanges MotherId = null, // deferred — applied after gerbils SaveChanges Notes = $"aus Stammbaum-Diagramm abgeleitet (Konfidenz: {sl.Confidence})", diff --git a/GerbilManagerWebAPI/Import/IngestResolvedService.cs b/GerbilManagerWebAPI/Import/IngestResolvedService.cs index 604a7c8..14852f1 100644 --- a/GerbilManagerWebAPI/Import/IngestResolvedService.cs +++ b/GerbilManagerWebAPI/Import/IngestResolvedService.cs @@ -2,6 +2,7 @@ using System.Text.Json; using System.Text.Json.Serialization; using GerbilManagerWebAPI.Models; using Microsoft.EntityFrameworkCore; +using GerbilManagerWebAPI.Services; namespace GerbilManagerWebAPI.Import { @@ -61,6 +62,7 @@ namespace GerbilManagerWebAPI.Import _db.GerbilPhotos.RemoveRange(_db.GerbilPhotos); _db.WeightRecords.RemoveRange(_db.WeightRecords); _db.HealthRecords.RemoveRange(_db.HealthRecords); + _db.SaleContracts.RemoveRange(_db.SaleContracts); _db.Gerbils.RemoveRange(_db.Gerbils); _db.Litters.RemoveRange(_db.Litters); _db.Contacts.RemoveRange(_db.Contacts); @@ -79,6 +81,7 @@ namespace GerbilManagerWebAPI.Import await _db.GerbilPhotos.ExecuteDeleteAsync(); await _db.WeightRecords.ExecuteDeleteAsync(); await _db.HealthRecords.ExecuteDeleteAsync(); + await _db.SaleContracts.ExecuteDeleteAsync(); await _db.Gerbils.ExecuteDeleteAsync(); await _db.Litters.ExecuteDeleteAsync(); await _db.Contacts.ExecuteDeleteAsync(); @@ -137,7 +140,7 @@ namespace GerbilManagerWebAPI.Import var gerbilsToInsert = new List(); foreach (var g in data.Gerbils) { - gerbilsToInsert.Add(new Gerbil + var importedGerbil = new Gerbil { Id = g.Id, Name = g.Name, @@ -163,7 +166,9 @@ namespace GerbilManagerWebAPI.Import CharacterNote = g.CharacterNote, IsDeaf = g.IsDeaf, IsResident = g.IsResident - }); + }; + GerbilStatusService.Apply(importedGerbil, DateOnly.FromDateTime(DateTime.UtcNow)); + gerbilsToInsert.Add(importedGerbil); } _db.Gerbils.AddRange(gerbilsToInsert); await _db.SaveChangesAsync(); diff --git a/GerbilManagerWebAPI/Migrations/20260613114528_MakeLitterDateNullable.Designer.cs b/GerbilManagerWebAPI/Migrations/20260613114528_MakeLitterDateNullable.Designer.cs new file mode 100644 index 0000000..ce176a5 --- /dev/null +++ b/GerbilManagerWebAPI/Migrations/20260613114528_MakeLitterDateNullable.Designer.cs @@ -0,0 +1,1491 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace GerbilManagerWebAPI.Migrations +{ + [DbContext(typeof(ApplicationContext))] + [Migration("20260613114528_MakeLitterDateNullable")] + partial class MakeLitterDateNullable + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Block", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Data") + .IsRequired() + .HasColumnType("text"); + + b.Property("Order") + .HasColumnType("integer"); + + b.Property("PageId") + .HasColumnType("uuid"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("PageId"); + + b.ToTable("Blocks"); + + b.HasData( + new + { + Id = new Guid("51720002-0000-0000-0000-000000000001"), + Data = "{\"text\":\"Startseite\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000001"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000002"), + Data = "{\"text\":\"Über die Zucht\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000002"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000003"), + Data = "{\"text\":\"Abgabetiere\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000003"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000004"), + Data = "{\"text\":\"Abgabebedingungen\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000004"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000005"), + Data = "{\"text\":\"Farben & Genetik\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000005"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000006"), + Data = "{\"text\":\"Kontakt\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000006"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000010"), + Data = "{\"mode\":\"auto\",\"intro\":\"\"}", + Order = 1, + PageId = new Guid("51720001-0000-0000-0000-000000000003"), + Type = "AbgabetiereList" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000007"), + Data = "{\"text\":\"Impressum\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000007"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000070"), + Data = "{\"markdown\":\"**Angaben gemäß § 5 TMG**\\n\\nSeitenbetreiber: [Name und vollständige Adresse eintragen]\\n\\nE-Mail: [E-Mail-Adresse eintragen]\\n\\n---\\n\\n*Diese Seite wird vom Seitenbetreiber noch vervollständigt.*\"}", + Order = 1, + PageId = new Guid("51720001-0000-0000-0000-000000000007"), + Type = "RichText" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000008"), + Data = "{\"text\":\"Datenschutz\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000008"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000080"), + Data = "{\"markdown\":\"**Datenschutzerklärung**\\n\\nDiese Webseite dient der Vorstellung unserer Rennmauszucht. Es werden keine personenbezogenen Daten gespeichert oder weitergegeben.\\n\\nBei datenschutzbezogenen Fragen: [E-Mail-Adresse eintragen]\\n\\n---\\n\\n*Diese Seite wird vom Seitenbetreiber noch vervollständigt.*\"}", + Order = 1, + PageId = new Guid("51720001-0000-0000-0000-000000000008"), + Type = "RichText" + }); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.BreederSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("City") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Homepage") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("NameSuffix") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("text"); + + b.Property("ZuchtName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("BreederSettings"); + + b.HasData( + new + { + Id = new Guid("11111111-1111-1111-1111-000000000001"), + Address = "", + City = "", + Email = "", + Homepage = "", + Name = "", + NameSuffix = "", + Phone = "", + ZuchtName = "" + }); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.ColorVariety", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CanonicalGenotype") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .UseCollation("de-x-icu"); + + b.Property("SortOrder") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("ColorVarieties"); + + b.HasData( + new + { + Id = new Guid("00000000-0000-0000-0000-000000000001"), + CanonicalGenotype = "AA chch DD EE GG pp spsp rere", + Name = "REW", + SortOrder = 0 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000002"), + CanonicalGenotype = "aa chch DD EE GG PP spsp rere", + Name = "Hermelin", + SortOrder = 1 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000003"), + CanonicalGenotype = "AA chch DD EE GG PP spsp rere", + Name = "Himalaya", + SortOrder = 2 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000004"), + CanonicalGenotype = "aa cchmcchm DD EE gg PP spsp rere", + Name = "Zobel", + SortOrder = 3 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000005"), + CanonicalGenotype = "AA CC DD efef GG pp spsp rere", + Name = "Rotaugenschimmel", + SortOrder = 4 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000006"), + CanonicalGenotype = "AA CC DD EE GG PP spsp rere", + Name = "Agouti", + SortOrder = 5 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000007"), + CanonicalGenotype = "aa CC DD EE GG PP spsp rere", + Name = "Schwarz", + SortOrder = 6 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000008"), + CanonicalGenotype = "AA CC DD EE gg PP spsp rere", + Name = "Silberagouti", + SortOrder = 7 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000009"), + CanonicalGenotype = "aa CC DD EE gg PP spsp rere", + Name = "Anthrazit", + SortOrder = 8 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000010"), + CanonicalGenotype = "AA CC DD ee GG PP spsp rere", + Name = "Algierfuchs", + SortOrder = 9 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000011"), + CanonicalGenotype = "aa CC dd EE GG PP spsp rere", + Name = "Blau", + SortOrder = 10 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000012"), + CanonicalGenotype = "AA CC DD EE GG pp spsp rere", + Name = "Gold", + SortOrder = 11 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000013"), + CanonicalGenotype = "aa CC DD EE GG pp spsp rere", + Name = "Platin", + SortOrder = 12 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000014"), + CanonicalGenotype = "AA CC DD ee GG pp spsp rere", + Name = "Goldfuchs", + SortOrder = 13 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000015"), + CanonicalGenotype = "aa CC DD ee GG pp spsp rere", + Name = "Rotfuchs", + SortOrder = 14 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000016"), + CanonicalGenotype = "AA CC dd EE GG pp spsp rere", + Name = "Dilute Gold", + SortOrder = 15 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000017"), + CanonicalGenotype = "aa CC dd EE GG pp spsp rere", + Name = "Dilute Platin", + SortOrder = 16 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000018"), + CanonicalGenotype = "aa CC DD EE gg pp spsp rere", + Name = "Altweiss (REW)", + SortOrder = 17 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000019"), + CanonicalGenotype = "AA CC DD ee gg pp spsp rere", + Name = "Apricot (Blassfuchs)", + SortOrder = 18 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000020"), + CanonicalGenotype = "aa CC DD ee gg PP spsp rere", + Name = "Blaufuchs", + SortOrder = 19 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000021"), + CanonicalGenotype = "aa CC DD ee gg pp spsp rere", + Name = "C-Separator", + SortOrder = 20 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000022"), + CanonicalGenotype = "AA CC DD EE gg pp spsp rere", + Name = "Elfenbein", + SortOrder = 21 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000023"), + CanonicalGenotype = "aa CC DD ee GG PP spsp rere", + Name = "Kohlfuchs", + SortOrder = 22 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000024"), + CanonicalGenotype = "AA CC DD ee gg PP spsp rere", + Name = "Polarfuchs", + SortOrder = 23 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000025"), + CanonicalGenotype = "aa CC DD EE GG pp spsp rere", + Name = "Saphir", + SortOrder = 24 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000026"), + CanonicalGenotype = "AA CC DD efef GG PP spsp rere", + Name = "Orangeschimmel", + SortOrder = 25 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000027"), + CanonicalGenotype = "AA CC DD EE GG pp spsp rere", + Name = "Topas", + SortOrder = 26 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000028"), + CanonicalGenotype = "aa CC DD EE GG pp spsp rere", + Name = "Platin-Hell", + SortOrder = 27 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000029"), + CanonicalGenotype = "AA CC dd EE GG PP spsp rere", + Name = "Dilute Agouti", + SortOrder = 28 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000030"), + CanonicalGenotype = "AA CC dd EE gg PP spsp rere", + Name = "Dilute Silberagouti", + SortOrder = 29 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000031"), + CanonicalGenotype = "aa CC dd ee GG PP spsp rere", + Name = "Dilute Kohlfuchs", + SortOrder = 30 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000032"), + CanonicalGenotype = "aa CC dd EE gg PP spsp rere", + Name = "Dilute Anthrazit", + SortOrder = 31 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000033"), + CanonicalGenotype = "AA CC DD efef gg PP spsp rere", + Name = "Silberschimmel", + SortOrder = 36 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000034"), + CanonicalGenotype = "AA CC DD efef gg PP spsp rere", + Name = "Polarfuchsschimmel", + SortOrder = 37 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000035"), + CanonicalGenotype = "AA CC DD efef GG PP spsp rere", + Name = "Algierfuchsschimmel", + SortOrder = 38 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000036"), + CanonicalGenotype = "aa CC DD efef GG PP spsp rere", + Name = "Kohlfuchsschimmel", + SortOrder = 39 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000037"), + CanonicalGenotype = "aa CC DD efef gg PP spsp rere", + Name = "Blaufuchsschimmel", + SortOrder = 40 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000038"), + CanonicalGenotype = "aa CC DD ee GG PP spsp rere", + Name = "Kohlfuchs, hell", + SortOrder = 41 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000039"), + CanonicalGenotype = "AA CC DD ee GG pp spsp rere", + Name = "Goldfuchs, hell", + SortOrder = 42 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000040"), + CanonicalGenotype = "AA CC DD efef GG pp spsp rere", + Name = "Goldfuchsschimmel", + SortOrder = 43 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000041"), + CanonicalGenotype = "AA CC DD EE GG pp spsp rere", + Name = "Gold-Hell", + SortOrder = 44 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000042"), + CanonicalGenotype = "aa CC DD ee gg PP spsp rere", + Name = "Blaufuchs, hell", + SortOrder = 45 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000043"), + CanonicalGenotype = "aa CC DD efef GG pp spsp rere", + Name = "Rotfuchsschimmel", + SortOrder = 46 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000044"), + CanonicalGenotype = "AA CC DD ee gg PP spsp rere", + Name = "Polarfuchs, hell", + SortOrder = 47 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000045"), + CanonicalGenotype = "aa CC DD efef GG PP spsp rere", + Name = "Kohlfuchsschimmel, hell", + SortOrder = 48 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000046"), + CanonicalGenotype = "aa CC DD ee GG pp spsp rere", + Name = "Rotfuchs, hell", + SortOrder = 49 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000047"), + CanonicalGenotype = "aa CC DD ee GG PP spsp rere", + Name = "Kohlfuchs-Hell", + SortOrder = 50 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000048"), + CanonicalGenotype = "AA CC DD ee GG PP spsp rere", + Name = "Algierfuchs, hell", + SortOrder = 51 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000049"), + CanonicalGenotype = "AA CC dd EE GG pp spsp rere", + Name = "Dilute Topas", + SortOrder = 52 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000050"), + CanonicalGenotype = "aa CC dd ee gg pp spsp rere", + Name = "Dilute Blaufuchs", + SortOrder = 53 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000051"), + CanonicalGenotype = "aa cchmcchm DD EE GG PP spsp rere", + Name = "Marder", + SortOrder = 54 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000052"), + CanonicalGenotype = "aa cchmch DD EE GG PP spsp rere", + Name = "Siam", + SortOrder = 55 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000053"), + CanonicalGenotype = "aa cchmch DD EE gg PP spsp rere", + Name = "Zobel-Hell", + SortOrder = 56 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000054"), + CanonicalGenotype = "AA cchmcchm DD EE GG PP spsp rere", + Name = "CP-Agouti", + SortOrder = 57 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000055"), + CanonicalGenotype = "AA cchmcchm DD EE gg PP spsp rere", + Name = "CP-Silberagouti", + SortOrder = 59 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000056"), + CanonicalGenotype = "AA cchmcchm DD ee GG PP spsp rere", + Name = "CP-Algierfuchs", + SortOrder = 61 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000057"), + CanonicalGenotype = "AA cchmcchm DD ee gg PP spsp rere", + Name = "CP-Polarfuchs", + SortOrder = 63 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000058"), + CanonicalGenotype = "AA cchmcchm dd ee GG PP spsp rere", + Name = "CP-Fuchs", + SortOrder = 65 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000059"), + CanonicalGenotype = "AA cchmch dd ee GG PP spsp rere", + Name = "CP-Fuchs-Hell", + SortOrder = 66 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000060"), + CanonicalGenotype = "AA cchmcchm dd ee gg PP spsp rere", + Name = "CP-Blaufuchs", + SortOrder = 67 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000061"), + CanonicalGenotype = "AA cchmcchm DD efef GG PP spsp rere", + Name = "CP-Orangeschimmel", + SortOrder = 68 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000062"), + CanonicalGenotype = "AA cchmch DD EE GG PP spsp rere", + Name = "CP-Agouti-Hell", + SortOrder = 58 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000063"), + CanonicalGenotype = "AA cchmch DD EE gg PP spsp rere", + Name = "CP-Silberagouti-Hell", + SortOrder = 60 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000064"), + CanonicalGenotype = "AA cchmch DD ee GG PP spsp rere", + Name = "CP-Algierfuchs-Hell", + SortOrder = 62 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000065"), + CanonicalGenotype = "AA cchmch DD ee gg PP spsp rere", + Name = "CP-Polarfuchs-Hell", + SortOrder = 64 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000066"), + CanonicalGenotype = "AA cchmch DD efef GG PP spsp rere", + Name = "CP-Orangeschimmel-Hell", + SortOrder = 69 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000067"), + CanonicalGenotype = "AA CC dd ee GG PP spsp rere", + Name = "Dilute Algierfuchs", + SortOrder = 32 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000068"), + CanonicalGenotype = "AA CC dd ee GG pp spsp rere", + Name = "Dilute Goldfuchs", + SortOrder = 33 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000069"), + CanonicalGenotype = "aa CC dd ee GG pp spsp rere", + Name = "Dilute Rotfuchs", + SortOrder = 34 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000070"), + CanonicalGenotype = "AA CC dd ee gg PP spsp rere", + Name = "Dilute Polarfuchs", + SortOrder = 35 + }); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Contact", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("IsBreeder") + .HasColumnType("boolean"); + + b.Property("IsReceiver") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .UseCollation("de-x-icu"); + + b.Property("NameSuffix") + .HasColumnType("text"); + + b.Property("Notes") + .HasColumnType("text"); + + b.Property("Phone") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Contacts"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Enclosure", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Notes") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Enclosures"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.EnclosurePhoto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Caption") + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EnclosureId") + .HasColumnType("uuid"); + + b.Property("FileName") + .IsRequired() + .HasColumnType("text"); + + b.Property("SortOrder") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("EnclosureId"); + + b.ToTable("EnclosurePhotos"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Gerbil", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CauseOfDeath") + .HasColumnType("text"); + + b.Property("CharacterNote") + .HasColumnType("text"); + + b.Property("CharacterTraits") + .IsRequired() + .HasColumnType("text"); + + b.Property("ColorVarietyId") + .HasColumnType("uuid"); + + b.Property("DateOfBirth") + .HasColumnType("date"); + + b.Property("DateOfDeath") + .HasColumnType("date"); + + b.Property("EnclosureId") + .HasColumnType("uuid"); + + b.Property("ExternalRef") + .HasColumnType("text"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("text"); + + b.Property("Genotype") + .HasColumnType("text"); + + b.Property("GoHomeDate") + .HasColumnType("date"); + + b.Property("ImportSource") + .HasColumnType("text"); + + b.Property("IsCastrated") + .HasColumnType("boolean"); + + b.Property("IsDeaf") + .HasColumnType("boolean"); + + b.Property("IsResident") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true); + + b.Property("LitterId") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .UseCollation("de-x-icu"); + + b.Property("NameSearch") + .HasColumnType("text") + .UseCollation("de-x-icu"); + + b.Property("Notes") + .HasColumnType("text"); + + b.Property("OriginBreeder") + .HasColumnType("text") + .UseCollation("de-x-icu"); + + b.Property("OriginContactId") + .HasColumnType("uuid"); + + b.Property("RawImportData") + .HasColumnType("text"); + + b.Property("ReceiverContactId") + .HasColumnType("uuid"); + + b.Property("SpottingType") + .HasColumnType("text"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ColorVarietyId"); + + b.HasIndex("EnclosureId"); + + b.HasIndex("ExternalRef") + .IsUnique() + .HasFilter("\"ExternalRef\" IS NOT NULL"); + + b.HasIndex("LitterId"); + + b.HasIndex("OriginContactId"); + + b.HasIndex("ReceiverContactId"); + + b.ToTable("Gerbils"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.GerbilPhoto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Caption") + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("FileName") + .IsRequired() + .HasColumnType("text"); + + b.Property("GerbilId") + .HasColumnType("uuid"); + + b.Property("SortOrder") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("GerbilId"); + + b.ToTable("GerbilPhotos"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.HealthRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("GerbilId") + .HasColumnType("uuid"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.Property("Veterinarian") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("GerbilId"); + + b.ToTable("HealthRecords"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Litter", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("DeathsWithin8Weeks") + .HasColumnType("integer"); + + b.Property("ExpectedGoHomeDate") + .HasColumnType("date"); + + b.Property("ExternalRef") + .HasColumnType("text"); + + b.Property("FatherId") + .HasColumnType("uuid"); + + b.Property("LitterLetter") + .HasColumnType("text"); + + b.Property("MotherId") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Notes") + .HasColumnType("text"); + + b.Property("PairingCode") + .HasColumnType("text"); + + b.Property("TotalBorn") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ExternalRef") + .IsUnique() + .HasFilter("\"ExternalRef\" IS NOT NULL"); + + b.HasIndex("FatherId"); + + b.HasIndex("MotherId"); + + b.ToTable("Litters"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.MailSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AppPasswordProtected") + .HasColumnType("text"); + + b.Property("BackgroundPollEnabled") + .HasColumnType("boolean"); + + b.Property("Folder") + .IsRequired() + .HasColumnType("text"); + + b.Property("GmailAddress") + .HasColumnType("text"); + + b.Property("LastUid") + .HasColumnType("bigint"); + + b.Property("PollIntervalMinutes") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("MailSettings"); + + b.HasData( + new + { + Id = new Guid("ab0c0000-0000-0000-0000-000000000001"), + BackgroundPollEnabled = false, + Folder = "INBOX", + LastUid = 0L, + PollIntervalMinutes = 15 + }); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Media", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Alt") + .HasColumnType("text"); + + b.Property("FileName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("Url") + .IsRequired() + .HasColumnType("text"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Media"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Page", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("SeoDescription") + .HasColumnType("text"); + + b.Property("Slug") + .IsRequired() + .HasColumnType("text"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("Slug") + .IsUnique(); + + b.ToTable("Pages"); + + b.HasData( + new + { + Id = new Guid("51720001-0000-0000-0000-000000000001"), + Slug = "start", + Status = "Published", + Title = "Startseite" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000002"), + Slug = "ueber-die-zucht", + Status = "Published", + Title = "Über die Zucht" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000003"), + Slug = "abgabetiere", + Status = "Published", + Title = "Abgabetiere" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000004"), + Slug = "abgabebedingungen", + Status = "Published", + Title = "Abgabebedingungen" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000005"), + Slug = "farben-genetik", + Status = "Published", + Title = "Farben & Genetik" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000006"), + Slug = "kontakt", + Status = "Published", + Title = "Kontakt" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000007"), + Slug = "impressum", + Status = "Published", + Title = "Impressum" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000008"), + Slug = "datenschutz", + Status = "Published", + Title = "Datenschutz" + }); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Request", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AnsweredAt") + .HasColumnType("timestamp with time zone"); + + b.Property("AssignedContactId") + .HasColumnType("uuid"); + + b.Property("BodyText") + .HasColumnType("text"); + + b.Property("DraftReply") + .HasColumnType("text"); + + b.Property("FromAddress") + .IsRequired() + .HasColumnType("text"); + + b.Property("FromName") + .HasColumnType("text"); + + b.Property("GmailMessageId") + .IsRequired() + .HasColumnType("text"); + + b.Property("InReplyToMessageId") + .HasColumnType("text"); + + b.Property("ReceivedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ReferencesHeader") + .HasColumnType("text"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text"); + + b.Property("Subject") + .HasColumnType("text"); + + b.Property("ThreadId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("AssignedContactId"); + + b.HasIndex("GmailMessageId") + .IsUnique(); + + b.ToTable("Requests"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.SaleContract", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ContactId") + .HasColumnType("uuid"); + + b.Property("ContractDate") + .HasColumnType("date"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("FileName") + .IsRequired() + .HasColumnType("text"); + + b.Property("HandoverDate") + .HasColumnType("date"); + + b.Property("Price") + .HasPrecision(10, 2) + .HasColumnType("numeric(10,2)"); + + b.HasKey("Id"); + + b.HasIndex("ContactId"); + + b.ToTable("SaleContracts"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.SaleContractAnimal", b => + { + b.Property("SaleContractId") + .HasColumnType("uuid"); + + b.Property("GerbilId") + .HasColumnType("uuid"); + + b.HasKey("SaleContractId", "GerbilId"); + + b.HasIndex("GerbilId"); + + b.ToTable("SaleContractAnimal"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Site", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DefaultLocale") + .IsRequired() + .HasColumnType("text"); + + b.Property("NavOrder") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Sites"); + + b.HasData( + new + { + Id = new Guid("5172e000-0000-0000-0000-000000000001"), + DefaultLocale = "de", + NavOrder = "[\"51720001-0000-0000-0000-000000000001\",\"51720001-0000-0000-0000-000000000002\",\"51720001-0000-0000-0000-000000000003\",\"51720001-0000-0000-0000-000000000004\",\"51720001-0000-0000-0000-000000000005\",\"51720001-0000-0000-0000-000000000006\"]" + }); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.WeightRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("GerbilId") + .HasColumnType("uuid"); + + b.Property("Notes") + .HasColumnType("text"); + + b.Property("WeightGrams") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("GerbilId"); + + b.ToTable("WeightRecords"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Block", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Page", null) + .WithMany("Blocks") + .HasForeignKey("PageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.EnclosurePhoto", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Enclosure", null) + .WithMany() + .HasForeignKey("EnclosureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Gerbil", b => + { + b.HasOne("GerbilManagerWebAPI.Models.ColorVariety", "ColorVariety") + .WithMany() + .HasForeignKey("ColorVarietyId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("GerbilManagerWebAPI.Models.Enclosure", "Enclosure") + .WithMany("Gerbils") + .HasForeignKey("EnclosureId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("GerbilManagerWebAPI.Models.Litter", "Litter") + .WithMany() + .HasForeignKey("LitterId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("GerbilManagerWebAPI.Models.Contact", "OriginContact") + .WithMany() + .HasForeignKey("OriginContactId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("GerbilManagerWebAPI.Models.Contact", "ReceiverContact") + .WithMany() + .HasForeignKey("ReceiverContactId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("ColorVariety"); + + b.Navigation("Enclosure"); + + b.Navigation("Litter"); + + b.Navigation("OriginContact"); + + b.Navigation("ReceiverContact"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.GerbilPhoto", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Gerbil", null) + .WithMany() + .HasForeignKey("GerbilId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.HealthRecord", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Gerbil", null) + .WithMany() + .HasForeignKey("GerbilId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Litter", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Gerbil", "Father") + .WithMany() + .HasForeignKey("FatherId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("GerbilManagerWebAPI.Models.Gerbil", "Mother") + .WithMany() + .HasForeignKey("MotherId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Father"); + + b.Navigation("Mother"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Request", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Contact", "AssignedContact") + .WithMany() + .HasForeignKey("AssignedContactId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("AssignedContact"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.SaleContract", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Contact", "Contact") + .WithMany() + .HasForeignKey("ContactId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Contact"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.SaleContractAnimal", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Gerbil", "Gerbil") + .WithMany() + .HasForeignKey("GerbilId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GerbilManagerWebAPI.Models.SaleContract", null) + .WithMany("Animals") + .HasForeignKey("SaleContractId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Gerbil"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.WeightRecord", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Gerbil", null) + .WithMany() + .HasForeignKey("GerbilId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Enclosure", b => + { + b.Navigation("Gerbils"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Page", b => + { + b.Navigation("Blocks"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.SaleContract", b => + { + b.Navigation("Animals"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/GerbilManagerWebAPI/Migrations/20260613114528_MakeLitterDateNullable.cs b/GerbilManagerWebAPI/Migrations/20260613114528_MakeLitterDateNullable.cs new file mode 100644 index 0000000..092b542 --- /dev/null +++ b/GerbilManagerWebAPI/Migrations/20260613114528_MakeLitterDateNullable.cs @@ -0,0 +1,37 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace GerbilManagerWebAPI.Migrations +{ + /// + public partial class MakeLitterDateNullable : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Date", + table: "Litters", + type: "date", + nullable: true, + oldClrType: typeof(DateOnly), + oldType: "date"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Date", + table: "Litters", + type: "date", + nullable: false, + defaultValue: new DateOnly(1, 1, 1), + oldClrType: typeof(DateOnly), + oldType: "date", + oldNullable: true); + } + } +} diff --git a/GerbilManagerWebAPI/Migrations/20260613120908_AddContractAnimalPhoto.Designer.cs b/GerbilManagerWebAPI/Migrations/20260613120908_AddContractAnimalPhoto.Designer.cs new file mode 100644 index 0000000..8dff225 --- /dev/null +++ b/GerbilManagerWebAPI/Migrations/20260613120908_AddContractAnimalPhoto.Designer.cs @@ -0,0 +1,1494 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace GerbilManagerWebAPI.Migrations +{ + [DbContext(typeof(ApplicationContext))] + [Migration("20260613120908_AddContractAnimalPhoto")] + partial class AddContractAnimalPhoto + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Block", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Data") + .IsRequired() + .HasColumnType("text"); + + b.Property("Order") + .HasColumnType("integer"); + + b.Property("PageId") + .HasColumnType("uuid"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("PageId"); + + b.ToTable("Blocks"); + + b.HasData( + new + { + Id = new Guid("51720002-0000-0000-0000-000000000001"), + Data = "{\"text\":\"Startseite\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000001"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000002"), + Data = "{\"text\":\"Über die Zucht\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000002"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000003"), + Data = "{\"text\":\"Abgabetiere\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000003"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000004"), + Data = "{\"text\":\"Abgabebedingungen\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000004"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000005"), + Data = "{\"text\":\"Farben & Genetik\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000005"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000006"), + Data = "{\"text\":\"Kontakt\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000006"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000010"), + Data = "{\"mode\":\"auto\",\"intro\":\"\"}", + Order = 1, + PageId = new Guid("51720001-0000-0000-0000-000000000003"), + Type = "AbgabetiereList" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000007"), + Data = "{\"text\":\"Impressum\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000007"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000070"), + Data = "{\"markdown\":\"**Angaben gemäß § 5 TMG**\\n\\nSeitenbetreiber: [Name und vollständige Adresse eintragen]\\n\\nE-Mail: [E-Mail-Adresse eintragen]\\n\\n---\\n\\n*Diese Seite wird vom Seitenbetreiber noch vervollständigt.*\"}", + Order = 1, + PageId = new Guid("51720001-0000-0000-0000-000000000007"), + Type = "RichText" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000008"), + Data = "{\"text\":\"Datenschutz\",\"level\":1}", + Order = 0, + PageId = new Guid("51720001-0000-0000-0000-000000000008"), + Type = "Heading" + }, + new + { + Id = new Guid("51720002-0000-0000-0000-000000000080"), + Data = "{\"markdown\":\"**Datenschutzerklärung**\\n\\nDiese Webseite dient der Vorstellung unserer Rennmauszucht. Es werden keine personenbezogenen Daten gespeichert oder weitergegeben.\\n\\nBei datenschutzbezogenen Fragen: [E-Mail-Adresse eintragen]\\n\\n---\\n\\n*Diese Seite wird vom Seitenbetreiber noch vervollständigt.*\"}", + Order = 1, + PageId = new Guid("51720001-0000-0000-0000-000000000008"), + Type = "RichText" + }); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.BreederSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("City") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Homepage") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("NameSuffix") + .IsRequired() + .HasColumnType("text"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("text"); + + b.Property("ZuchtName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("BreederSettings"); + + b.HasData( + new + { + Id = new Guid("11111111-1111-1111-1111-000000000001"), + Address = "", + City = "", + Email = "", + Homepage = "", + Name = "", + NameSuffix = "", + Phone = "", + ZuchtName = "" + }); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.ColorVariety", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CanonicalGenotype") + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .UseCollation("de-x-icu"); + + b.Property("SortOrder") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("ColorVarieties"); + + b.HasData( + new + { + Id = new Guid("00000000-0000-0000-0000-000000000001"), + CanonicalGenotype = "AA chch DD EE GG pp spsp rere", + Name = "REW", + SortOrder = 0 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000002"), + CanonicalGenotype = "aa chch DD EE GG PP spsp rere", + Name = "Hermelin", + SortOrder = 1 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000003"), + CanonicalGenotype = "AA chch DD EE GG PP spsp rere", + Name = "Himalaya", + SortOrder = 2 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000004"), + CanonicalGenotype = "aa cchmcchm DD EE gg PP spsp rere", + Name = "Zobel", + SortOrder = 3 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000005"), + CanonicalGenotype = "AA CC DD efef GG pp spsp rere", + Name = "Rotaugenschimmel", + SortOrder = 4 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000006"), + CanonicalGenotype = "AA CC DD EE GG PP spsp rere", + Name = "Agouti", + SortOrder = 5 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000007"), + CanonicalGenotype = "aa CC DD EE GG PP spsp rere", + Name = "Schwarz", + SortOrder = 6 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000008"), + CanonicalGenotype = "AA CC DD EE gg PP spsp rere", + Name = "Silberagouti", + SortOrder = 7 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000009"), + CanonicalGenotype = "aa CC DD EE gg PP spsp rere", + Name = "Anthrazit", + SortOrder = 8 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000010"), + CanonicalGenotype = "AA CC DD ee GG PP spsp rere", + Name = "Algierfuchs", + SortOrder = 9 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000011"), + CanonicalGenotype = "aa CC dd EE GG PP spsp rere", + Name = "Blau", + SortOrder = 10 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000012"), + CanonicalGenotype = "AA CC DD EE GG pp spsp rere", + Name = "Gold", + SortOrder = 11 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000013"), + CanonicalGenotype = "aa CC DD EE GG pp spsp rere", + Name = "Platin", + SortOrder = 12 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000014"), + CanonicalGenotype = "AA CC DD ee GG pp spsp rere", + Name = "Goldfuchs", + SortOrder = 13 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000015"), + CanonicalGenotype = "aa CC DD ee GG pp spsp rere", + Name = "Rotfuchs", + SortOrder = 14 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000016"), + CanonicalGenotype = "AA CC dd EE GG pp spsp rere", + Name = "Dilute Gold", + SortOrder = 15 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000017"), + CanonicalGenotype = "aa CC dd EE GG pp spsp rere", + Name = "Dilute Platin", + SortOrder = 16 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000018"), + CanonicalGenotype = "aa CC DD EE gg pp spsp rere", + Name = "Altweiss (REW)", + SortOrder = 17 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000019"), + CanonicalGenotype = "AA CC DD ee gg pp spsp rere", + Name = "Apricot (Blassfuchs)", + SortOrder = 18 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000020"), + CanonicalGenotype = "aa CC DD ee gg PP spsp rere", + Name = "Blaufuchs", + SortOrder = 19 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000021"), + CanonicalGenotype = "aa CC DD ee gg pp spsp rere", + Name = "C-Separator", + SortOrder = 20 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000022"), + CanonicalGenotype = "AA CC DD EE gg pp spsp rere", + Name = "Elfenbein", + SortOrder = 21 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000023"), + CanonicalGenotype = "aa CC DD ee GG PP spsp rere", + Name = "Kohlfuchs", + SortOrder = 22 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000024"), + CanonicalGenotype = "AA CC DD ee gg PP spsp rere", + Name = "Polarfuchs", + SortOrder = 23 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000025"), + CanonicalGenotype = "aa CC DD EE GG pp spsp rere", + Name = "Saphir", + SortOrder = 24 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000026"), + CanonicalGenotype = "AA CC DD efef GG PP spsp rere", + Name = "Orangeschimmel", + SortOrder = 25 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000027"), + CanonicalGenotype = "AA CC DD EE GG pp spsp rere", + Name = "Topas", + SortOrder = 26 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000028"), + CanonicalGenotype = "aa CC DD EE GG pp spsp rere", + Name = "Platin-Hell", + SortOrder = 27 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000029"), + CanonicalGenotype = "AA CC dd EE GG PP spsp rere", + Name = "Dilute Agouti", + SortOrder = 28 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000030"), + CanonicalGenotype = "AA CC dd EE gg PP spsp rere", + Name = "Dilute Silberagouti", + SortOrder = 29 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000031"), + CanonicalGenotype = "aa CC dd ee GG PP spsp rere", + Name = "Dilute Kohlfuchs", + SortOrder = 30 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000032"), + CanonicalGenotype = "aa CC dd EE gg PP spsp rere", + Name = "Dilute Anthrazit", + SortOrder = 31 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000033"), + CanonicalGenotype = "AA CC DD efef gg PP spsp rere", + Name = "Silberschimmel", + SortOrder = 36 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000034"), + CanonicalGenotype = "AA CC DD efef gg PP spsp rere", + Name = "Polarfuchsschimmel", + SortOrder = 37 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000035"), + CanonicalGenotype = "AA CC DD efef GG PP spsp rere", + Name = "Algierfuchsschimmel", + SortOrder = 38 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000036"), + CanonicalGenotype = "aa CC DD efef GG PP spsp rere", + Name = "Kohlfuchsschimmel", + SortOrder = 39 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000037"), + CanonicalGenotype = "aa CC DD efef gg PP spsp rere", + Name = "Blaufuchsschimmel", + SortOrder = 40 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000038"), + CanonicalGenotype = "aa CC DD ee GG PP spsp rere", + Name = "Kohlfuchs, hell", + SortOrder = 41 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000039"), + CanonicalGenotype = "AA CC DD ee GG pp spsp rere", + Name = "Goldfuchs, hell", + SortOrder = 42 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000040"), + CanonicalGenotype = "AA CC DD efef GG pp spsp rere", + Name = "Goldfuchsschimmel", + SortOrder = 43 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000041"), + CanonicalGenotype = "AA CC DD EE GG pp spsp rere", + Name = "Gold-Hell", + SortOrder = 44 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000042"), + CanonicalGenotype = "aa CC DD ee gg PP spsp rere", + Name = "Blaufuchs, hell", + SortOrder = 45 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000043"), + CanonicalGenotype = "aa CC DD efef GG pp spsp rere", + Name = "Rotfuchsschimmel", + SortOrder = 46 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000044"), + CanonicalGenotype = "AA CC DD ee gg PP spsp rere", + Name = "Polarfuchs, hell", + SortOrder = 47 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000045"), + CanonicalGenotype = "aa CC DD efef GG PP spsp rere", + Name = "Kohlfuchsschimmel, hell", + SortOrder = 48 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000046"), + CanonicalGenotype = "aa CC DD ee GG pp spsp rere", + Name = "Rotfuchs, hell", + SortOrder = 49 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000047"), + CanonicalGenotype = "aa CC DD ee GG PP spsp rere", + Name = "Kohlfuchs-Hell", + SortOrder = 50 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000048"), + CanonicalGenotype = "AA CC DD ee GG PP spsp rere", + Name = "Algierfuchs, hell", + SortOrder = 51 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000049"), + CanonicalGenotype = "AA CC dd EE GG pp spsp rere", + Name = "Dilute Topas", + SortOrder = 52 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000050"), + CanonicalGenotype = "aa CC dd ee gg pp spsp rere", + Name = "Dilute Blaufuchs", + SortOrder = 53 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000051"), + CanonicalGenotype = "aa cchmcchm DD EE GG PP spsp rere", + Name = "Marder", + SortOrder = 54 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000052"), + CanonicalGenotype = "aa cchmch DD EE GG PP spsp rere", + Name = "Siam", + SortOrder = 55 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000053"), + CanonicalGenotype = "aa cchmch DD EE gg PP spsp rere", + Name = "Zobel-Hell", + SortOrder = 56 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000054"), + CanonicalGenotype = "AA cchmcchm DD EE GG PP spsp rere", + Name = "CP-Agouti", + SortOrder = 57 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000055"), + CanonicalGenotype = "AA cchmcchm DD EE gg PP spsp rere", + Name = "CP-Silberagouti", + SortOrder = 59 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000056"), + CanonicalGenotype = "AA cchmcchm DD ee GG PP spsp rere", + Name = "CP-Algierfuchs", + SortOrder = 61 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000057"), + CanonicalGenotype = "AA cchmcchm DD ee gg PP spsp rere", + Name = "CP-Polarfuchs", + SortOrder = 63 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000058"), + CanonicalGenotype = "AA cchmcchm dd ee GG PP spsp rere", + Name = "CP-Fuchs", + SortOrder = 65 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000059"), + CanonicalGenotype = "AA cchmch dd ee GG PP spsp rere", + Name = "CP-Fuchs-Hell", + SortOrder = 66 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000060"), + CanonicalGenotype = "AA cchmcchm dd ee gg PP spsp rere", + Name = "CP-Blaufuchs", + SortOrder = 67 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000061"), + CanonicalGenotype = "AA cchmcchm DD efef GG PP spsp rere", + Name = "CP-Orangeschimmel", + SortOrder = 68 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000062"), + CanonicalGenotype = "AA cchmch DD EE GG PP spsp rere", + Name = "CP-Agouti-Hell", + SortOrder = 58 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000063"), + CanonicalGenotype = "AA cchmch DD EE gg PP spsp rere", + Name = "CP-Silberagouti-Hell", + SortOrder = 60 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000064"), + CanonicalGenotype = "AA cchmch DD ee GG PP spsp rere", + Name = "CP-Algierfuchs-Hell", + SortOrder = 62 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000065"), + CanonicalGenotype = "AA cchmch DD ee gg PP spsp rere", + Name = "CP-Polarfuchs-Hell", + SortOrder = 64 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000066"), + CanonicalGenotype = "AA cchmch DD efef GG PP spsp rere", + Name = "CP-Orangeschimmel-Hell", + SortOrder = 69 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000067"), + CanonicalGenotype = "AA CC dd ee GG PP spsp rere", + Name = "Dilute Algierfuchs", + SortOrder = 32 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000068"), + CanonicalGenotype = "AA CC dd ee GG pp spsp rere", + Name = "Dilute Goldfuchs", + SortOrder = 33 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000069"), + CanonicalGenotype = "aa CC dd ee GG pp spsp rere", + Name = "Dilute Rotfuchs", + SortOrder = 34 + }, + new + { + Id = new Guid("00000000-0000-0000-0000-000000000070"), + CanonicalGenotype = "AA CC dd ee gg PP spsp rere", + Name = "Dilute Polarfuchs", + SortOrder = 35 + }); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Contact", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Address") + .HasColumnType("text"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("IsBreeder") + .HasColumnType("boolean"); + + b.Property("IsReceiver") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .UseCollation("de-x-icu"); + + b.Property("NameSuffix") + .HasColumnType("text"); + + b.Property("Notes") + .HasColumnType("text"); + + b.Property("Phone") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Contacts"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Enclosure", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Notes") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Enclosures"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.EnclosurePhoto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Caption") + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("EnclosureId") + .HasColumnType("uuid"); + + b.Property("FileName") + .IsRequired() + .HasColumnType("text"); + + b.Property("SortOrder") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("EnclosureId"); + + b.ToTable("EnclosurePhotos"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Gerbil", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CauseOfDeath") + .HasColumnType("text"); + + b.Property("CharacterNote") + .HasColumnType("text"); + + b.Property("CharacterTraits") + .IsRequired() + .HasColumnType("text"); + + b.Property("ColorVarietyId") + .HasColumnType("uuid"); + + b.Property("DateOfBirth") + .HasColumnType("date"); + + b.Property("DateOfDeath") + .HasColumnType("date"); + + b.Property("EnclosureId") + .HasColumnType("uuid"); + + b.Property("ExternalRef") + .HasColumnType("text"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("text"); + + b.Property("Genotype") + .HasColumnType("text"); + + b.Property("GoHomeDate") + .HasColumnType("date"); + + b.Property("ImportSource") + .HasColumnType("text"); + + b.Property("IsCastrated") + .HasColumnType("boolean"); + + b.Property("IsDeaf") + .HasColumnType("boolean"); + + b.Property("IsResident") + .ValueGeneratedOnAdd() + .HasColumnType("boolean") + .HasDefaultValue(true); + + b.Property("LitterId") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text") + .UseCollation("de-x-icu"); + + b.Property("NameSearch") + .HasColumnType("text") + .UseCollation("de-x-icu"); + + b.Property("Notes") + .HasColumnType("text"); + + b.Property("OriginBreeder") + .HasColumnType("text") + .UseCollation("de-x-icu"); + + b.Property("OriginContactId") + .HasColumnType("uuid"); + + b.Property("RawImportData") + .HasColumnType("text"); + + b.Property("ReceiverContactId") + .HasColumnType("uuid"); + + b.Property("SpottingType") + .HasColumnType("text"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("ColorVarietyId"); + + b.HasIndex("EnclosureId"); + + b.HasIndex("ExternalRef") + .IsUnique() + .HasFilter("\"ExternalRef\" IS NOT NULL"); + + b.HasIndex("LitterId"); + + b.HasIndex("OriginContactId"); + + b.HasIndex("ReceiverContactId"); + + b.ToTable("Gerbils"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.GerbilPhoto", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Caption") + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("FileName") + .IsRequired() + .HasColumnType("text"); + + b.Property("GerbilId") + .HasColumnType("uuid"); + + b.Property("SortOrder") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("GerbilId"); + + b.ToTable("GerbilPhotos"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.HealthRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("GerbilId") + .HasColumnType("uuid"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.Property("Veterinarian") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("GerbilId"); + + b.ToTable("HealthRecords"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Litter", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("DeathsWithin8Weeks") + .HasColumnType("integer"); + + b.Property("ExpectedGoHomeDate") + .HasColumnType("date"); + + b.Property("ExternalRef") + .HasColumnType("text"); + + b.Property("FatherId") + .HasColumnType("uuid"); + + b.Property("LitterLetter") + .HasColumnType("text"); + + b.Property("MotherId") + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Notes") + .HasColumnType("text"); + + b.Property("PairingCode") + .HasColumnType("text"); + + b.Property("TotalBorn") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ExternalRef") + .IsUnique() + .HasFilter("\"ExternalRef\" IS NOT NULL"); + + b.HasIndex("FatherId"); + + b.HasIndex("MotherId"); + + b.ToTable("Litters"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.MailSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AppPasswordProtected") + .HasColumnType("text"); + + b.Property("BackgroundPollEnabled") + .HasColumnType("boolean"); + + b.Property("Folder") + .IsRequired() + .HasColumnType("text"); + + b.Property("GmailAddress") + .HasColumnType("text"); + + b.Property("LastUid") + .HasColumnType("bigint"); + + b.Property("PollIntervalMinutes") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("MailSettings"); + + b.HasData( + new + { + Id = new Guid("ab0c0000-0000-0000-0000-000000000001"), + BackgroundPollEnabled = false, + Folder = "INBOX", + LastUid = 0L, + PollIntervalMinutes = 15 + }); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Media", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Alt") + .HasColumnType("text"); + + b.Property("FileName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Height") + .HasColumnType("integer"); + + b.Property("Url") + .IsRequired() + .HasColumnType("text"); + + b.Property("Width") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Media"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Page", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("SeoDescription") + .HasColumnType("text"); + + b.Property("Slug") + .IsRequired() + .HasColumnType("text"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("Slug") + .IsUnique(); + + b.ToTable("Pages"); + + b.HasData( + new + { + Id = new Guid("51720001-0000-0000-0000-000000000001"), + Slug = "start", + Status = "Published", + Title = "Startseite" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000002"), + Slug = "ueber-die-zucht", + Status = "Published", + Title = "Über die Zucht" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000003"), + Slug = "abgabetiere", + Status = "Published", + Title = "Abgabetiere" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000004"), + Slug = "abgabebedingungen", + Status = "Published", + Title = "Abgabebedingungen" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000005"), + Slug = "farben-genetik", + Status = "Published", + Title = "Farben & Genetik" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000006"), + Slug = "kontakt", + Status = "Published", + Title = "Kontakt" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000007"), + Slug = "impressum", + Status = "Published", + Title = "Impressum" + }, + new + { + Id = new Guid("51720001-0000-0000-0000-000000000008"), + Slug = "datenschutz", + Status = "Published", + Title = "Datenschutz" + }); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Request", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AnsweredAt") + .HasColumnType("timestamp with time zone"); + + b.Property("AssignedContactId") + .HasColumnType("uuid"); + + b.Property("BodyText") + .HasColumnType("text"); + + b.Property("DraftReply") + .HasColumnType("text"); + + b.Property("FromAddress") + .IsRequired() + .HasColumnType("text"); + + b.Property("FromName") + .HasColumnType("text"); + + b.Property("GmailMessageId") + .IsRequired() + .HasColumnType("text"); + + b.Property("InReplyToMessageId") + .HasColumnType("text"); + + b.Property("ReceivedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ReferencesHeader") + .HasColumnType("text"); + + b.Property("Status") + .IsRequired() + .HasColumnType("text"); + + b.Property("Subject") + .HasColumnType("text"); + + b.Property("ThreadId") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("AssignedContactId"); + + b.HasIndex("GmailMessageId") + .IsUnique(); + + b.ToTable("Requests"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.SaleContract", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ContactId") + .HasColumnType("uuid"); + + b.Property("ContractDate") + .HasColumnType("date"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("FileName") + .IsRequired() + .HasColumnType("text"); + + b.Property("HandoverDate") + .HasColumnType("date"); + + b.Property("Price") + .HasPrecision(10, 2) + .HasColumnType("numeric(10,2)"); + + b.HasKey("Id"); + + b.HasIndex("ContactId"); + + b.ToTable("SaleContracts"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.SaleContractAnimal", b => + { + b.Property("SaleContractId") + .HasColumnType("uuid"); + + b.Property("GerbilId") + .HasColumnType("uuid"); + + b.Property("PhotoId") + .HasColumnType("uuid"); + + b.HasKey("SaleContractId", "GerbilId"); + + b.HasIndex("GerbilId"); + + b.ToTable("SaleContractAnimal"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Site", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("DefaultLocale") + .IsRequired() + .HasColumnType("text"); + + b.Property("NavOrder") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Sites"); + + b.HasData( + new + { + Id = new Guid("5172e000-0000-0000-0000-000000000001"), + DefaultLocale = "de", + NavOrder = "[\"51720001-0000-0000-0000-000000000001\",\"51720001-0000-0000-0000-000000000002\",\"51720001-0000-0000-0000-000000000003\",\"51720001-0000-0000-0000-000000000004\",\"51720001-0000-0000-0000-000000000005\",\"51720001-0000-0000-0000-000000000006\"]" + }); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.WeightRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("GerbilId") + .HasColumnType("uuid"); + + b.Property("Notes") + .HasColumnType("text"); + + b.Property("WeightGrams") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("GerbilId"); + + b.ToTable("WeightRecords"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Block", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Page", null) + .WithMany("Blocks") + .HasForeignKey("PageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.EnclosurePhoto", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Enclosure", null) + .WithMany() + .HasForeignKey("EnclosureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Gerbil", b => + { + b.HasOne("GerbilManagerWebAPI.Models.ColorVariety", "ColorVariety") + .WithMany() + .HasForeignKey("ColorVarietyId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("GerbilManagerWebAPI.Models.Enclosure", "Enclosure") + .WithMany("Gerbils") + .HasForeignKey("EnclosureId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("GerbilManagerWebAPI.Models.Litter", "Litter") + .WithMany() + .HasForeignKey("LitterId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("GerbilManagerWebAPI.Models.Contact", "OriginContact") + .WithMany() + .HasForeignKey("OriginContactId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("GerbilManagerWebAPI.Models.Contact", "ReceiverContact") + .WithMany() + .HasForeignKey("ReceiverContactId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("ColorVariety"); + + b.Navigation("Enclosure"); + + b.Navigation("Litter"); + + b.Navigation("OriginContact"); + + b.Navigation("ReceiverContact"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.GerbilPhoto", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Gerbil", null) + .WithMany() + .HasForeignKey("GerbilId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.HealthRecord", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Gerbil", null) + .WithMany() + .HasForeignKey("GerbilId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Litter", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Gerbil", "Father") + .WithMany() + .HasForeignKey("FatherId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("GerbilManagerWebAPI.Models.Gerbil", "Mother") + .WithMany() + .HasForeignKey("MotherId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("Father"); + + b.Navigation("Mother"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Request", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Contact", "AssignedContact") + .WithMany() + .HasForeignKey("AssignedContactId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("AssignedContact"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.SaleContract", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Contact", "Contact") + .WithMany() + .HasForeignKey("ContactId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Contact"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.SaleContractAnimal", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Gerbil", "Gerbil") + .WithMany() + .HasForeignKey("GerbilId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("GerbilManagerWebAPI.Models.SaleContract", null) + .WithMany("Animals") + .HasForeignKey("SaleContractId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Gerbil"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.WeightRecord", b => + { + b.HasOne("GerbilManagerWebAPI.Models.Gerbil", null) + .WithMany() + .HasForeignKey("GerbilId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Enclosure", b => + { + b.Navigation("Gerbils"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.Page", b => + { + b.Navigation("Blocks"); + }); + + modelBuilder.Entity("GerbilManagerWebAPI.Models.SaleContract", b => + { + b.Navigation("Animals"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/GerbilManagerWebAPI/Migrations/20260613120908_AddContractAnimalPhoto.cs b/GerbilManagerWebAPI/Migrations/20260613120908_AddContractAnimalPhoto.cs new file mode 100644 index 0000000..5ad0e64 --- /dev/null +++ b/GerbilManagerWebAPI/Migrations/20260613120908_AddContractAnimalPhoto.cs @@ -0,0 +1,29 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace GerbilManagerWebAPI.Migrations +{ + /// + public partial class AddContractAnimalPhoto : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "PhotoId", + table: "SaleContractAnimal", + type: "uuid", + nullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "PhotoId", + table: "SaleContractAnimal"); + } + } +} diff --git a/GerbilManagerWebAPI/Migrations/ApplicationContextModelSnapshot.cs b/GerbilManagerWebAPI/Migrations/ApplicationContextModelSnapshot.cs index 504c28e..af36b60 100644 --- a/GerbilManagerWebAPI/Migrations/ApplicationContextModelSnapshot.cs +++ b/GerbilManagerWebAPI/Migrations/ApplicationContextModelSnapshot.cs @@ -970,7 +970,7 @@ namespace GerbilManagerWebAPI.Migrations .ValueGeneratedOnAdd() .HasColumnType("uuid"); - b.Property("Date") + b.Property("Date") .HasColumnType("date"); b.Property("DeathsWithin8Weeks") @@ -1271,6 +1271,9 @@ namespace GerbilManagerWebAPI.Migrations b.Property("GerbilId") .HasColumnType("uuid"); + b.Property("PhotoId") + .HasColumnType("uuid"); + b.HasKey("SaleContractId", "GerbilId"); b.HasIndex("GerbilId"); diff --git a/GerbilManagerWebAPI/Models/Litter.cs b/GerbilManagerWebAPI/Models/Litter.cs index 882cccb..c2da095 100644 --- a/GerbilManagerWebAPI/Models/Litter.cs +++ b/GerbilManagerWebAPI/Models/Litter.cs @@ -8,7 +8,7 @@ namespace GerbilManagerWebAPI.Models [Key] public Guid Id { get; set; } public required string Name { get; set; } - public DateOnly Date { get; set; } + public DateOnly? Date { get; set; } /// Total born count (was "Strength"). public int? TotalBorn { get; set; } diff --git a/GerbilManagerWebAPI/Models/SaleContract.cs b/GerbilManagerWebAPI/Models/SaleContract.cs index 497179c..de475b7 100644 --- a/GerbilManagerWebAPI/Models/SaleContract.cs +++ b/GerbilManagerWebAPI/Models/SaleContract.cs @@ -41,5 +41,9 @@ namespace GerbilManagerWebAPI.Models public Guid SaleContractId { get; set; } public Guid GerbilId { get; set; } public Gerbil? Gerbil { get; set; } + + /// Optional gewähltes Tierfoto () fürs Vertragsbild. + /// Nur die Id wird gespeichert; beim PDF-Rendern wird die Datei nachgeladen. + public Guid? PhotoId { get; set; } } } diff --git a/GerbilManagerWebAPI/Services/GerbilStatusService.cs b/GerbilManagerWebAPI/Services/GerbilStatusService.cs index 31cbf25..c1a3dc0 100644 --- a/GerbilManagerWebAPI/Services/GerbilStatusService.cs +++ b/GerbilManagerWebAPI/Services/GerbilStatusService.cs @@ -20,7 +20,7 @@ namespace GerbilManagerWebAPI.Services /// public static class GerbilStatusService { - public const int MaxAgeYears = 7; + public const int MaxAgeYears = 6; /// Derives and sets g.Status using the gerbil's current field values. /// Must be called AFTER all other fields (DateOfDeath, ReceiverContactId, DateOfBirth) diff --git a/gerbil-manager-web/src/api/contracts.ts b/gerbil-manager-web/src/api/contracts.ts index e5d7295..790ded7 100644 --- a/gerbil-manager-web/src/api/contracts.ts +++ b/gerbil-manager-web/src/api/contracts.ts @@ -22,6 +22,8 @@ export interface CreateSaleContract { price: number handoverDate: DateOnlyString contractDate?: DateOnlyString | null + /** Optionales Vertragsfoto je Tier: GerbilId → GerbilPhoto-Id. */ + animalPhotos?: Record } export function listContracts(query: GridifyQuery): Promise> { @@ -40,3 +42,8 @@ export function deleteContract(id: string): Promise { export function contractFileUrl(contract: Pick): string { return `${API_BASE_URL}${contract.url}` } + +/** Absolute Download-URL des druckfertigen PDF. */ +export function contractPdfUrl(contract: Pick): string { + return `${API_BASE_URL}/contracts/${contract.id}/pdf` +} diff --git a/gerbil-manager-web/src/pages/GerbilsPage.tsx b/gerbil-manager-web/src/pages/GerbilsPage.tsx index 8411deaf5a840f893f575685702acf2166865023..314f0f291943817181abfddeb8a1b165d8131953 100644 GIT binary patch delta 492 zcmaiwKT88K7>7Z+*h93~!YLHrE7yNgTPRNA6?Cy%2T=!?rcKHPugQ_5SBe%##nFJX zi@VV8Q~Vf?=8Dibx#fl5`##SvFY)vA^VQKC&hC)MigJdcXa*t01Q4TR6iJv;74nG! z1Q;m-d;|k3R0uUmL_)-oG~s$P3oztND!5ITuUMMJ4Uj~2*Yo1R`Pg~{XtkiXreVS3 z|7cCP5ERqV3^I^ZSxy^_zzf=EelaBr`C`v*B|?oy`aS-pMe>Sd*%ugk}O0B_~KYo#wkF4X+A QC1b=o`m9-8G%Cy75B&Y9V*mgE delta 31 ncmeAu?<&|ZiF>mgPe1SG2~q(pn}5lD<(Pclihc8I&AEaA)sYQR diff --git a/gerbil-manager-web/src/pages/VertraegeListPage.tsx b/gerbil-manager-web/src/pages/VertraegeListPage.tsx index 26b1144..f13939e 100644 --- a/gerbil-manager-web/src/pages/VertraegeListPage.tsx +++ b/gerbil-manager-web/src/pages/VertraegeListPage.tsx @@ -2,7 +2,7 @@ import { useMemo } from 'react' import { Link } from 'react-router-dom' import { de } from '../strings/de' -import { contractFileUrl, deleteContract, listContracts } from '../api/contracts' +import { contractFileUrl, contractPdfUrl, deleteContract, listContracts } from '../api/contracts' import { listContactsPaged } from '../api/contacts' import { useApi, useMutation } from '../hooks/useApi' import { useInfiniteList, useInfiniteSentinel } from '../hooks/useInfiniteList' @@ -81,6 +81,9 @@ export default function VertraegeListPage() { {t.fields.handoverDate} {formatDate(c.handoverDate)} + + {t.downloadPdf} + {t.download} diff --git a/gerbil-manager-web/src/pages/VertragWizardPage.tsx b/gerbil-manager-web/src/pages/VertragWizardPage.tsx index 0ea60f1..c32a9cc 100644 --- a/gerbil-manager-web/src/pages/VertragWizardPage.tsx +++ b/gerbil-manager-web/src/pages/VertragWizardPage.tsx @@ -8,7 +8,7 @@ * serverseitig in EINER Transaktion: .docx erzeugen + speichern, Vertrag * anlegen, Tiere auf „Abgegeben“ stellen (Abnehmer + Abgabedatum). */ -import { useMemo, useState } from 'react' +import { useEffect, useMemo, useState } from 'react' import { Link, useNavigate, useSearchParams } from 'react-router-dom' import { de } from '../strings/de' import { listGerbils } from '../api/gerbils' @@ -16,6 +16,7 @@ import { createContact, listContactsPaged } from '../api/contacts' import { contractFileUrl, createContract, type SaleContract } from '../api/contracts' import { getBreederProfile, isBreederProfileComplete } from '../api/settings' import { listColorVarieties } from '../api/lookups' +import { listGerbilPhotos, photoSrc, profilePhoto } from '../api/photos' import { useApi, useMutation } from '../hooks/useApi' import { formatDate, genderLabel } from '../format/labels' import './vertragWizard.css' @@ -110,6 +111,11 @@ export default function VertragWizardPage() { return next }) + /* Vertragsfoto je Tier: GerbilId → PhotoId ('' = bewusst kein Foto). */ + const [animalPhotos, setAnimalPhotos] = useState>({}) + const setAnimalPhoto = (gerbilId: string, photoId: string) => + setAnimalPhotos((m) => ({ ...m, [gerbilId]: photoId })) + /* ── Schritt 3: Preis & Datum ── */ const [priceText, setPriceText] = useState('') const [handoverDate, setHandoverDate] = useState(todayIso()) @@ -127,6 +133,12 @@ export default function VertragWizardPage() { price: parsePrice(priceText)!, handoverDate, contractDate: contractDate || null, + // nur ausgewählte Tiere mit tatsächlich gewähltem Foto übermitteln + animalPhotos: Object.fromEntries( + [...selectedIds] + .map((id) => [id, animalPhotos[id]] as const) + .filter(([, pid]) => Boolean(pid)), + ), }), ) async function onGenerate() { @@ -339,6 +351,13 @@ export default function VertragWizardPage() { .join(' · ')} + {selectedIds.has(g.id) && ( + setAnimalPhoto(g.id, photoId)} + /> + )} ))} @@ -450,3 +469,57 @@ export default function VertragWizardPage() { ) } + +/** + * Foto-Auswahl je Tier für den Vertrag. Lädt die Tierfotos lazy; Standard ist + * das Profilfoto (erstes nach SortOrder). '' = bewusst „Kein Foto“. + * Rendert nichts, wenn das Tier keine Fotos hat. + */ +function ContractPhotoPicker({ + gerbilId, + chosen, + onChange, +}: { + gerbilId: string + chosen: string | undefined + onChange: (photoId: string) => void +}) { + const t = de.pages.vertraege.wizard + const photos = useApi(() => listGerbilPhotos(gerbilId), [gerbilId]) + const list = useMemo(() => photos.data ?? [], [photos.data]) + + // Sobald Fotos da sind und noch nichts entschieden ist: Profilfoto vorauswählen. + useEffect(() => { + if (list.length > 0 && chosen === undefined) { + const p = profilePhoto(list) + if (p) onChange(p.id) + } + }, [list, chosen, onChange]) + + if (photos.loading || list.length === 0) return null + + return ( +
+ {t.photoLabel} +
+ + {list.map((p) => ( + + ))} +
+
+ ) +} diff --git a/gerbil-manager-web/src/pages/vertragWizard.css b/gerbil-manager-web/src/pages/vertragWizard.css index c017699..2286478 100644 --- a/gerbil-manager-web/src/pages/vertragWizard.css +++ b/gerbil-manager-web/src/pages/vertragWizard.css @@ -140,3 +140,50 @@ grid-row: 1 / span 2; align-self: center; } + +/* ── Vertragsfoto-Auswahl je Tier (Schritt „Tiere“) ── */ +.contract-photopick { + margin: 0.5rem 0 0.25rem 1.9rem; + display: flex; + flex-direction: column; + gap: 0.4rem; +} +.contract-photopick__label { + font-size: 0.8rem; + color: var(--color-muted, #8c7f6e); +} +.contract-photopick__thumbs { + display: flex; + flex-wrap: wrap; + gap: 0.5rem; +} +.contract-photopick__thumb { + width: 64px; + height: 64px; + padding: 0; + border: 2px solid var(--color-border, #d9ccb4); + border-radius: 10px; + background: var(--color-surface, #fff); + overflow: hidden; + cursor: pointer; + display: flex; + align-items: center; + justify-content: center; + transition: border-color 0.15s ease, box-shadow 0.15s ease; +} +.contract-photopick__thumb img { + width: 100%; + height: 100%; + object-fit: cover; + display: block; +} +.contract-photopick__thumb--none { + font-size: 0.72rem; + color: var(--color-muted, #8c7f6e); + text-align: center; + line-height: 1.1; +} +.contract-photopick__thumb.is-selected { + border-color: var(--color-accent, #a85f2e); + box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-accent, #a85f2e) 30%, transparent); +} diff --git a/gerbil-manager-web/src/strings/de.ts b/gerbil-manager-web/src/strings/de.ts index e225e8e..7927b9c 100644 --- a/gerbil-manager-web/src/strings/de.ts +++ b/gerbil-manager-web/src/strings/de.ts @@ -66,6 +66,9 @@ export const de = { // DESIGN (Rennmaus Filter): kurze Variante für den Toggle-Chip. showExternalShort: 'Externe Ahnen', showExternalHint: 'Tiere aus fremden Zuchten, die nur für den Stammbaum erfasst sind.', + // BESTAND-FILTER: Tiere ohne Geburtsdatum ausblenden (Toggle-Chip neben „Externe Ahnen“). + hideUndatedShort: 'Mit Geburtsdatum', + hideUndatedHint: 'Tiere ohne hinterlegtes Geburtsdatum ausblenden.', }, // Sortier-Optionen sort: { @@ -451,7 +454,8 @@ export const de = { newButton: 'Neuer Vertrag', empty: 'Noch keine Verträge — erstelle den ersten über „Neuer Vertrag“ oder den Abgabe-Bereich.', countText: (n: number) => (n === 1 ? '1 Vertrag' : `${n} Verträge`), - download: 'Herunterladen', + download: 'Word', + downloadPdf: 'PDF', delete: 'Löschen', confirmDelete: 'Vertrag wirklich löschen? Die Word-Datei wird mit entfernt; der Status der Tiere bleibt unverändert.', @@ -483,6 +487,8 @@ export const de = { pickAnimalsHint: 'Nur lebende, nicht abgegebene Tiere werden angezeigt.', noAnimals: 'Keine abgebbaren Tiere gefunden.', animalsRequired: 'Bitte mindestens ein Tier auswählen.', + photoLabel: 'Foto für den Vertrag', + photoNone: 'Kein Foto', // Schritt 3 priceLabel: 'Kaufpreis (€)', pricePlaceholder: 'z. B. 72,00', diff --git a/tools/import/extract.py b/tools/import/extract.py index 035b504..73bbbc7 100644 --- a/tools/import/extract.py +++ b/tools/import/extract.py @@ -323,9 +323,10 @@ def _reconstruct_parents(animals): father = above[-1] if above else None mother = below[0] if below else None for parent, role in ((father, "father"), (mother, "mother")): - if parent and parent["name"]: + if parent: + p_name = parent["name"] or "unbekannt" a["parentRefs"].append({ - "name": parent["name"], + "name": p_name, "dob": parent["dob"], "roleGuess": role, "method": "chart-position", @@ -348,7 +349,7 @@ def _attach_photos(z, sheets, animals, fname): if not cands: # fall back to nearest animal by row across all gens cands = animals - target = min(cands, key=lambda a: abs(a["_row"] - row)) if cands else None + target = min(cands, key=lambda a: abs((a["_row"] - row) - 10)) if cands else None if not target: continue ext = os.path.splitext(media)[1] or ".img" diff --git a/tools/import/merge_and_resolve.py b/tools/import/merge_and_resolve.py index 9bedb11..f5a2d13 100644 --- a/tools/import/merge_and_resolve.py +++ b/tools/import/merge_and_resolve.py @@ -231,6 +231,34 @@ def get_normalized_contact_name(name): return name, True +def get_normalized_gerbil_name(name): + if not name: + return "" + n = name.strip() + norm_key = "".join(c for c in n.lower() if c.isalnum()) + + gerbil_norm_map = { + "samgenshellyvdbuntenfellnasen": "Sammy gen. Shelly von den bunten Fellnasen", + "sammygenshellyvdbuntenfellnasen": "Sammy gen. Shelly von den bunten Fellnasen", + "schmidt": "Schmidti", + "sheila": "Sheila of Ulmer Strolche", + "shinichi": "Shinichi von PZ Mücke", + "silenosgenadonis": "Silenos gen. Adonis von den Kleinen Chaoten", + "silenosgenadonisvdkleinenchaoten": "Silenos gen. Adonis von den Kleinen Chaoten", + "silver": "Silver von den kleinen Chaoten", + "snoops": "Snoopsi", + "sokrates": "Sokrates von den Kleinen Chaoten", + "splash": "Slash", + "teiko": "Teiko von den kleinen Chaoten", + "trixy": "Trixxy von den Kleinen Chaoten", + "unique": "Unique of Wild Dreams", + } + + if norm_key in gerbil_norm_map: + return gerbil_norm_map[norm_key] + + return n + def get_call_name(name): if not name: return "" @@ -485,15 +513,42 @@ def main(): print("Loading color variety seeds...") variety_map = {} variety_genotypes = {} + + # Load from C# ApplicationContext.cs catalog for stable database GUIDs (index + 1) + here = os.path.dirname(os.path.abspath(__file__)) + app_context_path = os.path.abspath(os.path.join(here, "../../GerbilManagerWebAPI/ApplicationContext.cs")) + cs_name_to_id = {} + if os.path.exists(app_context_path): + with open(app_context_path, 'r', encoding='utf-8') as f: + content = f.read() + catalog_match = re.search(r'catalog\s*=\s*\{(.*?)\};', content, re.DOTALL) + if catalog_match: + block = catalog_match.group(1) + entries = re.findall(r'\(\s*"([^"]+)"\s*,\s*"([^"]+)"\s*,\s*(\d+)\s*\)', block) + for idx, (name, genotype, sort_order) in enumerate(entries): + variety_id = f"00000000-0000-0000-0000-{idx + 1:012d}" + cs_name_to_id[name.strip().lower()] = variety_id + variety_map[name.strip().lower()] = variety_id + variety_genotypes[variety_id] = genotype.strip() + else: + print(f"Warning: ApplicationContext.cs not found at {app_context_path}") + if os.path.exists(SEEDS_PATH): with open(SEEDS_PATH, "r", encoding="utf-8") as f: seeds = json.load(f) for v in seeds: - variety_id = f"00000000-0000-0000-0000-{v['sortOrder'] + 1:012d}" - variety_map[v["name"].strip().lower()] = variety_id + name_lower = v["name"].strip().lower() + variety_id = cs_name_to_id.get(name_lower) + if not variety_id: + variety_id = f"00000000-0000-0000-0000-{v['sortOrder'] + 1:012d}" + variety_map[name_lower] = variety_id + + # Map English name if present if "english" in v and v["english"]: variety_map[v["english"].strip().lower()] = variety_id - variety_genotypes[variety_id] = v.get("canonicalGenotype") + + if variety_id not in variety_genotypes: + variety_genotypes[variety_id] = v.get("canonicalGenotype") else: print(f"Warning: Seeds path not found at {SEEDS_PATH}") @@ -694,8 +749,8 @@ def main(): for dl in docx_litters: l_name = dl["litterId"] dob_val = parse_date(dl["dob"]) - f_name = dl["fatherName"] - m_name = dl["motherName"] + f_name = get_normalized_gerbil_name(dl["fatherName"]) + m_name = get_normalized_gerbil_name(dl["motherName"]) ws_code = dl["wsCode"] note_val = dl.get("note") @@ -719,7 +774,7 @@ def main(): raw_litters.append({ "Id": l_scoped_id, "Name": l_name, - "Date": dob_val or "0001-01-01", + "Date": dob_val, "TotalBorn": total_born, "DeathsWithin8Weeks": deaths_8w, "FatherId": generate_guid(f"stammbaum-animal-{normalize_name(f_name)}"), # placeholder @@ -784,8 +839,8 @@ def main(): # Pre-index Wurfchronik litters from markdown md_litters_idx = {} for rl in raw_litters: - f_name = rl.get("FatherName") or rl.get("fatherName") or rl.get("ParentMaleName") or rl.get("parentMaleName") - m_name = rl.get("MotherName") or rl.get("motherName") or rl.get("ParentFemaleName") or rl.get("parentFemaleName") + f_name = get_normalized_gerbil_name(rl.get("FatherName") or rl.get("fatherName") or rl.get("ParentMaleName") or rl.get("parentMaleName")) + m_name = get_normalized_gerbil_name(rl.get("MotherName") or rl.get("motherName") or rl.get("ParentFemaleName") or rl.get("parentFemaleName")) ldate = parse_date(rl.get("Date") or rl.get("date") or rl.get("DateOfBirth") or rl.get("dateOfBirth")) if f_name and m_name and ldate: key = (normalize_name(f_name), normalize_name(m_name), ldate) @@ -800,8 +855,8 @@ def main(): a["_mapped_litter_scoped_id"] = None if father_ref and mother_ref: - f_name = father_ref.get("name") - m_name = mother_ref.get("name") + f_name = get_normalized_gerbil_name(father_ref.get("name")) + m_name = get_normalized_gerbil_name(mother_ref.get("name")) dob_val = parse_date(a.get("dob")) mapped_litter = None @@ -827,14 +882,16 @@ def main(): m_dob = parse_date(mother_ref.get("dob")) for p_cand in stammbaum_only_animals: - cand_call_norm = normalize_name(get_call_name(p_cand["name"])) - if cand_call_norm == normalize_name(f_name) or normalize_name(p_cand["name"]) == normalize_name(f_name): + cand_call_norm = normalize_name(get_call_name(p_cand["name"])) or "unbekannt" + cand_name_norm = normalize_name(p_cand["name"]) or "unbekannt" + if cand_call_norm == normalize_name(f_name) or cand_name_norm == normalize_name(f_name): if not f_dob or parse_date(p_cand.get("dob")) == f_dob: f_scoped_id = generate_guid(f"stammbaum-animal-{p_cand['id']}") break for p_cand in stammbaum_only_animals: - cand_call_norm = normalize_name(get_call_name(p_cand["name"])) - if cand_call_norm == normalize_name(m_name) or normalize_name(p_cand["name"]) == normalize_name(m_name): + cand_call_norm = normalize_name(get_call_name(p_cand["name"])) or "unbekannt" + cand_name_norm = normalize_name(p_cand["name"]) or "unbekannt" + if cand_call_norm == normalize_name(m_name) or cand_name_norm == normalize_name(m_name): if not m_dob or parse_date(p_cand.get("dob")) == m_dob: m_scoped_id = generate_guid(f"stammbaum-animal-{p_cand['id']}") break @@ -842,7 +899,7 @@ def main(): raw_litters.append({ "Id": l_scoped_id, "Name": f"Wurf von {f_name} + {m_name}", - "Date": dob_val or "0001-01-01", + "Date": dob_val, "TotalBorn": None, "DeathsWithin8Weeks": None, "FatherId": f_scoped_id or generate_guid(f"stammbaum-animal-{normalize_name(f_name)}"), @@ -924,8 +981,6 @@ def main(): name_val = "Wurf" dob_val = parse_date(rl.get("Date") or rl.get("date") or rl.get("DateOfBirth") or rl.get("dateOfBirth")) - if not dob_val: - dob_val = "0001-01-01" new_guid = rl["_scoped_id"] if not new_guid: @@ -986,7 +1041,7 @@ def main(): def get_litter_date(l_id): if l_id in litter_by_scoped_id: d = litter_by_scoped_id[l_id]["Date"] - if d and d != "0001-01-01": + if d: return d return None @@ -994,7 +1049,7 @@ def main(): all_processed_gerbils = [] for rg in raw_gerbils: filename = rg.get("_filename") - name_val = rg.get("Name") or rg.get("name") or rg.get("callName") + name_val = get_normalized_gerbil_name(rg.get("Name") or rg.get("name") or rg.get("callName")) if not name_val: name_val = "Unbekannt" @@ -1142,7 +1197,7 @@ def main(): # Map and append stammbaum animals to all_processed_gerbils for a in stammbaum_only_animals: a_id = a["id"] - name_val = a["name"] + name_val = get_normalized_gerbil_name(a["name"]) gender_val = str(a.get("gender") or "").lower().strip() if gender_val in ["m", "male"]: @@ -1166,7 +1221,7 @@ def main(): dt_dob = datetime.strptime(dob_val, "%Y-%m-%d") dt_now = datetime.now() age_years = (dt_now - dt_dob).days / 365.25 - if age_years >= 7.0: + if age_years >= 6.0: status = "Deceased" except Exception: pass @@ -1249,7 +1304,7 @@ def main(): # Map and append docx animals to all_processed_gerbils for idx, da in enumerate(docx_animals): - name_val = da["name"] + name_val = get_normalized_gerbil_name(da["name"]) gender = da["gender"] dob_val = parse_date(da.get("litterDob")) @@ -1335,7 +1390,7 @@ def main(): for l in resolved_litters: ld = l["Date"] - if ld and ld != "0001-01-01": + if ld: for pid in [l["FatherId"], l["MotherId"]]: if pid: parent_litter_dates.setdefault(pid, []).append(ld) @@ -1459,6 +1514,8 @@ def main(): if ph not in merged_photos: merged_photos.append(ph) + if not best_g.get("_old_scoped_litter_id") and g.get("_old_scoped_litter_id"): + best_g["_old_scoped_litter_id"] = g["_old_scoped_litter_id"] if not best_g["LitterId"] and g["LitterId"]: best_g["LitterId"] = g["LitterId"] if not best_g["DateOfBirth"] and g["DateOfBirth"]: @@ -1499,6 +1556,22 @@ def main(): if not any(kw in g["Notes"].lower() for kw in ["parent listed", "mutter von", "vater von", "dam of", "sire of"]): merged_notes.append(g["Notes"]) + # Reconcile fields based on number of source files supporting them + for field in ["DateOfBirth", "DateOfDeath", "Gender", "Genotype", "ColorVarietyId"]: + votes = {} + for g in sub: + val = g.get(field) + if val and val != "unknown": + # count source files + sources_count = len(str(g.get("ImportSource") or "").split(",")) + votes[val] = votes.get(val, 0) + sources_count + if votes: + best_val = max(votes, key=votes.get) + best_g[field] = best_val + # Keep helper fields in sync if we changed DateOfBirth + if field == "DateOfBirth": + best_g["_birth_date"] = best_val + best_g["_eff_dob"] = best_val or "2010-01-01" if merged_notes: best_g["Notes"] = " | ".join(merged_notes) @@ -1513,13 +1586,49 @@ def main(): print(f"Deduplicated to {len(resolved_gerbils)} unique gerbil records.") + # Apply age-based death threshold (6.0 years) to all resolved gerbils + dt_now = datetime.now() + for g in resolved_gerbils: + if g.get("Status") != "Deceased" and g.get("Status") != "GivenAway": + if not g.get("DateOfDeath") and not g.get("ReceiverContactId"): + dob_str = g.get("DateOfBirth") + if dob_str: + try: + dt_dob = datetime.strptime(dob_str, "%Y-%m-%d") + age_years = (dt_now - dt_dob).days / 365.25 + if age_years >= 6.0: + g["Status"] = "Deceased" + except Exception: + pass + # 5. Map Gerbils to Litters for g in resolved_gerbils: old_lid = g["_old_scoped_litter_id"] - if old_lid in litter_id_map: - g["LitterId"] = litter_id_map[old_lid] - else: - g["LitterId"] = None + l_guid = litter_id_map.get(old_lid) + g["LitterId"] = l_guid + + if l_guid and l_guid in litter_by_scoped_id: + l = litter_by_scoped_id[l_guid] + l_date = l.get("Date") + if l_date: + if not g.get("DateOfBirth"): + g["DateOfBirth"] = l_date + g["_birth_date"] = l_date + g["_eff_dob"] = l_date + + # Apply age-based death threshold (6.0 years) to all resolved gerbils (including newly backfilled ones) + if g.get("Status") != "Deceased" and g.get("Status") != "GivenAway": + if not g.get("DateOfDeath") and not g.get("ReceiverContactId"): + dob_str = g.get("DateOfBirth") + if dob_str: + try: + dt_dob = datetime.strptime(dob_str, "%Y-%m-%d") + age_years = (dt_now - dt_dob).days / 365.25 + if age_years >= 6.0: + g["Status"] = "Deceased" + except Exception: + pass + # Clean helper fields del g["_old_scoped_litter_id"] del g["_eff_dob"] @@ -1575,7 +1684,7 @@ def main(): final_c = next((rg for rg in resolved_gerbils if rg["Id"] == final_id), None) if final_c and final_c["Gender"] in ["male", "unknown"]: # Ensure parent is born before litter if birth date is known - if l["Date"] != "0001-01-01" and final_c["DateOfBirth"]: + if l["Date"] and final_c["DateOfBirth"]: if final_c["DateOfBirth"] < l["Date"]: valid_candidates.append(final_c) else: @@ -1600,7 +1709,7 @@ def main(): continue final_c = next((rg for rg in resolved_gerbils if rg["Id"] == final_id), None) if final_c and final_c["Gender"] in ["female", "unknown"]: - if l["Date"] != "0001-01-01" and final_c["DateOfBirth"]: + if l["Date"] and final_c["DateOfBirth"]: if final_c["DateOfBirth"] < l["Date"]: valid_candidates.append(final_c) else: diff --git a/tools/import/output/review-report.md b/tools/import/output/review-report.md index d6989ac..2a08622 100644 --- a/tools/import/output/review-report.md +++ b/tools/import/output/review-report.md @@ -10,7 +10,7 @@ _Automatisch erzeugt von `tools/import/extract.py` — **noch nichts in die Date - in mehreren Dateien gefunden (Dubletten zusammengeführt): 460 - Konflikte zur Klärung: **2** - Mehrdeutige / unvollständige Einträge (ohne Name+Datum): **342** -- Fotos zugeordnet: **417** +- Fotos zugeordnet: **418** - Würfe aus der Wurfchronik: **752** - Tiere mit Wurf verknüpft: **270** (davon über Geburtsdatum **und** Eltern: 167, nur über Geburtsdatum: 103; mehrdeutig: 17) - Würfe mit Datenqualitäts-Hinweisen: 113 (+ 138 Zeilen mit abweichendem Spaltenschema) diff --git a/tools/import/resolve_import.py b/tools/import/resolve_import.py index 07d808f..e9cb8a5 100644 --- a/tools/import/resolve_import.py +++ b/tools/import/resolve_import.py @@ -71,15 +71,38 @@ def main(): # Load color variety seeds print("Loading color variety seeds...") + variety_map = {} + + # Load from C# ApplicationContext.cs catalog for stable database GUIDs (index + 1) + app_context_path = os.path.abspath(os.path.join(HERE, "..", "..", "GerbilManagerWebAPI", "ApplicationContext.cs")) + cs_name_to_id = {} + if os.path.exists(app_context_path): + with open(app_context_path, 'r', encoding='utf-8') as f: + content = f.read() + catalog_match = re.search(r'catalog\s*=\s*\{(.*?)\};', content, re.DOTALL) + if catalog_match: + block = catalog_match.group(1) + entries = re.findall(r'\(\s*"([^"]+)"\s*,\s*"([^"]+)"\s*,\s*(\d+)\s*\)', block) + for idx, (name, genotype, sort_order) in enumerate(entries): + variety_id = f"00000000-0000-0000-0000-{idx + 1:012d}" + cs_name_to_id[name.strip().lower()] = variety_id + variety_map[name.strip().lower()] = variety_id + else: + print(f"Warning: ApplicationContext.cs not found at {app_context_path}") + with open(SEEDS_PATH, "r", encoding="utf-8") as f: seeds = json.load(f) - # Map variety name -> Guid - variety_map = {} for v in seeds: - # UUID is based on SortOrder + 1 - variety_id = f"00000000-0000-0000-0000-{v['sortOrder'] + 1:012d}" - variety_map[v["name"].strip().lower()] = variety_id + name_lower = v["name"].strip().lower() + variety_id = cs_name_to_id.get(name_lower) + if not variety_id: + variety_id = f"00000000-0000-0000-0000-{v['sortOrder'] + 1:012d}" + variety_map[name_lower] = variety_id + + # Map English name if present + if "english" in v and v["english"]: + variety_map[v["english"].strip().lower()] = variety_id # 1. Establish stable Guid maps animal_guid_map = {a["id"]: generate_guid(f"animal-{a['id']}") for a in animals} @@ -297,12 +320,12 @@ def main(): elif not is_resident: status = "GivenAway" else: - # Age presumed deceased (>7 years) + # Age presumed deceased (>6 years) if dob: dt_dob = datetime.strptime(dob, "%Y-%m-%d") dt_now = datetime.now() age_years = (dt_now - dt_dob).days / 365.25 - if age_years >= 7.0: + if age_years >= 6.0: status = "Deceased" else: status = "Breeding" # default to breeding for resident stock diff --git a/tools/import/test_extract.py b/tools/import/test_extract.py index cb21384..5ad68fb 100644 --- a/tools/import/test_extract.py +++ b/tools/import/test_extract.py @@ -337,6 +337,65 @@ check("KC-matcher: norm_zucht regression — 'von den Kleinen Chaoten'", check("KC-matcher: norm_zucht('v.d. Kleinen Chaoten') == 'kleinechaote' (was broken before fix)", e.norm_zucht("v.d. Kleinen Chaoten") == "kleinechaote") +# --- Stammbaum von Danako validation --- +danako_path = r"C:\Users\gulum\dev\Wurfchronik_Bilder\Stammbaum von Danako.xlsx" +if not os.path.exists(danako_path): + danako_path = r"C:\Users\gulum\dev\Sttammbäume\Stammbaum von Danako.xlsx" + +if os.path.exists(danako_path): + print(f"\nFound Danako stammbaum at {danako_path}, running integration validation...") + danako_animals = e.extract_stammbaum(danako_path) + danako_by_name = {a["name"]: a for a in danako_animals} + + check("Danako present in Danako sheet", "Danako" in danako_by_name) + if "Danako" in danako_by_name: + d = danako_by_name["Danako"] + check("Danako DOB is 22.08.2018", d["dob"] == "22.08.2018") + check("Danako photo matches image7.png", d["photos"] == ["photos/danako-22082018/image7.png"]) + + check("Osamu present in Danako sheet", "Osamu" in danako_by_name) + if "Osamu" in danako_by_name: + o = danako_by_name["Osamu"] + check("Osamu DOB is 10.12.2015", o["dob"] == "10.12.2015") + check("Osamu photo matches image4.jpeg", o["photos"] == ["photos/osamu-10122015/image4.jpeg"]) + + # Check parentRefs of Osamu in Danako sheet + o_parents = o.get("parentRefs", []) + o_father = next((p for p in o_parents if p.get("roleGuess") == "father"), None) + o_mother = next((p for p in o_parents if p.get("roleGuess") == "mother"), None) + check("Osamu father is Porter", o_father is not None and o_father["name"] == "Porter") + check("Osamu mother is Yuka", o_mother is not None and o_mother["name"] == "Yuka") + if o_father: + check("Osamu father DOB is 23.05.2015", o_father["dob"] == "23.05.2015") + if o_mother: + check("Osamu mother DOB is 12.07.2015", o_mother["dob"] == "12.07.2015") + + check("Porter present in Danako sheet", "Porter" in danako_by_name) + if "Porter" in danako_by_name: + p = danako_by_name["Porter"] + check("Porter DOB is 23.05.2015", p["dob"] == "23.05.2015") + check("Porter photo matches image6.jpeg", p["photos"] == ["photos/porter-23052015/image6.jpeg"]) + + check("Yuka present in Danako sheet", "Yuka" in danako_by_name) + if "Yuka" in danako_by_name: + y = danako_by_name["Yuka"] + check("Yuka DOB is 12.07.2015", y["dob"] == "12.07.2015") + check("Yuka photo matches image5.jpeg", y["photos"] == ["photos/yuka-12072015/image5.jpeg"]) + + check("Eddward present in Danako sheet", "Eddward" in danako_by_name) + if "Eddward" in danako_by_name: + ed = danako_by_name["Eddward"] + check("Eddward DOB is 18.11.2015", ed["dob"] == "18.11.2015") + check("Eddward photo matches image1.jpeg", ed["photos"] == ["photos/eddward-18112015/image1.jpeg"]) + + check("Harumi present in Danako sheet", "Harumi" in danako_by_name) + if "Harumi" in danako_by_name: + h = danako_by_name["Harumi"] + check("Harumi DOB is 21.02.2015", h["dob"] == "21.02.2015") + check("Harumi photo matches image2.jpeg", h["photos"] == ["photos/harumi-21022015/image2.jpeg"]) +else: + print("\nWarning: Danako stammbaum file not found, skipping integration checks.") + if failed: print(f"\n{failed} test(s) FAILED") sys.exit(1)