Skip to content

Commit

Permalink
bug: add missing users repository interface (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoZambon authored Feb 8, 2024
1 parent 24bda06 commit 818451e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
20 changes: 5 additions & 15 deletions ZSecurity/Repositories/BaseUsersRepository.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using ZDatabase.Interfaces;
using ZSecurity.Interfaces;
using ZSecurity.Repositories.Interfaces;

namespace ZSecurity.Repositories
{
public abstract class BaseUsersRepository<TActions, TUsersKey>
/// <inheritdoc />
public abstract class BaseUsersRepository<TActions, TUsersKey> : IBaseUsersRepository<TActions, TUsersKey>
where TActions : class, IActionEntity
where TUsersKey : struct
{
Expand All @@ -26,15 +28,7 @@ public BaseUsersRepository(IDbContext dbContext)
#endregion

#region Public methods
/// <summary>
/// Determines whether the user has any action asynchronous.
/// </summary>
/// <param name="userID">The user identifier.</param>
/// <param name="actionCodes">The action codes.</param>
/// <returns>
/// <c>true</c> if the user has any of the action codes; otherwise, <c>false</c>.
/// </returns>
/// <exception cref="System.ArgumentNullException">actionCodes</exception>
/// <inheritdoc />
public async Task<bool> HasAnyActionAsync(TUsersKey userID, params string[] actionCodes)
{
if (!actionCodes.Any())
Expand All @@ -46,11 +40,7 @@ public async Task<bool> HasAnyActionAsync(TUsersKey userID, params string[] acti
.Any(x => actionCodes.Contains(x.Code));
}

/// <summary>
/// Lists all actions asynchronous.
/// </summary>
/// <param name="userID">The user identifier.</param>
/// <returns>The actions list.</returns>
/// <inheritdoc />
public abstract Task<IEnumerable<TActions>> ListAllActionsAsync(TUsersKey userID);
#endregion

Expand Down
32 changes: 32 additions & 0 deletions ZSecurity/Repositories/Interfaces/IBaseUsersRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using ZSecurity.Interfaces;

namespace ZSecurity.Repositories.Interfaces
{
/// <summary>
/// Interface for base users repository.
/// </summary>
/// <typeparam name="TActions">The type of the actions.</typeparam>
/// <typeparam name="TUsersKey">The type of the users key.</typeparam>
public interface IBaseUsersRepository<TActions, TUsersKey>
where TActions : class, IActionEntity
where TUsersKey : struct
{
/// <summary>
/// Determines whether the user has any action asynchronous.
/// </summary>
/// <param name="userID">The user identifier.</param>
/// <param name="actionCodes">The action codes.</param>
/// <returns>
/// <c>true</c> if the user has any of the action codes; otherwise, <c>false</c>.
/// </returns>
/// <exception cref="System.ArgumentNullException">actionCodes</exception>
Task<bool> HasAnyActionAsync(TUsersKey userID, params string[] actionCodes);

/// <summary>
/// Lists all actions asynchronous.
/// </summary>
/// <param name="userID">The user identifier.</param>
/// <returns>The actions list.</returns>
Task<IEnumerable<TActions>> ListAllActionsAsync(TUsersKey userID);
}
}
3 changes: 2 additions & 1 deletion ZSecurity/Services/SecurityHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
using ZSecurity.Helpers;
using ZSecurity.Interfaces;
using ZSecurity.Repositories;
using ZSecurity.Repositories.Interfaces;

namespace ZSecurity.Services
{
public class SecurityHandler<TBaseUserRepository, TActions, TUsersKey> : ISecurityHandler
where TBaseUserRepository : BaseUsersRepository<TActions, TUsersKey>
where TBaseUserRepository : IBaseUsersRepository<TActions, TUsersKey>
where TActions : class, IActionEntity
where TUsersKey : struct
{
Expand Down

0 comments on commit 818451e

Please sign in to comment.