Skip to content

Commit

Permalink
repos
Browse files Browse the repository at this point in the history
  • Loading branch information
Utar94 committed Dec 22, 2024
1 parent 540947c commit 366ee0e
Show file tree
Hide file tree
Showing 13 changed files with 418 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Logitar.EventSourcing.EntityFrameworkCore.Relational;
using Logitar.Identity.Core.ApiKeys;
using Logitar.Identity.Core.Passwords;
using Logitar.Identity.Core.Roles;
using Logitar.Identity.Core.Sessions;
using Logitar.Identity.Core.Tokens;
using Logitar.Identity.Core.Users;
using Logitar.Identity.EntityFrameworkCore.Relational.Repositories;
using Logitar.Identity.EntityFrameworkCore.Relational.Tokens;
using Logitar.Identity.Infrastructure;
using Microsoft.Extensions.DependencyInjection;

namespace Logitar.Identity.EntityFrameworkCore.Relational;

public static class DependencyInjectionExtensions
{
public static IServiceCollection AddLogitarIdentityWithEntityFrameworkCoreRelational(this IServiceCollection services)
{
return services
.AddLogitarEventSourcingWithEntityFrameworkCoreRelational()
.AddLogitarIdentityInfrastructure()
.AddEventHandlers()
.AddMediatR(config => config.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()))
.AddRepositories()
//.AddTransient<ICustomAttributeService, CustomAttributeService>() // TODO(fpion): implement
.AddScoped<ITokenBlacklist, TokenBlacklist>();
}

private static IServiceCollection AddEventHandlers(this IServiceCollection services)
{
return services/*
.AddTransient<IApiKeyEventHandler, ApiKeyEventHandler>()
.AddTransient<IOneTimePasswordEventHandler, OneTimePasswordEventHandler>()
.AddTransient<IRoleEventHandler, RoleEventHandler>()
.AddTransient<ISessionEventHandler, SessionEventHandler>()
.AddTransient<IUserEventHandler, UserEventHandler>()*/; // TODO(fpion): implement
}

