feat(notification): add admin rest management and deletion

Add revision-safe service and template APIs, channel mapping, and validated admin controls.

Ref: IT-1601
This commit is contained in:
2026-10-17 22:51:01 +03:00
parent 81654c0d33
commit 8e81572386
80 changed files with 2253 additions and 54 deletions
@@ -20,6 +20,33 @@ internal sealed class NotificationServiceRepository(NotificationDbContext db, Te
return service is null ? null : Map(service, await VersionCountsAsync(ct));
}
public async Task<NotificationServiceInfo?> GetByNameAsync(string name, CancellationToken ct = default)
{
var service = await db.Services.AsNoTracking().Include(s => s.Languages).SingleOrDefaultAsync(s => s.Name == name, ct);
return service is null ? null : Map(service, await VersionCountsAsync(ct));
}
public async Task<bool> DeleteAsync(Guid id, Guid revision, CancellationToken ct = default)
{
var removed = false;
await mutations.ExecuteAsync(async () =>
{
if (revision == Guid.Empty)
throw new EmailTemplateWriteException("A nonempty service revision is required.", false);
var service = await db.Services.Include(s => s.Languages).SingleOrDefaultAsync(s => s.Id == id, ct);
if (service is null)
return;
if (service.Revision != revision)
throw new EmailTemplateWriteException("The service revision changed. Read it again before deleting.");
if (await db.TemplateDefinitions.AnyAsync(d => d.ServiceId == id, ct))
throw new EmailTemplateWriteException("Remove every template definition before deleting this service, including definitions without translations.");
db.ServiceLanguages.RemoveRange(service.Languages);
db.Services.Remove(service);
removed = true;
}, ct);
return removed;
}
public Task SaveAsync(NotificationServiceInfo model, bool isNew, CancellationToken ct = default) => mutations.ExecuteAsync(async () =>
{
Validate(model);