Offerings: banner krijgt positie top|bottom (backend, migratie, admin-tab, OpenAPI)
- OfferingBanner.Position ('top'|'bottom'); bestaande banners worden 'bottom' (migratie AddOfferingBannerPosition)
- GET /api/v1/offerings/banner?position=top|bottom: zonder parameter bottom, 204 zonder actieve banner, 400 bij ongeldige waarde; antwoord bevat position
- Max 1 actieve banner per positie (laatst gewijzigde binnen de planning wint); top en bottom kunnen tegelijk actief zijn
- Top: tekst max 120 tekens, titel optioneel; bottom: titel verplicht
- Admin: Banner-tab met twee secties (Boven/Onder), eigen aanmaken en aan/uit per plek
- OpenAPI-snapshot met de hand bijgewerkt (geen lokale MariaDB): CI bevestigt
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,8 +10,8 @@ public interface IOfferingBannersService
|
||||
{
|
||||
Task<IReadOnlyList<OfferingBannerDto>> ListAsync();
|
||||
|
||||
/// <summary>The one banner that is switched on and inside its schedule right now, or null.</summary>
|
||||
Task<PublicOfferingBannerDto?> GetActiveAsync();
|
||||
/// <summary>The one banner at <paramref name="position"/> that is switched on and inside its schedule right now, or null.</summary>
|
||||
Task<PublicOfferingBannerDto?> GetActiveAsync(string position);
|
||||
|
||||
Task<OfferingBannerDto> CreateAsync(OfferingBannerRequest request, Guid callerId);
|
||||
Task<OfferingBannerDto?> UpdateAsync(Guid id, OfferingBannerRequest request, Guid callerId);
|
||||
@@ -29,17 +29,19 @@ public class OfferingBannersService(
|
||||
public async Task<IReadOnlyList<OfferingBannerDto>> ListAsync()
|
||||
=> (await repository.GetAllAsync()).Select(ToDto).ToList();
|
||||
|
||||
public async Task<PublicOfferingBannerDto?> GetActiveAsync()
|
||||
public async Task<PublicOfferingBannerDto?> GetActiveAsync(string position)
|
||||
{
|
||||
var now = _time.GetUtcNow();
|
||||
|
||||
// Several can be switched on (planned ones, overlaps); the most recently changed wins.
|
||||
// Several can be switched on (planned ones, overlaps); per position the most recently changed wins,
|
||||
// so a top and a bottom banner can be shown at the same time.
|
||||
var current = (await repository.GetSwitchedOnAsync())
|
||||
.Where(b => b.Position == position)
|
||||
.Where(b => (b.StartsAt is null || b.StartsAt <= now) && (b.EndsAt is null || now < b.EndsAt))
|
||||
.OrderByDescending(b => b.UpdatedAt)
|
||||
.FirstOrDefault();
|
||||
|
||||
return current is null ? null : new PublicOfferingBannerDto(current.Title, current.Text, current.LinkLabel, current.LinkUrl);
|
||||
return current is null ? null : new PublicOfferingBannerDto(current.Title, current.Text, current.LinkLabel, current.LinkUrl, current.Position);
|
||||
}
|
||||
|
||||
public async Task<OfferingBannerDto> CreateAsync(OfferingBannerRequest request, Guid callerId)
|
||||
@@ -83,7 +85,8 @@ public class OfferingBannersService(
|
||||
private static void Apply(OfferingBanner b, OfferingBannerRequest r, DateTimeOffset now, Guid callerId)
|
||||
{
|
||||
var hasLink = !string.IsNullOrWhiteSpace(r.LinkUrl) && !string.IsNullOrWhiteSpace(r.LinkLabel);
|
||||
b.Title = r.Title.Trim();
|
||||
b.Position = r.Position;
|
||||
b.Title = (r.Title ?? string.Empty).Trim();
|
||||
b.Text = r.Text.Trim();
|
||||
b.LinkLabel = hasLink ? r.LinkLabel!.Trim() : null;
|
||||
b.LinkUrl = hasLink ? r.LinkUrl!.Trim() : null;
|
||||
@@ -101,5 +104,5 @@ public class OfferingBannersService(
|
||||
}
|
||||
|
||||
private static OfferingBannerDto ToDto(OfferingBanner b) => new(
|
||||
b.Id.ToString(), b.Title, b.Text, b.LinkLabel, b.LinkUrl, b.IsActive, b.StartsAt, b.EndsAt, b.UpdatedAt);
|
||||
b.Id.ToString(), b.Position, b.Title, b.Text, b.LinkLabel, b.LinkUrl, b.IsActive, b.StartsAt, b.EndsAt, b.UpdatedAt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user