Adds the Offerings module and retargets the CI/CD pipeline to Api.SlpSoftware
Continuous Integration / config (pull_request) Successful in 12s
Continuous Integration / changes (pull_request) Successful in 22s
Continuous Integration / backend-build (pull_request) Successful in 5m53s
Continuous Integration / vulnerability-scan (pull_request) Successful in 5m46s
Continuous Integration / frontend-prepare (pull_request) Successful in 1m54s
Continuous Integration / backend-test (pull_request) Successful in 7m37s
Continuous Integration / frontend-build (pull_request) Successful in 2m14s
Continuous Integration / frontend-test (pull_request) Successful in 4m59s
Continuous Integration / frontend-lint (pull_request) Successful in 2m2s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 7m34s
Continuous Integration / deploy-test (pull_request) Skipped

Implements Unit 2 "Offerings" (backend module, admin CRUD UI with
drag-and-drop reordering, public GET /api/v1/offerings endpoint) and
executes the feature's D-15 CI/CD cutover, switching the deploy
pipeline's build/publish target from SlpModularCms.Api to
SlpModularCms.Api.SlpSoftware.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FWyStNL2ZsjrS7FLd7xvvN
This commit is contained in:
2026-08-02 16:23:09 +02:00
co-authored by Claude Sonnet 5
parent b6e9c07c06
commit cfb06b28b6
79 changed files with 4069 additions and 94 deletions
@@ -0,0 +1,78 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
using SlpModularCms.Modules.Offerings.Models;
using SlpModularCms.Modules.Offerings.Services;
namespace SlpModularCms.Modules.Offerings.Controllers;
[ApiController]
[Route("offerings")]
[Authorize(Policy = "AdminOnly")]
public class OfferingsController(IOfferingsService service) : ControllerBase
{
[HttpGet]
[AllowAnonymous]
[EnableRateLimiting("offerings-public")]
public async Task<IActionResult> GetOfferings()
{
var offerings = await service.GetPublicOfferingsAsync();
return Ok(offerings);
}
[HttpGet("admin")]
public async Task<IActionResult> GetAllForAdmin()
{
var offerings = await service.GetAllForAdminAsync();
return Ok(offerings);
}
[HttpPost("admin")]
public async Task<IActionResult> Create([FromBody] CreateOfferingRequest request)
{
var dto = await service.CreateAsync(request, GetCallerId());
return CreatedAtAction(nameof(GetAllForAdmin), null, dto);
}
[HttpPut("admin/{id:guid}")]
public async Task<IActionResult> Update(Guid id, [FromBody] UpdateOfferingRequest request)
{
var dto = await service.UpdateAsync(id, request, GetCallerId());
return dto is null ? NotFound() : Ok(dto);
}
[HttpDelete("admin/{id:guid}")]
public async Task<IActionResult> Delete(Guid id)
{
var deleted = await service.DeleteAsync(id, GetCallerId());
return deleted ? NoContent() : NotFound();
}
[HttpPut("admin/reorder")]
public async Task<IActionResult> Reorder([FromBody] ReorderOfferingsRequest request)
{
await service.ReorderAsync(request.OrderedIds, GetCallerId());
return NoContent();
}
[HttpPost("admin/{id:guid}/move-up")]
public async Task<IActionResult> MoveUp(Guid id)
{
await service.MoveUpAsync(id, GetCallerId());
return NoContent();
}
[HttpPost("admin/{id:guid}/move-down")]
public async Task<IActionResult> MoveDown(Guid id)
{
await service.MoveDownAsync(id, GetCallerId());
return NoContent();
}
private Guid GetCallerId()
{
var claim = User.FindFirstValue(ClaimTypes.NameIdentifier) ?? User.FindFirstValue("sub");
return Guid.TryParse(claim, out var id) ? id : Guid.Empty;
}
}
@@ -0,0 +1,19 @@
namespace SlpModularCms.Modules.Offerings.Data.Entities;
public class Offering
{
public Guid Id { get; set; }
public string Title { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public string Price { get; set; } = string.Empty;
public string PriceNote { get; set; } = string.Empty;
public List<string> Features { get; set; } = [];
public string CtaLabel { get; set; } = string.Empty;
public bool Featured { get; set; }
public int DisplayOrder { get; set; }
public bool IsDeleted { get; set; }
public DateTimeOffset? DeletedAt { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
public Guid LastModifiedByUserId { get; set; }
}
@@ -0,0 +1,46 @@
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using SlpModularCms.Modules.Offerings.Data.Entities;
namespace SlpModularCms.Modules.Offerings.Data;
public class OfferingsDbContext(DbContextOptions<OfferingsDbContext> options) : DbContext(options)
{
public DbSet<Offering> Offerings => Set<Offering>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Offering>(entity =>
{
entity.ToTable("OfferingsOfferings");
entity.HasKey(e => e.Id);
entity.Property(e => e.Title).IsRequired().HasMaxLength(100);
entity.Property(e => e.Description).IsRequired().HasMaxLength(500);
entity.Property(e => e.Price).IsRequired().HasMaxLength(50);
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.IsDeleted).IsRequired();
entity.Property(e => e.CreatedAt).IsRequired();
entity.Property(e => e.UpdatedAt).IsRequired();
entity.Property(e => e.LastModifiedByUserId).IsRequired();
// Features is a small, always-fully-replaced string list (max 10 items of max 200
// chars) — a JSON column is simpler than a child table for something never queried
// by individual feature value.
entity.Property(e => e.Features)
.HasConversion(
features => JsonSerializer.Serialize(features, (JsonSerializerOptions?)null),
json => JsonSerializer.Deserialize<List<string>>(json, (JsonSerializerOptions?)null) ?? new List<string>())
.Metadata.SetValueComparer(new ValueComparer<List<string>>(
(a, b) => (a ?? new List<string>()).SequenceEqual(b ?? new List<string>()),
v => v.Aggregate(0, (hash, item) => HashCode.Combine(hash, item.GetHashCode())),
v => v.ToList()));
entity.HasQueryFilter(e => !e.IsDeleted);
});
}
}
@@ -0,0 +1,88 @@
// <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("20260802124751_InitialCreate")]
partial class InitialCreate
{
/// <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.Offerings.Data.Entities.Offering", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.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<bool>("Featured")
.HasColumnType("tinyint(1)");
b.Property<string>("Features")
.IsRequired()
.HasColumnType("longtext");
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>("Title")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("datetime");
b.HasKey("Id");
b.ToTable("OfferingsOfferings", (string)null);
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,50 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SlpModularCms.Modules.Offerings.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("MySQL:Charset", "utf8mb4");
migrationBuilder.CreateTable(
name: "OfferingsOfferings",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false),
Title = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false),
Description = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false),
Price = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false),
PriceNote = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false),
Features = table.Column<string>(type: "longtext", nullable: false),
CtaLabel = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false),
Featured = table.Column<bool>(type: "tinyint(1)", nullable: false),
DisplayOrder = table.Column<int>(type: "int", nullable: false),
IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
DeletedAt = table.Column<DateTimeOffset>(type: "datetime", nullable: true),
CreatedAt = table.Column<DateTimeOffset>(type: "datetime", nullable: false),
UpdatedAt = table.Column<DateTimeOffset>(type: "datetime", nullable: false),
LastModifiedByUserId = table.Column<Guid>(type: "char(36)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_OfferingsOfferings", x => x.Id);
})
.Annotation("MySQL:Charset", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "OfferingsOfferings");
}
}
}
@@ -0,0 +1,85 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using SlpModularCms.Modules.Offerings.Data;
#nullable disable
namespace SlpModularCms.Modules.Offerings.Migrations
{
[DbContext(typeof(OfferingsDbContext))]
partial class OfferingsDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("SlpModularCms.Modules.Offerings.Data.Entities.Offering", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.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<bool>("Featured")
.HasColumnType("tinyint(1)");
b.Property<string>("Features")
.IsRequired()
.HasColumnType("longtext");
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>("Title")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("datetime");
b.HasKey("Id");
b.ToTable("OfferingsOfferings", (string)null);
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace SlpModularCms.Modules.Offerings.Models;
public record CreateOfferingRequest(
[Required, MaxLength(100)] string Title,
[Required, MaxLength(500)] string Description,
[Required, MaxLength(50)] string Price,
[Required, MaxLength(100)] string PriceNote,
[Required, FeaturesValidation] List<string> Features,
[Required, MaxLength(50)] string CtaLabel,
bool Featured = false
);
@@ -0,0 +1,33 @@
using System.ComponentModel.DataAnnotations;
namespace SlpModularCms.Modules.Offerings.Models;
/// <summary>
/// DataAnnotations has no built-in way to bound both collection size and each item's
/// length (BR-OFF-04: 1-10 features, each &#8804;200 characters) — this attribute covers
/// what <see cref="MinLengthAttribute"/>/<see cref="MaxLengthAttribute"/> alone cannot.
/// </summary>
public class FeaturesValidationAttribute : ValidationAttribute
{
private const int MinItems = 1;
private const int MaxItems = 10;
private const int MaxItemLength = 200;
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
{
if (value is not List<string> features)
return new ValidationResult("Features must be a list of strings.", [validationContext.MemberName!]);
if (features.Count is < MinItems or > MaxItems)
return new ValidationResult(
$"Features must contain between {MinItems} and {MaxItems} items.",
[validationContext.MemberName!]);
if (features.Any(f => string.IsNullOrWhiteSpace(f) || f.Length > MaxItemLength))
return new ValidationResult(
$"Each feature must be non-empty and at most {MaxItemLength} characters.",
[validationContext.MemberName!]);
return ValidationResult.Success;
}
}
@@ -0,0 +1,16 @@
using System.Diagnostics.CodeAnalysis;
namespace SlpModularCms.Modules.Offerings.Models;
[ExcludeFromCodeCoverage]
public record OfferingAdminDto(
string Id,
string Title,
string Description,
string Price,
string PriceNote,
IReadOnlyList<string> Features,
string CtaLabel,
bool Featured,
int DisplayOrder
);
@@ -0,0 +1,15 @@
using System.Diagnostics.CodeAnalysis;
namespace SlpModularCms.Modules.Offerings.Models;
[ExcludeFromCodeCoverage]
public record OfferingDto(
string Id,
string Title,
string Description,
string Price,
string PriceNote,
IReadOnlyList<string> Features,
string CtaLabel,
bool Featured
);
@@ -0,0 +1,7 @@
using System.ComponentModel.DataAnnotations;
namespace SlpModularCms.Modules.Offerings.Models;
public record ReorderOfferingsRequest(
[Required, MinLength(1)] List<Guid> OrderedIds
);
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace SlpModularCms.Modules.Offerings.Models;
public record UpdateOfferingRequest(
[Required, MaxLength(100)] string Title,
[Required, MaxLength(500)] string Description,
[Required, MaxLength(50)] string Price,
[Required, MaxLength(100)] string PriceNote,
[Required, FeaturesValidation] List<string> Features,
[Required, MaxLength(50)] string CtaLabel,
bool Featured = false
);
@@ -0,0 +1,41 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SlpModularCms.Core.Hosting;
using SlpModularCms.Core.Modules;
using SlpModularCms.Modules.Offerings.Data;
using SlpModularCms.Modules.Offerings.Repositories;
using SlpModularCms.Modules.Offerings.Services;
namespace SlpModularCms.Modules.Offerings;
[ExcludeFromCodeCoverage]
public class OfferingsModule : IModule
{
public string Name => "Offerings";
public string Version => "1.0.0";
public void RegisterServices(IServiceCollection services)
{
services.AddDbContext<OfferingsDbContext>((serviceProvider, options) =>
{
var config = serviceProvider.GetRequiredService<IConfiguration>();
options.UseMySQL(config.GetConnectionString("DefaultConnection")!);
options.ReplaceService<IHistoryRepository, NonLockingMySQLHistoryRepository>();
});
services.AddScoped<IOfferingRepository, OfferingRepository>();
services.AddScoped<IOfferingsService, OfferingsService>();
services.AddHttpContextAccessor();
}
public void UseModule(IApplicationBuilder app)
{
using var scope = app.ApplicationServices.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<OfferingsDbContext>();
db.Database.Migrate();
}
}
@@ -0,0 +1,18 @@
using Microsoft.EntityFrameworkCore.Storage;
using SlpModularCms.Modules.Offerings.Data.Entities;
namespace SlpModularCms.Modules.Offerings.Repositories;
public interface IOfferingRepository
{
Task<IReadOnlyList<Offering>> GetAllAsync();
Task<Offering?> GetByIdAsync(Guid id);
Task AddAsync(Offering offering);
void Update(Offering offering);
Task<int> GetMaxDisplayOrderAsync();
Task<Offering?> GetFeaturedAsync();
Task<Offering?> GetPreviousAsync(int displayOrder);
Task<Offering?> GetNextAsync(int displayOrder);
Task SaveChangesAsync();
Task<IDbContextTransaction> BeginTransactionAsync();
}
@@ -0,0 +1,45 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;
using SlpModularCms.Modules.Offerings.Data;
using SlpModularCms.Modules.Offerings.Data.Entities;
namespace SlpModularCms.Modules.Offerings.Repositories;
public class OfferingRepository(OfferingsDbContext context) : IOfferingRepository
{
public async Task<IReadOnlyList<Offering>> GetAllAsync()
=> await context.Offerings.OrderBy(o => o.DisplayOrder).ToListAsync();
public async Task<Offering?> GetByIdAsync(Guid id)
=> await context.Offerings.FirstOrDefaultAsync(o => o.Id == id);
public async Task AddAsync(Offering offering)
=> await context.Offerings.AddAsync(offering);
public void Update(Offering offering)
=> context.Offerings.Update(offering);
public async Task<int> GetMaxDisplayOrderAsync()
=> await context.Offerings.Select(o => (int?)o.DisplayOrder).MaxAsync() ?? -1;
public async Task<Offering?> GetFeaturedAsync()
=> await context.Offerings.FirstOrDefaultAsync(o => o.Featured);
public async Task<Offering?> GetPreviousAsync(int displayOrder)
=> await context.Offerings
.Where(o => o.DisplayOrder < displayOrder)
.OrderByDescending(o => o.DisplayOrder)
.FirstOrDefaultAsync();
public async Task<Offering?> GetNextAsync(int displayOrder)
=> await context.Offerings
.Where(o => o.DisplayOrder > displayOrder)
.OrderBy(o => o.DisplayOrder)
.FirstOrDefaultAsync();
public async Task SaveChangesAsync()
=> await context.SaveChangesAsync();
public async Task<IDbContextTransaction> BeginTransactionAsync()
=> await context.Database.BeginTransactionAsync();
}
@@ -0,0 +1,15 @@
using SlpModularCms.Modules.Offerings.Models;
namespace SlpModularCms.Modules.Offerings.Services;
public interface IOfferingsService
{
Task<IReadOnlyList<OfferingDto>> GetPublicOfferingsAsync();
Task<IReadOnlyList<OfferingAdminDto>> GetAllForAdminAsync();
Task<OfferingAdminDto> CreateAsync(CreateOfferingRequest request, Guid callerId);
Task<OfferingAdminDto?> UpdateAsync(Guid id, UpdateOfferingRequest request, Guid callerId);
Task<bool> DeleteAsync(Guid id, Guid callerId);
Task ReorderAsync(IReadOnlyList<Guid> orderedIds, Guid callerId);
Task MoveUpAsync(Guid id, Guid callerId);
Task MoveDownAsync(Guid id, Guid callerId);
}
@@ -0,0 +1,227 @@
using Microsoft.Extensions.Logging;
using SlpModularCms.Modules.Offerings.Data.Entities;
using SlpModularCms.Modules.Offerings.Models;
using SlpModularCms.Modules.Offerings.Repositories;
namespace SlpModularCms.Modules.Offerings.Services;
public class OfferingsService(IOfferingRepository repository, ILogger<OfferingsService> logger) : IOfferingsService
{
public async Task<IReadOnlyList<OfferingDto>> GetPublicOfferingsAsync()
{
var offerings = await repository.GetAllAsync();
return offerings.Select(ToPublicDto).ToList();
}
public async Task<IReadOnlyList<OfferingAdminDto>> GetAllForAdminAsync()
{
var offerings = await repository.GetAllAsync();
return offerings.Select(ToAdminDto).ToList();
}
public async Task<OfferingAdminDto> CreateAsync(CreateOfferingRequest request, Guid callerId)
{
var now = DateTimeOffset.UtcNow;
var offering = new Offering
{
Id = Guid.NewGuid(),
Title = request.Title,
Description = request.Description,
Price = request.Price,
PriceNote = request.PriceNote,
Features = request.Features,
CtaLabel = request.CtaLabel,
Featured = request.Featured,
DisplayOrder = await repository.GetMaxDisplayOrderAsync() + 1,
CreatedAt = now,
UpdatedAt = now,
LastModifiedByUserId = callerId,
};
// BR-OFF-01 (featured exclusivity) touches two rows in one logical action —
// transactional per NFR Design Pattern 1 so a mid-operation failure can never
// leave two offerings both featured or the new one unsaved after the old one
// was already un-featured.
if (request.Featured)
{
await using var transaction = await repository.BeginTransactionAsync();
await UnfeatureCurrentAsync();
await repository.AddAsync(offering);
await repository.SaveChangesAsync();
await transaction.CommitAsync();
}
else
{
await repository.AddAsync(offering);
await repository.SaveChangesAsync();
}
logger.LogInformation(
"Offering {OfferingId} {Action} by user {LastModifiedByUserId}",
offering.Id, "Created", callerId);
return ToAdminDto(offering);
}
public async Task<OfferingAdminDto?> UpdateAsync(Guid id, UpdateOfferingRequest request, Guid callerId)
{
var offering = await repository.GetByIdAsync(id);
if (offering is null)
return null;
offering.Title = request.Title;
offering.Description = request.Description;
offering.Price = request.Price;
offering.PriceNote = request.PriceNote;
offering.Features = request.Features;
offering.CtaLabel = request.CtaLabel;
offering.Featured = request.Featured;
offering.UpdatedAt = DateTimeOffset.UtcNow;
offering.LastModifiedByUserId = callerId;
if (request.Featured)
{
await using var transaction = await repository.BeginTransactionAsync();
await UnfeatureCurrentAsync(exceptId: offering.Id);
repository.Update(offering);
await repository.SaveChangesAsync();
await transaction.CommitAsync();
}
else
{
repository.Update(offering);
await repository.SaveChangesAsync();
}
logger.LogInformation(
"Offering {OfferingId} {Action} by user {LastModifiedByUserId}",
offering.Id, "Updated", callerId);
return ToAdminDto(offering);
}
public async Task<bool> DeleteAsync(Guid id, Guid callerId)
{
var offering = await repository.GetByIdAsync(id);
if (offering is null)
return false;
// BR-OFF-02: soft delete is never blocked, including for the last remaining offering.
offering.IsDeleted = true;
offering.DeletedAt = DateTimeOffset.UtcNow;
offering.UpdatedAt = offering.DeletedAt.Value;
offering.LastModifiedByUserId = callerId;
repository.Update(offering);
await repository.SaveChangesAsync();
logger.LogInformation(
"Offering {OfferingId} {Action} by user {LastModifiedByUserId}",
offering.Id, "Deleted", callerId);
return true;
}
public async Task ReorderAsync(IReadOnlyList<Guid> orderedIds, Guid callerId)
{
await using var transaction = await repository.BeginTransactionAsync();
var now = DateTimeOffset.UtcNow;
for (var i = 0; i < orderedIds.Count; i++)
{
var offering = await repository.GetByIdAsync(orderedIds[i]);
if (offering is null)
continue;
offering.DisplayOrder = i;
offering.UpdatedAt = now;
offering.LastModifiedByUserId = callerId;
repository.Update(offering);
}
await repository.SaveChangesAsync();
await transaction.CommitAsync();
logger.LogInformation(
"Offerings reordered ({Count} items) by user {LastModifiedByUserId}",
orderedIds.Count, callerId);
}
public async Task MoveUpAsync(Guid id, Guid callerId)
{
var offering = await repository.GetByIdAsync(id);
if (offering is null)
return;
var previous = await repository.GetPreviousAsync(offering.DisplayOrder);
if (previous is null)
return; // BR-OFF-03: already first, no-op
await using var transaction = await repository.BeginTransactionAsync();
SwapDisplayOrder(offering, previous, callerId);
await repository.SaveChangesAsync();
await transaction.CommitAsync();
}
public async Task MoveDownAsync(Guid id, Guid callerId)
{
var offering = await repository.GetByIdAsync(id);
if (offering is null)
return;
var next = await repository.GetNextAsync(offering.DisplayOrder);
if (next is null)
return; // BR-OFF-03: already last, no-op
await using var transaction = await repository.BeginTransactionAsync();
SwapDisplayOrder(offering, next, callerId);
await repository.SaveChangesAsync();
await transaction.CommitAsync();
}
private void SwapDisplayOrder(Offering a, Offering b, Guid callerId)
{
(a.DisplayOrder, b.DisplayOrder) = (b.DisplayOrder, a.DisplayOrder);
var now = DateTimeOffset.UtcNow;
a.UpdatedAt = now;
b.UpdatedAt = now;
a.LastModifiedByUserId = callerId;
b.LastModifiedByUserId = callerId;
repository.Update(a);
repository.Update(b);
}
private async Task UnfeatureCurrentAsync(Guid? exceptId = null)
{
var current = await repository.GetFeaturedAsync();
if (current is null || current.Id == exceptId)
return;
current.Featured = false;
current.UpdatedAt = DateTimeOffset.UtcNow;
repository.Update(current);
}
private static OfferingDto ToPublicDto(Offering o) => new(
o.Id.ToString(),
o.Title,
o.Description,
o.Price,
o.PriceNote,
o.Features,
o.CtaLabel,
o.Featured
);
private static OfferingAdminDto ToAdminDto(Offering o) => new(
o.Id.ToString(),
o.Title,
o.Description,
o.Price,
o.PriceNote,
o.Features,
o.CtaLabel,
o.Featured,
o.DisplayOrder
);
}
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>SlpModularCms.Modules.Offerings.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlpModularCms.Core\SlpModularCms.Core.csproj" />
</ItemGroup>
</Project>