Add validation to RealmCreate
This commit is contained in:
parent
09480eb1e4
commit
ddbb1f42d7
16 changed files with 326 additions and 23 deletions
8
IdentityShroud.Core/Services/IRealmService.cs
Normal file
8
IdentityShroud.Core/Services/IRealmService.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using IdentityShroud.Core.Messages.Realm;
|
||||
|
||||
namespace IdentityShroud.Core.Services;
|
||||
|
||||
public interface IRealmService
|
||||
{
|
||||
Task<Result<RealmCreateResponse>> Create(RealmCreateRequest request, CancellationToken ct = default);
|
||||
}
|
||||
|
|
@ -1,23 +1,24 @@
|
|||
using System.Security.Cryptography;
|
||||
using IdentityShroud.Core.Contracts;
|
||||
using IdentityShroud.Core.Helpers;
|
||||
using IdentityShroud.Core.Messages.Realm;
|
||||
using IdentityShroud.Core.Model;
|
||||
|
||||
namespace IdentityShroud.Core.Services;
|
||||
|
||||
public record RealmCreateResponse(Realm Realm);
|
||||
public record RealmCreateResponse(Guid Id, string Slug, string Name);
|
||||
|
||||
public class RealmService(
|
||||
Db db,
|
||||
IEncryptionService encryptionService)
|
||||
IEncryptionService encryptionService) : IRealmService
|
||||
{
|
||||
public async Task<Result<RealmCreateResponse>> Create(RealmCreateRequest request, CancellationToken ct = default)
|
||||
{
|
||||
Realm realm = new()
|
||||
{
|
||||
Id = request.Id ?? Guid.CreateVersion7(),
|
||||
Slug = request.Slug,
|
||||
Name = request.Description,
|
||||
Slug = request.Slug ?? SlugHelper.GenerateSlug(request.Name),
|
||||
Name = request.Name,
|
||||
};
|
||||
|
||||
using RSA rsa = RSA.Create(2048);
|
||||
|
|
@ -26,6 +27,7 @@ public class RealmService(
|
|||
db.Add(realm);
|
||||
await db.SaveChangesAsync(ct);
|
||||
|
||||
return new RealmCreateResponse(realm);
|
||||
return new RealmCreateResponse(
|
||||
realm.Id, realm.Slug, realm.Name);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue