Hero: planning en hero-brede aan/uit verwijderd (hero altijd aan, live zodra er een titel is); migratie, API, admin, tests en docs bijgewerkt

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 08:21:32 +01:00
co-authored by Claude Sonnet 5.5
parent ef62a3714f
commit b78e890f65
29 changed files with 341 additions and 285 deletions
@@ -2,7 +2,7 @@ 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>
/// <summary>The hero of the site in one language: texts, up to two buttons, the display and the slides.</summary>
public class HeroContent
{
public Guid Id { get; set; }
@@ -18,9 +18,6 @@ public class HeroContent
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; }
@@ -30,7 +30,6 @@ public class HeroDbContext(DbContextOptions<HeroDbContext> options) : DbContext(
entity.Property(e => e.Button1Target).HasMaxLength(500);
entity.Property(e => e.Button2Label).HasMaxLength(100);
entity.Property(e => e.Button2Target).HasMaxLength(500);
entity.Property(e => e.IsActive).IsRequired();
entity.Property(e => e.UpdatedAt).IsRequired();
entity.Property(e => e.LastModifiedByUserId).IsRequired();
entity.HasMany(e => e.Slides).WithOne().HasForeignKey(s => s.HeroId).OnDelete(DeleteBehavior.Cascade);
+1 -1
View File
@@ -16,7 +16,7 @@ using SlpModularCms.Modules.Hero.Services;
namespace SlpModularCms.Modules.Hero;
/// <summary>The manageable hero of a website: texts, buttons, slides with images, schedule; images are processed and served by the host.</summary>
/// <summary>The manageable hero of a website: texts, buttons, slides with images; images are processed and served by the host.</summary>
[ExcludeFromCodeCoverage]
public class HeroModule : IModule
{
@@ -29,7 +29,6 @@ public static class HeroTexts
public static readonly TextKey TooMany = new("hero.validation.button.tooMany", "max");
}
public static readonly TextKey EndAfterStart = new("hero.validation.schedule.endAfterStart");
public static class Slide
{
@@ -0,0 +1,247 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SlpModularCms.Modules.Hero.Data;
#nullable disable
namespace SlpModularCms.Modules.Hero.Migrations
{
[DbContext(typeof(HeroDbContext))]
[Migration("20261117071410_RemoveHeroScheduleAndSwitch")]
partial class RemoveHeroScheduleAndSwitch
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("SlpModularCms.Modules.Hero.Data.Entities.HeroContent", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Button1Label")
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.Property<string>("Button1Target")
.HasMaxLength(500)
.HasColumnType("varchar(500)");
b.Property<string>("Button2Label")
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.Property<string>("Button2Target")
.HasMaxLength(500)
.HasColumnType("varchar(500)");
b.Property<string>("Display")
.IsRequired()
.HasMaxLength(20)
.HasColumnType("varchar(20)");
b.Property<string>("Language")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("varchar(10)");
b.Property<Guid>("LastModifiedByUserId")
.HasColumnType("char(36)");
b.Property<string>("Lead")
.HasMaxLength(1000)
.HasColumnType("varchar(1000)");
b.Property<string>("Tagline")
.HasMaxLength(200)
.HasColumnType("varchar(200)");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(1000)
.HasColumnType("varchar(1000)");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("datetime");
b.HasKey("Id");
b.HasIndex("Language")
.IsUnique();
b.ToTable("Heroes", (string)null);
});
modelBuilder.Entity("SlpModularCms.Modules.Hero.Data.Entities.HeroImage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<long>("Bytes")
.HasColumnType("bigint");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("datetime");
b.Property<Guid>("CreatedByUserId")
.HasColumnType("char(36)");
b.Property<double>("FocusX")
.HasColumnType("double");
b.Property<double>("FocusY")
.HasColumnType("double");
b.Property<int>("Height")
.HasColumnType("int");
b.Property<string>("OriginalKey")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)");
b.Property<string>("OriginalSha256")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("varchar(64)");
b.Property<string>("SetHash")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("varchar(16)");
b.Property<string>("SourceFormat")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("varchar(10)");
b.Property<double?>("TallFocusX")
.HasColumnType("double");
b.Property<double?>("TallFocusY")
.HasColumnType("double");
b.Property<double?>("TallZoom")
.HasColumnType("double");
b.Property<string>("Variants")
.IsRequired()
.HasColumnType("longtext");
b.Property<double?>("WideFocusX")
.HasColumnType("double");
b.Property<double?>("WideFocusY")
.HasColumnType("double");
b.Property<double?>("WideZoom")
.HasColumnType("double");
b.Property<int>("Width")
.HasColumnType("int");
b.Property<double>("Zoom")
.HasColumnType("double");
b.HasKey("Id");
b.HasIndex("OriginalSha256")
.IsUnique();
b.ToTable("HeroImages", (string)null);
});
modelBuilder.Entity("SlpModularCms.Modules.Hero.Data.Entities.HeroRetiredFile", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Key")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("varchar(200)");
b.Property<string>("Kind")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("varchar(10)");
b.Property<DateTimeOffset>("RetiredAt")
.HasColumnType("datetime");
b.HasKey("Id");
b.ToTable("HeroRetiredFiles", (string)null);
});
modelBuilder.Entity("SlpModularCms.Modules.Hero.Data.Entities.HeroSlide", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Alt")
.IsRequired()
.HasMaxLength(600)
.HasColumnType("varchar(600)");
b.Property<bool>("Decorative")
.HasColumnType("tinyint(1)");
b.Property<Guid>("HeroId")
.HasColumnType("char(36)");
b.Property<Guid>("ImageId")
.HasColumnType("char(36)");
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.Property<int>("SortOrder")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ImageId");
b.HasIndex("HeroId", "SortOrder");
b.ToTable("HeroSlides", (string)null);
});
modelBuilder.Entity("SlpModularCms.Modules.Hero.Data.Entities.HeroSlide", b =>
{
b.HasOne("SlpModularCms.Modules.Hero.Data.Entities.HeroContent", null)
.WithMany("Slides")
.HasForeignKey("HeroId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("SlpModularCms.Modules.Hero.Data.Entities.HeroImage", "Image")
.WithMany()
.HasForeignKey("ImageId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Image");
});
modelBuilder.Entity("SlpModularCms.Modules.Hero.Data.Entities.HeroContent", b =>
{
b.Navigation("Slides");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,50 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SlpModularCms.Modules.Hero.Migrations
{
/// <inheritdoc />
public partial class RemoveHeroScheduleAndSwitch : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "EndsAt",
table: "Heroes");
migrationBuilder.DropColumn(
name: "IsActive",
table: "Heroes");
migrationBuilder.DropColumn(
name: "StartsAt",
table: "Heroes");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTimeOffset>(
name: "EndsAt",
table: "Heroes",
type: "datetime",
nullable: true);
migrationBuilder.AddColumn<bool>(
name: "IsActive",
table: "Heroes",
type: "tinyint(1)",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<DateTimeOffset>(
name: "StartsAt",
table: "Heroes",
type: "datetime",
nullable: true);
}
}
}
@@ -46,12 +46,6 @@ namespace SlpModularCms.Modules.Hero.Migrations
.HasMaxLength(20)
.HasColumnType("varchar(20)");
b.Property<DateTimeOffset?>("EndsAt")
.HasColumnType("datetime");
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.Property<string>("Language")
.IsRequired()
.HasMaxLength(10)
@@ -64,9 +58,6 @@ namespace SlpModularCms.Modules.Hero.Migrations
.HasMaxLength(1000)
.HasColumnType("varchar(1000)");
b.Property<DateTimeOffset?>("StartsAt")
.HasColumnType("datetime");
b.Property<string>("Tagline")
.HasMaxLength(200)
.HasColumnType("varchar(200)");
@@ -43,9 +43,6 @@ public record HeroAdminDto(
string? Lead,
string Display,
IReadOnlyList<HeroButtonDto> Buttons,
bool IsActive,
DateTimeOffset? StartsAt,
DateTimeOffset? EndsAt,
IReadOnlyList<HeroSlideAdminDto> Slides,
bool IsLive,
DateTimeOffset? UpdatedAt,
@@ -62,7 +59,7 @@ public record PublicImageDto(
public record PublicSlideDto(string Id, string Alt, bool Decorative, PublicImageDto Image);
/// <summary>What visitors and websites get: only content, never the schedule or on/off switches. The same shape is written into <c>#cms-data</c>.</summary>
/// <summary>What visitors and websites get: only content, never admin-only state. The same shape is written into <c>#cms-data</c>.</summary>
public record PublicHeroDto(
string Display,
string Title,
@@ -107,9 +104,6 @@ public record HeroSaveRequest(
string? Lead,
string? Display,
IReadOnlyList<HeroButtonRequest>? Buttons,
bool IsActive,
DateTimeOffset? StartsAt,
DateTimeOffset? EndsAt,
IReadOnlyList<HeroSlideRequest>? Slides,
IReadOnlyList<HeroImageFocusRequest>? ImageFocus = null) : IValidatableObject
{
@@ -195,11 +189,6 @@ public record HeroSaveRequest(
}
}
if (StartsAt is not null && EndsAt is not null && EndsAt <= StartsAt)
{
yield return new ValidationResult(texts.Get(HeroTexts.Validation.EndAfterStart), [nameof(EndsAt)]);
}
var focusEdits = ImageFocus ?? [];
for (var i = 0; i < focusEdits.Count; i++)
{
@@ -93,11 +93,8 @@ public static class HeroMapping
NeedsRender(image),
PreviewSrc: PreviewSrc(image));
public static bool IsLive(HeroContent hero, DateTimeOffset now)
=> hero.IsActive
&& !string.IsNullOrWhiteSpace(hero.Title)
&& (hero.StartsAt is null || hero.StartsAt <= now)
&& (hero.EndsAt is null || now < hero.EndsAt);
/// <summary>The hero is always on: it is live as soon as it has usable content (a title). There is no switch and no schedule (a deliberate choice; they may come back later, per slide).</summary>
public static bool IsLive(HeroContent hero) => !string.IsNullOrWhiteSpace(hero.Title);
private static List<HeroButtonDto> Buttons(HeroContent hero)
{
@@ -118,7 +115,7 @@ public static class HeroMapping
/// <summary>The published hero, or null when it is not live. Inactive slides and slides without a stored image are left out.</summary>
public static PublicHeroDto? ToPublic(HeroContent hero, DateTimeOffset now, int maxPublishedSlides)
{
if (!IsLive(hero, now))
if (!IsLive(hero))
{
return null;
}
@@ -159,7 +156,7 @@ public static class HeroMapping
{
if (hero is null)
{
return new HeroAdminDto(null, string.Empty, null, null, HeroDisplays.Single, [], true, null, null, [], false, null, maxPublishedSlides);
return new HeroAdminDto(null, string.Empty, null, null, HeroDisplays.Single, [], [], false, null, maxPublishedSlides);
}
var slides = hero.Slides
@@ -175,11 +172,8 @@ public static class HeroMapping
hero.Lead,
hero.Display,
Buttons(hero),
hero.IsActive,
hero.StartsAt,
hero.EndsAt,
slides,
IsLive(hero, now),
IsLive(hero),
hero.UpdatedAt,
maxPublishedSlides);
}
@@ -19,7 +19,7 @@ public interface IHeroService
/// <summary>The hero for the admin (empty defaults when none exists yet), with whether it is live right now.</summary>
Task<HeroAdminDto> GetAsync(CancellationToken cancellationToken);
/// <summary>Replaces the whole hero: texts, buttons, display, schedule and the ordered slide list.</summary>
/// <summary>Replaces the whole hero: texts, buttons, display and the ordered slide list.</summary>
Task<HeroAdminDto> SaveAsync(HeroSaveRequest request, Guid callerId, CancellationToken cancellationToken);
}
@@ -163,9 +163,6 @@ public class HeroService(
hero.Button2Label = buttons.Count > 1 ? buttons[1].Label : null;
hero.Button2Target = buttons.Count > 1 ? buttons[1].Target : null;
hero.IsActive = r.IsActive;
hero.StartsAt = r.StartsAt;
hero.EndsAt = r.EndsAt;
hero.UpdatedAt = now;
hero.LastModifiedByUserId = callerId;
}
@@ -175,7 +172,7 @@ public class HeroService(
public interface IPublicHeroService
{
/// <summary>The hero as websites get it, or null (no hero, switched off, outside the schedule or without a title).</summary>
/// <summary>The hero as websites get it, or null (no hero or without a title).</summary>
Task<PublicHeroDto?> GetActiveAsync(CancellationToken cancellationToken);
}
@@ -22,9 +22,6 @@
"targetInvalid": "Choose a part of the page (for example #contact), a page of the site (for example /privacy) or a full web address (https://…).",
"tooMany": "At most {max} buttons are possible."
},
"schedule": {
"endAfterStart": "The end must be after the start."
},
"slide": {
"imageRequired": "Every image in the list needs a photo.",
"imageUnknown": "An image in the list does not exist (any more).",
@@ -22,9 +22,6 @@
"targetInvalid": "Kies een onderdeel van de pagina (bijvoorbeeld #contact), een pagina van de site (bijvoorbeeld /privacy) of een volledig webadres (https://…).",
"tooMany": "Er zijn maximaal {max} knoppen mogelijk."
},
"schedule": {
"endAfterStart": "Het einde moet na het begin liggen."
},
"slide": {
"imageRequired": "Elke afbeelding in de lijst heeft een foto nodig.",
"imageUnknown": "Een afbeelding in de lijst bestaat niet (meer).",