OPC # 0001: Extract Clarity into standalone repo
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using Clarity.Server.Data;
|
||||
using Clarity.Server.Entity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Clarity.Server.Services
|
||||
{
|
||||
public class ProfileService
|
||||
{
|
||||
private readonly ApplicationDbContext db;
|
||||
private readonly IPIIVault piiVault;
|
||||
|
||||
public ProfileService(ApplicationDbContext db, IPIIVault piiVault)
|
||||
{
|
||||
this.db = db;
|
||||
this.piiVault = piiVault;
|
||||
}
|
||||
|
||||
public Task<Profile?> GetBySubjectAsync(string sub, CancellationToken ct = default) =>
|
||||
db.Profiles.FirstOrDefaultAsync(p => p.KeycloakSubject == sub, ct);
|
||||
|
||||
|
||||
|
||||
public async Task<Profile> CreateAsync(string sub, string firstName, string? middleName, string lastName, string ssn, CancellationToken ct = default)
|
||||
{
|
||||
var profile = new Profile
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
KeycloakSubject = sub,
|
||||
FirstName = firstName,
|
||||
MiddleName = middleName ?? string.Empty,
|
||||
LastName = lastName,
|
||||
Ssn = ssn,
|
||||
OnboardingComplete = true,
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
|
||||
db.Profiles.Add(profile);
|
||||
await db.SaveChangesAsync(ct);
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user