Skip to content

Commit

Permalink
Migrate IdentityServer4 -> Duende IdentityServer
Browse files Browse the repository at this point in the history
  • Loading branch information
phongnguyend committed Dec 27, 2024
1 parent 26a5567 commit 4288433
Show file tree
Hide file tree
Showing 392 changed files with 14,283 additions and 4,450 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using System;

namespace ClassifiedAds.Application.AuditLogEntries.DTOs
namespace ClassifiedAds.Application.AuditLogEntries.DTOs;

public class AuditLogEntryDTO
{
public class AuditLogEntryDTO
{
public Guid Id { get; set; }
public Guid Id { get; set; }

public Guid UserId { get; set; }
public Guid UserId { get; set; }

public string UserName { get; set; }
public string UserName { get; set; }

public string Action { get; set; }
public string Action { get; set; }

public string ObjectId { get; set; }
public string ObjectId { get; set; }

public string Log { get; set; }
public string Log { get; set; }

public DateTimeOffset CreatedDateTime { get; set; }
}
public DateTimeOffset CreatedDateTime { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,40 @@
using System.Threading;
using System.Threading.Tasks;

namespace ClassifiedAds.Application.AuditLogEntries.Queries
namespace ClassifiedAds.Application.AuditLogEntries.Queries;

public class GetAuditEntriesQuery : AuditLogEntryQueryOptions, IQuery<List<AuditLogEntryDTO>>
{
}

internal class GetAuditEntriesQueryHandler : IQueryHandler<GetAuditEntriesQuery, List<AuditLogEntryDTO>>
{
public class GetAuditEntriesQuery : AuditLogEntryQueryOptions, IQuery<List<AuditLogEntryDTO>>
private readonly IAuditLogEntryRepository _auditLogEntryRepository;
private readonly IUserRepository _userRepository;

public GetAuditEntriesQueryHandler(IAuditLogEntryRepository auditLogEntryRepository, IUserRepository userRepository)
{
_auditLogEntryRepository = auditLogEntryRepository;
_userRepository = userRepository;
}

internal class GetAuditEntriesQueryHandler : IQueryHandler<GetAuditEntriesQuery, List<AuditLogEntryDTO>>
public async Task<List<AuditLogEntryDTO>> HandleAsync(GetAuditEntriesQuery query, CancellationToken cancellationToken = default)
{
private readonly IAuditLogEntryRepository _auditLogEntryRepository;
private readonly IUserRepository _userRepository;

public GetAuditEntriesQueryHandler(IAuditLogEntryRepository auditLogEntryRepository, IUserRepository userRepository)
{
_auditLogEntryRepository = auditLogEntryRepository;
_userRepository = userRepository;
}

public async Task<List<AuditLogEntryDTO>> HandleAsync(GetAuditEntriesQuery query, CancellationToken cancellationToken = default)
{
var auditLogs = _auditLogEntryRepository.Get(query);
var users = _userRepository.GetQueryableSet();
var auditLogs = _auditLogEntryRepository.Get(query);
var users = _userRepository.GetQueryableSet();

var rs = auditLogs.Join(users, x => x.UserId, y => y.Id,
(x, y) => new AuditLogEntryDTO
{
Id = x.Id,
UserId = x.UserId,
Action = x.Action,
ObjectId = x.ObjectId,
Log = x.Log,
CreatedDateTime = x.CreatedDateTime,
UserName = y.UserName,
});
var rs = auditLogs.Join(users, x => x.UserId, y => y.Id,
(x, y) => new AuditLogEntryDTO
{
Id = x.Id,
UserId = x.UserId,
Action = x.Action,
ObjectId = x.ObjectId,
Log = x.Log,
CreatedDateTime = x.CreatedDateTime,
UserName = y.UserName,
});

return await _userRepository.ToListAsync(rs.OrderByDescending(x => x.CreatedDateTime));
}
return await _userRepository.ToListAsync(rs.OrderByDescending(x => x.CreatedDateTime));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,53 @@
using System.Threading;
using System.Threading.Tasks;

namespace ClassifiedAds.Application.AuditLogEntries.Queries
namespace ClassifiedAds.Application.AuditLogEntries.Queries;

public class GetPagedAuditEntriesQuery : AuditLogEntryQueryOptions, IQuery<Paged<AuditLogEntryDTO>>
{
public class GetPagedAuditEntriesQuery : AuditLogEntryQueryOptions, IQuery<Paged<AuditLogEntryDTO>>
{
public int Page { get; set; }
public int Page { get; set; }

public int PageSize { get; set; }
}

public int PageSize { get; set; }
internal class GetPagedAuditEntriesQueryHandler : IQueryHandler<GetPagedAuditEntriesQuery, Paged<AuditLogEntryDTO>>
{
private readonly IAuditLogEntryRepository _auditLogEntryRepository;
private readonly IUserRepository _userRepository;

public GetPagedAuditEntriesQueryHandler(IAuditLogEntryRepository auditLogEntryRepository, IUserRepository userRepository)
{
_auditLogEntryRepository = auditLogEntryRepository;
_userRepository = userRepository;
}

internal class GetPagedAuditEntriesQueryHandler : IQueryHandler<GetPagedAuditEntriesQuery, Paged<AuditLogEntryDTO>>
public async Task<Paged<AuditLogEntryDTO>> HandleAsync(GetPagedAuditEntriesQuery queryOptions, CancellationToken cancellationToken = default)
{
private readonly IAuditLogEntryRepository _auditLogEntryRepository;
private readonly IUserRepository _userRepository;
var query = _auditLogEntryRepository.Get(queryOptions);
var users = _userRepository.GetQueryableSet();

public GetPagedAuditEntriesQueryHandler(IAuditLogEntryRepository auditLogEntryRepository, IUserRepository userRepository)
var result = new Paged<AuditLogEntryDTO>
{
_auditLogEntryRepository = auditLogEntryRepository;
_userRepository = userRepository;
}
TotalItems = query.Count(),
};

public async Task<Paged<AuditLogEntryDTO>> HandleAsync(GetPagedAuditEntriesQuery queryOptions, CancellationToken cancellationToken = default)
{
var query = _auditLogEntryRepository.Get(queryOptions);
var users = _userRepository.GetQueryableSet();
var auditLogs = query.OrderByDescending(x => x.CreatedDateTime)
.Paged(queryOptions.Page, queryOptions.PageSize);

var result = new Paged<AuditLogEntryDTO>
var rs = auditLogs.Join(users, x => x.UserId, y => y.Id,
(x, y) => new AuditLogEntryDTO
{
TotalItems = query.Count(),
};

var auditLogs = query.OrderByDescending(x => x.CreatedDateTime)
.Paged(queryOptions.Page, queryOptions.PageSize);

var rs = auditLogs.Join(users, x => x.UserId, y => y.Id,
(x, y) => new AuditLogEntryDTO
{
Id = x.Id,
UserId = x.UserId,
Action = x.Action,
ObjectId = x.ObjectId,
Log = x.Log,
CreatedDateTime = x.CreatedDateTime,
UserName = y.UserName,
});

result.Items = await _userRepository.ToListAsync(rs);

return result;
}
Id = x.Id,
UserId = x.UserId,
Action = x.Action,
ObjectId = x.ObjectId,
Log = x.Log,
CreatedDateTime = x.CreatedDateTime,
UserName = y.UserName,
});

result.Items = await _userRepository.ToListAsync(rs);

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,31 @@
using System.Threading;
using System.Threading.Tasks;

namespace ClassifiedAds.Application
namespace ClassifiedAds.Application;

public class AddEntityCommand<TEntity> : ICommand
where TEntity : Entity<Guid>, IAggregateRoot
{
public class AddEntityCommand<TEntity> : ICommand
where TEntity : Entity<Guid>, IAggregateRoot
public AddEntityCommand(TEntity entity)
{
public AddEntityCommand(TEntity entity)
{
Entity = entity;
}

public TEntity Entity { get; set; }
Entity = entity;
}

internal class AddEntityCommandHandler<TEntity> : ICommandHandler<AddEntityCommand<TEntity>>
where TEntity : Entity<Guid>, IAggregateRoot
{
private readonly ICrudService<TEntity> _crudService;
public TEntity Entity { get; set; }
}

public AddEntityCommandHandler(ICrudService<TEntity> crudService)
{
_crudService = crudService;
}
internal class AddEntityCommandHandler<TEntity> : ICommandHandler<AddEntityCommand<TEntity>>
where TEntity : Entity<Guid>, IAggregateRoot
{
private readonly ICrudService<TEntity> _crudService;

public async Task HandleAsync(AddEntityCommand<TEntity> command, CancellationToken cancellationToken = default)
{
await _crudService.AddAsync(command.Entity);
}
public AddEntityCommandHandler(ICrudService<TEntity> crudService)
{
_crudService = crudService;
}

public async Task HandleAsync(AddEntityCommand<TEntity> command, CancellationToken cancellationToken = default)
{
await _crudService.AddAsync(command.Entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,31 @@
using System.Threading;
using System.Threading.Tasks;

namespace ClassifiedAds.Application
namespace ClassifiedAds.Application;

public class AddOrUpdateEntityCommand<TEntity> : ICommand
where TEntity : Entity<Guid>, IAggregateRoot
{
public class AddOrUpdateEntityCommand<TEntity> : ICommand
where TEntity : Entity<Guid>, IAggregateRoot
public AddOrUpdateEntityCommand(TEntity entity)
{
public AddOrUpdateEntityCommand(TEntity entity)
{
Entity = entity;
}

public TEntity Entity { get; set; }
Entity = entity;
}

internal class AddOrUpdateEntityCommandHandler<TEntity> : ICommandHandler<AddOrUpdateEntityCommand<TEntity>>
where TEntity : Entity<Guid>, IAggregateRoot
{
private readonly ICrudService<TEntity> _crudService;
public TEntity Entity { get; set; }
}

public AddOrUpdateEntityCommandHandler(ICrudService<TEntity> crudService)
{
_crudService = crudService;
}
internal class AddOrUpdateEntityCommandHandler<TEntity> : ICommandHandler<AddOrUpdateEntityCommand<TEntity>>
where TEntity : Entity<Guid>, IAggregateRoot
{
private readonly ICrudService<TEntity> _crudService;

public async Task HandleAsync(AddOrUpdateEntityCommand<TEntity> command, CancellationToken cancellationToken = default)
{
await _crudService.AddOrUpdateAsync(command.Entity);
}
public AddOrUpdateEntityCommandHandler(ICrudService<TEntity> crudService)
{
_crudService = crudService;
}

public async Task HandleAsync(AddOrUpdateEntityCommand<TEntity> command, CancellationToken cancellationToken = default)
{
await _crudService.AddOrUpdateAsync(command.Entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@
using System.Threading;
using System.Threading.Tasks;

namespace ClassifiedAds.Application
namespace ClassifiedAds.Application;

public class DeleteEntityCommand<TEntity> : ICommand
where TEntity : Entity<Guid>, IAggregateRoot
{
public TEntity Entity { get; set; }
}

internal class DeleteEntityCommandHandler<TEntity> : ICommandHandler<DeleteEntityCommand<TEntity>>
where TEntity : Entity<Guid>, IAggregateRoot
{
public class DeleteEntityCommand<TEntity> : ICommand
where TEntity : Entity<Guid>, IAggregateRoot
private readonly ICrudService<TEntity> _crudService;

public DeleteEntityCommandHandler(ICrudService<TEntity> crudService)
{
public TEntity Entity { get; set; }
_crudService = crudService;
}

internal class DeleteEntityCommandHandler<TEntity> : ICommandHandler<DeleteEntityCommand<TEntity>>
where TEntity : Entity<Guid>, IAggregateRoot
public async Task HandleAsync(DeleteEntityCommand<TEntity> command, CancellationToken cancellationToken = default)
{
private readonly ICrudService<TEntity> _crudService;

public DeleteEntityCommandHandler(ICrudService<TEntity> crudService)
{
_crudService = crudService;
}

public async Task HandleAsync(DeleteEntityCommand<TEntity> command, CancellationToken cancellationToken = default)
{
await _crudService.DeleteAsync(command.Entity);
}
await _crudService.DeleteAsync(command.Entity);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace ClassifiedAds.Application
namespace ClassifiedAds.Application;

public interface ICommand
{
public interface ICommand
{
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Threading;
using System.Threading.Tasks;

namespace ClassifiedAds.Application
namespace ClassifiedAds.Application;

public interface ICommandHandler<TCommand>
where TCommand : ICommand
{
public interface ICommandHandler<TCommand>
where TCommand : ICommand
{
Task HandleAsync(TCommand command, CancellationToken cancellationToken = default);
}
Task HandleAsync(TCommand command, CancellationToken cancellationToken = default);
}
Loading

0 comments on commit 4288433

Please sign in to comment.