H2: Hero-module (tabellen en migratie, beheer-API, publieke GET /hero, afbeeldingsupload met focus, opschoonservice, teksten) en OpenAPI-snapshot
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
using SlpModularCms.Core.Media;
|
||||
|
||||
namespace SlpModularCms.Modules.Hero.Data.Entities;
|
||||
|
||||
/// <summary>The hero of the site in one language: texts, up to two buttons, the display, the schedule and the slides.</summary>
|
||||
public class HeroContent
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>Unique; only <see cref="HeroLanguages.Default"/> is exposed and edited now, the column keeps the model ready for more.</summary>
|
||||
public string Language { get; set; } = HeroLanguages.Default;
|
||||
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string? Tagline { get; set; }
|
||||
public string? Lead { get; set; }
|
||||
public string Display { get; set; } = HeroDisplays.Single;
|
||||
public string? Button1Label { get; set; }
|
||||
public string? Button1Target { get; set; }
|
||||
public string? Button2Label { get; set; }
|
||||
public string? Button2Target { get; set; }
|
||||
public DateTimeOffset? StartsAt { get; set; }
|
||||
public DateTimeOffset? EndsAt { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
public Guid LastModifiedByUserId { get; set; }
|
||||
|
||||
public List<HeroSlide> Slides { get; set; } = [];
|
||||
}
|
||||
|
||||
public class HeroSlide
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid HeroId { get; set; }
|
||||
public Guid ImageId { get; set; }
|
||||
public HeroImage? Image { get; set; }
|
||||
public string Alt { get; set; } = string.Empty;
|
||||
public bool Decorative { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
}
|
||||
|
||||
/// <summary>A stored image: the original (never served), where the subject is, and the current set of variants.</summary>
|
||||
public class HeroImage
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>SHA-256 of the file as uploaded (hex); the same photo uploaded twice is one image.</summary>
|
||||
public string OriginalSha256 { get; set; } = string.Empty;
|
||||
public string OriginalKey { get; set; } = string.Empty;
|
||||
public string SourceFormat { get; set; } = string.Empty;
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
public long Bytes { get; set; }
|
||||
|
||||
public double FocusX { get; set; } = 0.5;
|
||||
public double FocusY { get; set; } = 0.5;
|
||||
public double Zoom { get; set; } = 1.0;
|
||||
public double? WideFocusX { get; set; }
|
||||
public double? WideFocusY { get; set; }
|
||||
public double? WideZoom { get; set; }
|
||||
public double? TallFocusX { get; set; }
|
||||
public double? TallFocusY { get; set; }
|
||||
public double? TallZoom { get; set; }
|
||||
|
||||
public string SetHash { get; set; } = string.Empty;
|
||||
public List<HeroVariant> Variants { get; set; } = [];
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public Guid CreatedByUserId { get; set; }
|
||||
|
||||
public FocusSetting General => new FocusSetting(FocusX, FocusY, Zoom).Normalize();
|
||||
|
||||
public FocusSetting FocusFor(string ratio) => ratio switch
|
||||
{
|
||||
"wide" when WideFocusX is not null && WideFocusY is not null => new FocusSetting(WideFocusX.Value, WideFocusY.Value, WideZoom ?? Zoom).Normalize(),
|
||||
"tall" when TallFocusX is not null && TallFocusY is not null => new FocusSetting(TallFocusX.Value, TallFocusY.Value, TallZoom ?? Zoom).Normalize(),
|
||||
_ => General,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>One file of the current set: the ratio, its pixel size, the type and the file name inside the set.</summary>
|
||||
public record HeroVariant(string Ratio, int Width, int Height, string Type, string FileName, long Bytes);
|
||||
|
||||
/// <summary>A set or an original that nothing uses any more; the clean-up deletes it once the retention time has passed.</summary>
|
||||
public class HeroRetiredFile
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary><c>set</c> (a set hash) or <c>original</c> (an original key).</summary>
|
||||
public string Kind { get; set; } = string.Empty;
|
||||
public string Key { get; set; } = string.Empty;
|
||||
public DateTimeOffset RetiredAt { get; set; }
|
||||
}
|
||||
|
||||
public static class HeroLanguages
|
||||
{
|
||||
public const string Default = "nl";
|
||||
}
|
||||
|
||||
public static class HeroDisplays
|
||||
{
|
||||
public const string Single = "single";
|
||||
public const string Slideshow = "slideshow";
|
||||
|
||||
public static bool IsValid(string? value) => value is Single or Slideshow;
|
||||
}
|
||||
Reference in New Issue
Block a user