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
@@ -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
);
}