Aanbiedingen: planning en aan/uit per pakket, admin-lijst /offerings/all, Annuleren op het pakketformulier

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 11:42:26 +01:00
co-authored by Claude Sonnet 5.5
parent 321234dfa6
commit 8af156c238
29 changed files with 916 additions and 73 deletions
@@ -29,6 +29,10 @@ public class OfferingsController(IOfferingsService service) : ControllerBase
return Ok(offerings);
}
/// <summary>Administrator list including switched-off, planned and expired offerings.</summary>
[HttpGet("all")]
public async Task<IActionResult> ListAll() => Ok(await service.ListAllAsync());
[HttpPost]
public async Task<IActionResult> Create([FromBody] CreateOfferingRequest request)
{
@@ -14,6 +14,12 @@ public class Offering
public Guid? CategoryId { get; set; }
public OfferingCategory? Category { get; set; }
public int DisplayOrder { get; set; }
/// <summary>Switched on. A switched-off offering is never shown publicly (it stays in the admin list).</summary>
public bool IsActive { get; set; } = true;
/// <summary>First moment it is shown (inclusive); null = no start limit.</summary>
public DateTimeOffset? StartsAt { get; set; }
/// <summary>First moment it is no longer shown (exclusive); null = no end limit.</summary>
public DateTimeOffset? EndsAt { get; set; }
public bool IsDeleted { get; set; }
public DateTimeOffset? DeletedAt { get; set; }
public DateTimeOffset CreatedAt { get; set; }
@@ -26,6 +26,7 @@ public class OfferingsDbContext(DbContextOptions<OfferingsDbContext> options) :
entity.Property(e => e.PriceNote).IsRequired().HasMaxLength(100);
entity.Property(e => e.CtaLabel).IsRequired().HasMaxLength(50);
entity.Property(e => e.DisplayOrder).IsRequired();
entity.Property(e => e.IsActive).IsRequired().HasDefaultValue(true);
entity.Property(e => e.IsDeleted).IsRequired();
entity.Property(e => e.CreatedAt).IsRequired();
entity.Property(e => e.UpdatedAt).IsRequired();
@@ -0,0 +1,200 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SlpModularCms.Modules.Offerings.Data;
#nullable disable
namespace SlpModularCms.Modules.Offerings.Migrations
{
[DbContext(typeof(OfferingsDbContext))]
[Migration("20261115100000_AddOfferingSchedule")]
partial class AddOfferingSchedule
{
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.Offerings.Data.Entities.OfferingBanner", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("datetime");
b.Property<DateTimeOffset?>("EndsAt")
.HasColumnType("datetime");
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.Property<Guid>("LastModifiedByUserId")
.HasColumnType("char(36)");
b.Property<string>("LinkLabel")
.HasMaxLength(50)
.HasColumnType("varchar(50)");
b.Property<string>("LinkUrl")
.HasMaxLength(500)
.HasColumnType("varchar(500)");
b.Property<DateTimeOffset?>("StartsAt")
.HasColumnType("datetime");
b.Property<string>("Position")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(10)
.HasColumnType("varchar(10)")
.HasDefaultValue("bottom");
b.Property<string>("Text")
.IsRequired()
.HasMaxLength(300)
.HasColumnType("varchar(300)");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("datetime");
b.HasKey("Id");
b.ToTable("OfferingsBanners", (string)null);
});
modelBuilder.Entity("SlpModularCms.Modules.Offerings.Data.Entities.Offering", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<Guid?>("CategoryId")
.HasColumnType("char(36)");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("datetime");
b.Property<string>("CtaLabel")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("varchar(50)");
b.Property<DateTimeOffset?>("DeletedAt")
.HasColumnType("datetime");
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("varchar(500)");
b.Property<int>("DisplayOrder")
.HasColumnType("int");
b.Property<DateTimeOffset?>("EndsAt")
.HasColumnType("datetime");
b.Property<bool>("Featured")
.HasColumnType("tinyint(1)");
b.Property<string>("Features")
.IsRequired()
.HasColumnType("longtext");
b.Property<bool>("IsActive")
.ValueGeneratedOnAdd()
.HasColumnType("tinyint(1)")
.HasDefaultValue(true);
b.Property<bool>("IsDeleted")
.HasColumnType("tinyint(1)");
b.Property<Guid>("LastModifiedByUserId")
.HasColumnType("char(36)");
b.Property<string>("Price")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("varchar(50)");
b.Property<string>("PriceNote")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.Property<string>("Slug")
.IsRequired()
.HasMaxLength(130)
.HasColumnType("varchar(130)");
b.Property<DateTimeOffset?>("StartsAt")
.HasColumnType("datetime");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("datetime");
b.HasKey("Id");
b.HasIndex("CategoryId");
b.ToTable("OfferingsOfferings", (string)null);
});
modelBuilder.Entity("SlpModularCms.Modules.Offerings.Data.Entities.OfferingCategory", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("datetime");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.Property<int>("SortOrder")
.HasColumnType("int");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("datetime");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("OfferingsCategories", (string)null);
});
modelBuilder.Entity("SlpModularCms.Modules.Offerings.Data.Entities.Offering", b =>
{
b.HasOne("SlpModularCms.Modules.Offerings.Data.Entities.OfferingCategory", "Category")
.WithMany()
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Restrict);
b.Navigation("Category");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,43 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SlpModularCms.Modules.Offerings.Migrations
{
/// <inheritdoc />
public partial class AddOfferingSchedule : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
// Existing offerings stay switched on without a schedule: nothing changes for the websites.
migrationBuilder.AddColumn<bool>(
name: "IsActive",
table: "OfferingsOfferings",
type: "tinyint(1)",
nullable: false,
defaultValue: true);
migrationBuilder.AddColumn<DateTimeOffset>(
name: "StartsAt",
table: "OfferingsOfferings",
type: "datetime",
nullable: true);
migrationBuilder.AddColumn<DateTimeOffset>(
name: "EndsAt",
table: "OfferingsOfferings",
type: "datetime",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(name: "EndsAt", table: "OfferingsOfferings");
migrationBuilder.DropColumn(name: "StartsAt", table: "OfferingsOfferings");
migrationBuilder.DropColumn(name: "IsActive", table: "OfferingsOfferings");
}
}
}
@@ -1,4 +1,4 @@
// <auto-generated />
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
@@ -101,6 +101,9 @@ namespace SlpModularCms.Modules.Offerings.Migrations
b.Property<int>("DisplayOrder")
.HasColumnType("int");
b.Property<DateTimeOffset?>("EndsAt")
.HasColumnType("datetime");
b.Property<bool>("Featured")
.HasColumnType("tinyint(1)");
@@ -108,6 +111,11 @@ namespace SlpModularCms.Modules.Offerings.Migrations
.IsRequired()
.HasColumnType("longtext");
b.Property<bool>("IsActive")
.ValueGeneratedOnAdd()
.HasColumnType("tinyint(1)")
.HasDefaultValue(true);
b.Property<bool>("IsDeleted")
.HasColumnType("tinyint(1)");
@@ -129,6 +137,9 @@ namespace SlpModularCms.Modules.Offerings.Migrations
.HasMaxLength(130)
.HasColumnType("varchar(130)");
b.Property<DateTimeOffset?>("StartsAt")
.HasColumnType("datetime");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(100)
@@ -11,5 +11,12 @@ public record CreateOfferingRequest(
[Required(AllowEmptyStrings = true), MaxLength(50)] string CtaLabel,
bool Featured = false,
[MaxLength(130)] string? Slug = null,
Guid? CategoryId = null
);
Guid? CategoryId = null,
bool IsActive = true,
DateTimeOffset? StartsAt = null,
DateTimeOffset? EndsAt = null
) : IValidatableObject
{
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
=> OfferingSchedule.Validate(StartsAt, EndsAt);
}
@@ -21,3 +21,26 @@ public record OfferingDto(
string? CategoryId = null,
string? Category = null
);
/// <summary>
/// Administrator view: the public representation plus the switch and the schedule. Never returned by the
/// public endpoint, whose JSON shape stays as websites expect it.
/// </summary>
[ExcludeFromCodeCoverage]
public record OfferingAdminDto(
string Id,
string Slug,
string Title,
string Description,
string Price,
string PriceNote,
IReadOnlyList<string> Features,
string CtaLabel,
bool Featured,
int DisplayOrder,
string? CategoryId,
string? Category,
bool IsActive,
DateTimeOffset? StartsAt,
DateTimeOffset? EndsAt
) : OfferingDto(Id, Slug, Title, Description, Price, PriceNote, Features, CtaLabel, Featured, DisplayOrder, CategoryId, Category);
@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
using SlpModularCms.Modules.Offerings.Data.Entities;
namespace SlpModularCms.Modules.Offerings.Models;
/// <summary>The one rule for "is this offering shown right now", shared by the public list and the SEO injection.</summary>
public static class OfferingSchedule
{
public static IEnumerable<ValidationResult> Validate(DateTimeOffset? startsAt, DateTimeOffset? endsAt)
{
if (startsAt is not null && endsAt is not null && endsAt <= startsAt)
yield return new ValidationResult("EndsAt must be after StartsAt.", [nameof(OfferingBanner.EndsAt)]);
}
/// <summary>Switched on, started (inclusive) and not yet ended (exclusive).</summary>
public static bool IsLive(Offering o, DateTimeOffset now)
=> o.IsActive && (o.StartsAt is null || o.StartsAt <= now) && (o.EndsAt is null || now < o.EndsAt);
}
@@ -11,5 +11,12 @@ public record UpdateOfferingRequest(
[Required(AllowEmptyStrings = true), MaxLength(50)] string CtaLabel,
bool Featured = false,
[MaxLength(130)] string? Slug = null,
Guid? CategoryId = null
);
Guid? CategoryId = null,
bool IsActive = true,
DateTimeOffset? StartsAt = null,
DateTimeOffset? EndsAt = null
) : IValidatableObject
{
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
=> OfferingSchedule.Validate(StartsAt, EndsAt);
}
@@ -4,9 +4,14 @@ namespace SlpModularCms.Modules.Offerings.Services;
public interface IOfferingsService
{
/// <summary>What visitors get: only offerings switched on and inside their schedule right now.</summary>
Task<IReadOnlyList<OfferingDto>> GetOfferingsAsync();
Task<OfferingDto> CreateAsync(CreateOfferingRequest request, Guid callerId);
Task<OfferingDto?> UpdateAsync(Guid id, UpdateOfferingRequest request, Guid callerId);
/// <summary>What administrators get: every offering with its switch and schedule.</summary>
Task<IReadOnlyList<OfferingAdminDto>> ListAllAsync();
Task<OfferingAdminDto> CreateAsync(CreateOfferingRequest request, Guid callerId);
Task<OfferingAdminDto?> UpdateAsync(Guid id, UpdateOfferingRequest request, Guid callerId);
Task<bool> DeleteAsync(Guid id, Guid callerId);
/// <summary>
@@ -10,15 +10,24 @@ public class OfferingsService(
IOfferingRepository repository,
IOfferingCategoryRepository categories,
ILogger<OfferingsService> logger,
IIndexHtmlCache? indexCache = null) : IOfferingsService
IIndexHtmlCache? indexCache = null,
TimeProvider? time = null) : IOfferingsService
{
private readonly TimeProvider _time = time ?? TimeProvider.System;
/// <summary>Public list: only offerings that are switched on and inside their schedule right now.</summary>
public async Task<IReadOnlyList<OfferingDto>> GetOfferingsAsync()
{
var now = _time.GetUtcNow();
var offerings = await repository.GetAllAsync();
return offerings.Select(ToDto).ToList();
return offerings.Where(o => OfferingSchedule.IsLive(o, now)).Select(ToDto).ToList();
}
public async Task<OfferingDto> CreateAsync(CreateOfferingRequest request, Guid callerId)
/// <summary>Administrator list: everything, including switched-off, planned and expired offerings.</summary>
public async Task<IReadOnlyList<OfferingAdminDto>> ListAllAsync()
=> (await repository.GetAllAsync()).Select(ToAdminDto).ToList();
public async Task<OfferingAdminDto> CreateAsync(CreateOfferingRequest request, Guid callerId)
{
var category = await ResolveCategoryAsync(request.CategoryId);
var now = DateTimeOffset.UtcNow;
@@ -35,6 +44,9 @@ public class OfferingsService(
CategoryId = category?.Id,
Category = category,
Featured = request.Featured,
IsActive = request.IsActive,
StartsAt = request.StartsAt,
EndsAt = request.EndsAt,
DisplayOrder = await repository.GetMaxDisplayOrderAsync() + 1,
CreatedAt = now,
UpdatedAt = now,
@@ -64,10 +76,10 @@ public class OfferingsService(
"Offering {OfferingId} {Action} by user {LastModifiedByUserId}",
offering.Id, "Created", callerId);
return ToDto(offering);
return ToAdminDto(offering);
}
public async Task<OfferingDto?> UpdateAsync(Guid id, UpdateOfferingRequest request, Guid callerId)
public async Task<OfferingAdminDto?> UpdateAsync(Guid id, UpdateOfferingRequest request, Guid callerId)
{
var offering = await repository.GetByIdAsync(id);
if (offering is null)
@@ -93,6 +105,9 @@ public class OfferingsService(
offering.CategoryId = category?.Id;
offering.Category = category;
offering.Featured = request.Featured;
offering.IsActive = request.IsActive;
offering.StartsAt = request.StartsAt;
offering.EndsAt = request.EndsAt;
offering.UpdatedAt = DateTimeOffset.UtcNow;
offering.LastModifiedByUserId = callerId;
@@ -115,7 +130,7 @@ public class OfferingsService(
"Offering {OfferingId} {Action} by user {LastModifiedByUserId}",
offering.Id, "Updated", callerId);
return ToDto(offering);
return ToAdminDto(offering);
}
public async Task<bool> DeleteAsync(Guid id, Guid callerId)
@@ -245,4 +260,22 @@ public class OfferingsService(
o.CategoryId?.ToString(),
o.Category?.Name
);
private static OfferingAdminDto ToAdminDto(Offering o) => new(
o.Id.ToString(),
o.Slug,
o.Title,
o.Description,
o.Price,
o.PriceNote,
o.Features,
o.CtaLabel,
o.Featured,
o.DisplayOrder,
o.CategoryId?.ToString(),
o.Category?.Name,
o.IsActive,
o.StartsAt,
o.EndsAt
);
}