private static IServiceCollection AddRepositories(this IServiceCollection services)
{
return services
.AddScoped<IApiKeyRepository, ApiKeyRepository>()
.AddScoped<IOneTimePasswordRepository, OneTimePasswordRepository>()
.AddScoped<IRoleRepository, RoleRepository>()
.AddScoped<ISessionRepository, SessionRepository>()
.AddScoped<IUserRepository, UserRepository>();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text;

namespace Logitar.Identity.EntityFrameworkCore.Relational.Entities;
namespace Logitar.Identity.EntityFrameworkCore.Relational.Entities;

public sealed class ActorEntity
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Logitar.Identity.Core;
using Logitar.Identity.Core.ApiKeys;
using Logitar.Identity.Core.ApiKeys.Events;
using System.Text.Json;

namespace Logitar.Identity.EntityFrameworkCore.Relational.Entities;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Logitar.Identity.Core;
using Logitar.Identity.Core.Passwords;
using Logitar.Identity.Core.Passwords.Events;
using System.Text.Json;

namespace Logitar.Identity.EntityFrameworkCore.Relational.Entities;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Logitar.Identity.Core;
using Logitar.Identity.Core.Roles;
using Logitar.Identity.Core.Roles.Events;
using System.Text.Json;

namespace Logitar.Identity.EntityFrameworkCore.Relational.Entities;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Logitar.Identity.Core;
using Logitar.Identity.Core.Sessions;
using Logitar.Identity.Core.Sessions.Events;
using System.Text.Json;

namespace Logitar.Identity.EntityFrameworkCore.Relational.Entities;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Logitar.Identity.Core;
using Logitar.Identity.Core.Users;
using Logitar.Identity.Core.Users.Events;
using System.Text.Json;

namespace Logitar.Identity.EntityFrameworkCore.Relational.Entities;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

<ItemGroup>
<Using Include="System.Reflection" />
<Using Include="System.Text" />
<Using Include="System.Text.Json" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Logitar.EventSourcing;
using Logitar.Identity.Core;
using Logitar.Identity.Core.ApiKeys;
using Logitar.Identity.Core.Roles;

namespace Logitar.Identity.EntityFrameworkCore.Relational.Repositories;

public class ApiKeyRepository : Repository, IApiKeyRepository
{
public ApiKeyRepository(IEventStore eventStore) : base(eventStore)
{
}

public async Task<ApiKey?> LoadAsync(ApiKeyId id, CancellationToken cancellationToken)
{
return await LoadAsync(id, isDeleted: null, cancellationToken);
}
public async Task<ApiKey?> LoadAsync(ApiKeyId id, long? version, CancellationToken cancellationToken)
{
return await LoadAsync(id, version, isDeleted: null, cancellationToken);
}
public async Task<ApiKey?> LoadAsync(ApiKeyId id, bool? isDeleted, CancellationToken cancellationToken)
{
return await LoadAsync(id, version: null, isDeleted, cancellationToken);
}
public async Task<ApiKey?> LoadAsync(ApiKeyId id, long? version, bool? isDeleted, CancellationToken cancellationToken)
{
return await LoadAsync<ApiKey>(id.StreamId, version, isDeleted, cancellationToken);
}

public async Task<IReadOnlyCollection<ApiKey>> LoadAsync(CancellationToken cancellationToken)
{
return await LoadAsync(isDeleted: null, cancellationToken);
}
public async Task<IReadOnlyCollection<ApiKey>> LoadAsync(bool? isDeleted, CancellationToken cancellationToken)
{
return await LoadAsync<ApiKey>(isDeleted, cancellationToken);
}

public async Task<IReadOnlyCollection<ApiKey>> LoadAsync(IEnumerable<ApiKeyId> ids, CancellationToken cancellationToken)
{
return await LoadAsync(ids, isDeleted: null, cancellationToken);
}
public async Task<IReadOnlyCollection<ApiKey>> LoadAsync(IEnumerable<ApiKeyId> ids, bool? isDeleted, CancellationToken cancellationToken)
{
IEnumerable<StreamId> streamIds = ids.Select(id => id.StreamId);
return await LoadAsync<ApiKey>(streamIds, isDeleted, cancellationToken);
}

public Task<IReadOnlyCollection<ApiKey>> LoadAsync(TenantId? tenantId, CancellationToken cancellationToken)
{
throw new NotImplementedException(); // TODO(fpion): implement
}

public Task<IReadOnlyCollection<ApiKey>> LoadAsync(Role role, CancellationToken cancellationToken)
{
throw new NotImplementedException(); // TODO(fpion): implement
}

public async Task SaveAsync(ApiKey apikey, CancellationToken cancellationToken)
{
await base.SaveAsync(apikey, cancellationToken);
}
public async Task SaveAsync(IEnumerable<ApiKey> apikeys, CancellationToken cancellationToken)
{
await base.SaveAsync(apikeys, cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Logitar.EventSourcing;
using Logitar.Identity.Core;
using Logitar.Identity.Core.Passwords;

namespace Logitar.Identity.EntityFrameworkCore.Relational.Repositories;

public class OneTimePasswordRepository : Repository, IOneTimePasswordRepository
{
public OneTimePasswordRepository(IEventStore eventStore) : base(eventStore)
{
}

public async Task<OneTimePassword?> LoadAsync(OneTimePasswordId id, CancellationToken cancellationToken)
{
return await LoadAsync(id, isDeleted: null, cancellationToken);
}
public async Task<OneTimePassword?> LoadAsync(OneTimePasswordId id, long? version, CancellationToken cancellationToken)
{
return await LoadAsync(id, version, isDeleted: null, cancellationToken);
}
public async Task<OneTimePassword?> LoadAsync(OneTimePasswordId id, bool? isDeleted, CancellationToken cancellationToken)
{
return await LoadAsync(id, version: null, isDeleted, cancellationToken);
}
public async Task<OneTimePassword?> LoadAsync(OneTimePasswordId id, long? version, bool? isDeleted, CancellationToken cancellationToken)
{
return await LoadAsync<OneTimePassword>(id.StreamId, version, isDeleted, cancellationToken);
}

public async Task<IReadOnlyCollection<OneTimePassword>> LoadAsync(CancellationToken cancellationToken)
{
return await LoadAsync(isDeleted: null, cancellationToken);
}
public async Task<IReadOnlyCollection<OneTimePassword>> LoadAsync(bool? isDeleted, CancellationToken cancellationToken)
{
return await LoadAsync<OneTimePassword>(isDeleted, cancellationToken);
}

public async Task<IReadOnlyCollection<OneTimePassword>> LoadAsync(IEnumerable<OneTimePasswordId> ids, CancellationToken cancellationToken)
{
return await LoadAsync(ids, isDeleted: null, cancellationToken);
}
public async Task<IReadOnlyCollection<OneTimePassword>> LoadAsync(IEnumerable<OneTimePasswordId> ids, bool? isDeleted, CancellationToken cancellationToken)
{
IEnumerable<StreamId> streamIds = ids.Select(id => id.StreamId);
return await LoadAsync<OneTimePassword>(streamIds, isDeleted, cancellationToken);
}

public Task<IReadOnlyCollection<OneTimePassword>> LoadAsync(TenantId? tenantId, CancellationToken cancellationToken)
{
throw new NotImplementedException(); // TODO(fpion): implement
}

public async Task SaveAsync(OneTimePassword onetimepassword, CancellationToken cancellationToken)
{
await base.SaveAsync(onetimepassword, cancellationToken);
}
public async Task SaveAsync(IEnumerable<OneTimePassword> onetimepasswords, CancellationToken cancellationToken)
{
await base.SaveAsync(onetimepasswords, cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Logitar.EventSourcing;
using Logitar.Identity.Core;
using Logitar.Identity.Core.ApiKeys;
using Logitar.Identity.Core.Roles;
using Logitar.Identity.Core.Users;

namespace Logitar.Identity.EntityFrameworkCore.Relational.Repositories;

public class RoleRepository : Repository, IRoleRepository
{
public RoleRepository(IEventStore eventStore) : base(eventStore)
{
}

public async Task<Role?> LoadAsync(RoleId id, CancellationToken cancellationToken)
{
return await LoadAsync(id, isDeleted: null, cancellationToken);
}
public async Task<Role?> LoadAsync(RoleId id, long? version, CancellationToken cancellationToken)
{
return await LoadAsync(id, version, isDeleted: null, cancellationToken);
}
public async Task<Role?> LoadAsync(RoleId id, bool? isDeleted, CancellationToken cancellationToken)
{
return await LoadAsync(id, version: null, isDeleted, cancellationToken);
}
public async Task<Role?> LoadAsync(RoleId id, long? version, bool? isDeleted, CancellationToken cancellationToken)
{
return await LoadAsync<Role>(id.StreamId, version, isDeleted, cancellationToken);
}

public async Task<IReadOnlyCollection<Role>> LoadAsync(CancellationToken cancellationToken)
{
return await LoadAsync(isDeleted: null, cancellationToken);
}
public async Task<IReadOnlyCollection<Role>> LoadAsync(bool? isDeleted, CancellationToken cancellationToken)
{
return await LoadAsync<Role>(isDeleted, cancellationToken);
}

public async Task<IReadOnlyCollection<Role>> LoadAsync(IEnumerable<RoleId> ids, CancellationToken cancellationToken)
{
return await LoadAsync(ids, isDeleted: null, cancellationToken);
}
public async Task<IReadOnlyCollection<Role>> LoadAsync(IEnumerable<RoleId> ids, bool? isDeleted, CancellationToken cancellationToken)
{
IEnumerable<StreamId> streamIds = ids.Select(id => id.StreamId);
return await LoadAsync<Role>(streamIds, isDeleted, cancellationToken);
}

public Task<IReadOnlyCollection<Role>> LoadAsync(TenantId? tenantId, CancellationToken cancellationToken)
{
throw new NotImplementedException(); // TODO(fpion): implement
}

public Task<Role?> LoadAsync(TenantId? tenantId, UniqueName uniqueName, CancellationToken cancellationToken)
{
throw new NotImplementedException(); // TODO(fpion): implement
}

public Task<IReadOnlyCollection<Role>> LoadAsync(ApiKey apiKey, CancellationToken cancellationToken)
{
throw new NotImplementedException(); // TODO(fpion): implement
}
public Task<IReadOnlyCollection<Role>> LoadAsync(User user, CancellationToken cancellationToken)
{
throw new NotImplementedException(); // TODO(fpion): implement
}

public async Task SaveAsync(Role role, CancellationToken cancellationToken)
{
await base.SaveAsync(role, cancellationToken);
}
public async Task SaveAsync(IEnumerable<Role> roles, CancellationToken cancellationToken)
{
await base.SaveAsync(roles, cancellationToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Logitar.EventSourcing;
using Logitar.Identity.Core;
using Logitar.Identity.Core.Sessions;
using Logitar.Identity.Core.Users;

namespace Logitar.Identity.EntityFrameworkCore.Relational.Repositories;

public class SessionRepository : Repository, ISessionRepository
{
public SessionRepository(IEventStore eventStore) : base(eventStore)
{
}

public async Task<Session?> LoadAsync(SessionId id, CancellationToken cancellationToken)
{
return await LoadAsync(id, isDeleted: null, cancellationToken);
}
public async Task<Session?> LoadAsync(SessionId id, long? version, CancellationToken cancellationToken)
{
return await LoadAsync(id, version, isDeleted: null, cancellationToken);
}
public async Task<Session?> LoadAsync(SessionId id, bool? isDeleted, CancellationToken cancellationToken)
{
return await LoadAsync(id, version: null, isDeleted, cancellationToken);
}
public async Task<Session?> LoadAsync(SessionId id, long? version, bool? isDeleted, CancellationToken cancellationToken)
{
return await LoadAsync<Session>(id.StreamId, version, isDeleted, cancellationToken);
}

public async Task<IReadOnlyCollection<Session>> LoadAsync(CancellationToken cancellationToken)
{
return await LoadAsync(isDeleted: null, cancellationToken);
}
public async Task<IReadOnlyCollection<Session>> LoadAsync(bool? isDeleted, CancellationToken cancellationToken)
{
return await LoadAsync<Session>(isDeleted, cancellationToken);
}

public async Task<IReadOnlyCollection<Session>> LoadAsync(IEnumerable<SessionId> ids, CancellationToken cancellationToken)
{
return await LoadAsync(ids, isDeleted: null, cancellationToken);
}
public async Task<IReadOnlyCollection<Session>> LoadAsync(IEnumerable<SessionId> ids, bool? isDeleted, CancellationToken cancellationToken)
{
IEnumerable<StreamId> streamIds = ids.Select(id => id.StreamId);
return await LoadAsync<Session>(streamIds, isDeleted, cancellationToken);
}

public Task<IReadOnlyCollection<Session>> LoadAsync(TenantId? tenantId, CancellationToken cancellationToken)
{
throw new NotImplementedException(); // TODO(fpion): implement
}

public Task<IReadOnlyCollection<Session>> LoadActiveAsync(User user, CancellationToken cancellationToken)
{
throw new NotImplementedException(); // TODO(fpion): implement
}
public Task<IReadOnlyCollection<Session>> LoadAsync(User user, CancellationToken cancellationToken)
{
throw new NotImplementedException(); // TODO(fpion): implement
}

public async Task SaveAsync(Session session, CancellationToken cancellationToken)
{
await base.SaveAsync(session, cancellationToken);
}
public async Task SaveAsync(IEnumerable<Session> sessions, CancellationToken cancellationToken)
{
await base.SaveAsync(sessions, cancellationToken);
}
}
Loading

0 comments on commit 366ee0e

Please sign in to comment.