Преглед на файлове

More refactoring for clean architecture

master
Safet Purkovic преди 4 години
родител
ревизия
53c04cc94b
променени са 19 файла, в които са добавени 49 реда и са изтрити 51 реда
  1. 3
    3
      BlackRock.Reporting.API/Controllers/PDFGeneratorController.cs
  2. 0
    10
      BlackRock.Reporting.API/Core/IGenerator.cs
  3. 0
    10
      BlackRock.Reporting.API/Core/IUnitOfWork.cs
  4. 10
    0
      BlackRock.Reporting.API/Core/Interfaces/IGenerator.cs
  5. 2
    2
      BlackRock.Reporting.API/Core/Interfaces/IPdfGenerator.cs
  6. 1
    1
      BlackRock.Reporting.API/Core/Interfaces/IRepository.cs
  7. 9
    0
      BlackRock.Reporting.API/Core/Interfaces/IUnitOfWork.cs
  8. 2
    2
      BlackRock.Reporting.API/Core/Interfaces/IUsersRepository.cs
  9. 1
    1
      BlackRock.Reporting.API/Mediator/UserMediator/Commands/CreateUserCommand.cs
  10. 1
    1
      BlackRock.Reporting.API/Mediator/UserMediator/Commands/DeleteUsersCommand.cs
  11. 4
    4
      BlackRock.Reporting.API/Mediator/UserMediator/Commands/UpdateUserCommand.cs
  12. 5
    5
      BlackRock.Reporting.API/Mediator/UserMediator/Commands/UpdateUserEmailCommand.cs
  13. 1
    1
      BlackRock.Reporting.API/Mediator/UserMediator/Queries/GetAllUsersQuery.cs
  14. 1
    2
      BlackRock.Reporting.API/Mediator/UserMediator/Queries/GetUserQuery.cs
  15. 1
    1
      BlackRock.Reporting.API/Persistence/PdfGenerator.cs
  16. 1
    1
      BlackRock.Reporting.API/Persistence/Repositories/EFRepository.cs
  17. 1
    1
      BlackRock.Reporting.API/Persistence/Repositories/UsersRepository.cs
  18. 1
    1
      BlackRock.Reporting.API/Persistence/UnitOfWork.cs
  19. 5
    5
      BlackRock.Reporting.API/Program.cs

+ 3
- 3
BlackRock.Reporting.API/Controllers/PDFGeneratorController.cs Целия файл

using System.Web; using System.Web;
using AutoMapper; using AutoMapper;
using BlackRock.Reporting.API.Core;
using BlackRock.Reporting.API.Core.Interfaces;
using BlackRock.Reporting.API.Core.Models; using BlackRock.Reporting.API.Core.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PuppeteerSharp; using PuppeteerSharp;
string path = Path.Combine(host.ContentRootPath, $"wwwroot/pdfs/{fileName}"); string path = Path.Combine(host.ContentRootPath, $"wwwroot/pdfs/{fileName}");
// Mapping from DTO class to Puppeteer PdfOptions class. For margins and paper format // Mapping from DTO class to Puppeteer PdfOptions class. For margins and paper format
var options = mapper.Map<OptionsForPdf, PdfOptions>(pdfOptions); var options = mapper.Map<OptionsForPdf, PdfOptions>(pdfOptions);
await generator.Generate(result, path, options); await generator.Generate(result, path, options);


FileStream stream = new FileStream(path, FileMode.Open); FileStream stream = new FileStream(path, FileMode.Open);
return File(stream, "application/pdf", fileName); return File(stream, "application/pdf", fileName);
} }




[HttpGet("isolate/{url}")] [HttpGet("isolate/{url}")]
public async Task<IActionResult> GetIsolated([FromQuery] OptionsForPdf pdfOptions, string url = "http://localhost:3000/#/dashboard") public async Task<IActionResult> GetIsolated([FromQuery] OptionsForPdf pdfOptions, string url = "http://localhost:3000/#/dashboard")

+ 0
- 10
BlackRock.Reporting.API/Core/IGenerator.cs Целия файл

using PuppeteerSharp;

namespace BlackRock.Reporting.API.Core
{
public interface IGenerator
{
Task Generate(string url, string path,PdfOptions options);
Task Isolate(string url, string path,PdfOptions options);
}
}

+ 0
- 10
BlackRock.Reporting.API/Core/IUnitOfWork.cs Целия файл

using BlackRock.Reporting.API.Core.Repositories;

namespace BlackRock.Reporting.API.Core
{
public interface IUnitOfWork
{
IUsersRepository UsersRepository{get;set;}
Task SaveChangesAsync();
}
}

+ 10
- 0
BlackRock.Reporting.API/Core/Interfaces/IGenerator.cs Целия файл

using PuppeteerSharp;

namespace BlackRock.Reporting.API.Core.Interfaces
{
public interface IGenerator
{
Task Generate(string url, string path, PdfOptions options);
Task Isolate(string url, string path, PdfOptions options);
}
}

BlackRock.Reporting.API/Core/IPdfGenerator.cs → BlackRock.Reporting.API/Core/Interfaces/IPdfGenerator.cs Целия файл

namespace BlackRock.Reporting.API.Core
namespace BlackRock.Reporting.API.Core.Interfaces
{ {
public interface IPdfGenerator : IGenerator public interface IPdfGenerator : IGenerator
{ {
} }
} }

BlackRock.Reporting.API/Core/Repositories/IRepository.cs → BlackRock.Reporting.API/Core/Interfaces/IRepository.cs Целия файл

using BlackRock.Reporting.API.Core.Models; using BlackRock.Reporting.API.Core.Models;


namespace BlackRock.Reporting.API.Core.Repositories
namespace BlackRock.Reporting.API.Core.Interfaces
{ {
public interface IRepository<TEntity> where TEntity : class, IBaseEntity public interface IRepository<TEntity> where TEntity : class, IBaseEntity
{ {

+ 9
- 0
BlackRock.Reporting.API/Core/Interfaces/IUnitOfWork.cs Целия файл


namespace BlackRock.Reporting.API.Core.Interfaces
{
public interface IUnitOfWork
{
IUsersRepository UsersRepository { get; set; }
Task SaveChangesAsync();
}
}

BlackRock.Reporting.API/Core/Repositories/IUsersRepository.cs → BlackRock.Reporting.API/Core/Interfaces/IUsersRepository.cs Целия файл

using BlackRock.Reporting.API.Core.Models; using BlackRock.Reporting.API.Core.Models;


namespace BlackRock.Reporting.API.Core.Repositories
namespace BlackRock.Reporting.API.Core.Interfaces
{ {
public interface IUsersRepository : IRepository<User> public interface IUsersRepository : IRepository<User>
{ {
void UpdateEmail(User user,string email);
void UpdateEmail(User user, string email);
Task<PagedCollection<User>> GetAllByFilter(UsersFilter queryObj); Task<PagedCollection<User>> GetAllByFilter(UsersFilter queryObj);
} }
} }

+ 1
- 1
BlackRock.Reporting.API/Mediator/UserMediator/Commands/CreateUserCommand.cs Целия файл

using AutoMapper; using AutoMapper;
using BlackRock.Reporting.API.Core;
using BlackRock.Reporting.API.Core.Interfaces;
using BlackRock.Reporting.API.Core.Models; using BlackRock.Reporting.API.Core.Models;
using BlackRock.Reporting.API.Mediator.UserMediator.Model; using BlackRock.Reporting.API.Mediator.UserMediator.Model;
using MediatR; using MediatR;

+ 1
- 1
BlackRock.Reporting.API/Mediator/UserMediator/Commands/DeleteUsersCommand.cs Целия файл

using AutoMapper; using AutoMapper;
using BlackRock.Reporting.API.Core;
using BlackRock.Reporting.API.Core.Interfaces;
using BlackRock.Reporting.API.Mediator.UserMediator.Model; using BlackRock.Reporting.API.Mediator.UserMediator.Model;
using MediatR; using MediatR;



+ 4
- 4
BlackRock.Reporting.API/Mediator/UserMediator/Commands/UpdateUserCommand.cs Целия файл

using AutoMapper; using AutoMapper;
using BlackRock.Reporting.API.Core;
using BlackRock.Reporting.API.Core.Interfaces;
using BlackRock.Reporting.API.Core.Models; using BlackRock.Reporting.API.Core.Models;
using BlackRock.Reporting.API.Mediator.UserMediator.Dto; using BlackRock.Reporting.API.Mediator.UserMediator.Dto;
using BlackRock.Reporting.API.Mediator.UserMediator.Model; using BlackRock.Reporting.API.Mediator.UserMediator.Model;
{ {
public class UpdateUserCommand : IRequest<Result<UserDto>> public class UpdateUserCommand : IRequest<Result<UserDto>>
{ {
public UserCommand User { get;set; }
public int Id { get;set; }
public UserCommand User { get; set; }
public int Id { get; set; }
} }


public class UpdateUserCommandHandlers : IRequestHandler<UpdateUserCommand, Result<UserDto>> public class UpdateUserCommandHandlers : IRequestHandler<UpdateUserCommand, Result<UserDto>>

+ 5
- 5
BlackRock.Reporting.API/Mediator/UserMediator/Commands/UpdateUserEmailCommand.cs Целия файл

using AutoMapper; using AutoMapper;
using BlackRock.Reporting.API.Mediator.UserMediator.Dto; using BlackRock.Reporting.API.Mediator.UserMediator.Dto;
using BlackRock.Reporting.API.Mediator.UserMediator.Model; using BlackRock.Reporting.API.Mediator.UserMediator.Model;
using BlackRock.Reporting.API.Core;
using BlackRock.Reporting.API.Core.Interfaces;
using BlackRock.Reporting.API.Core.Models; using BlackRock.Reporting.API.Core.Models;
using MediatR; using MediatR;


{ {
public class UpdateUserEmailCommand : IRequest<Result<UserDto>> public class UpdateUserEmailCommand : IRequest<Result<UserDto>>
{ {
public UserCommand User {set;get;}
public int Id { get; set;}
public UserCommand User { set; get; }
public int Id { get; set; }
} }


public class UpdateUserEmailCommandHandlers : IRequestHandler<UpdateUserEmailCommand, Result<UserDto>> public class UpdateUserEmailCommandHandlers : IRequestHandler<UpdateUserEmailCommand, Result<UserDto>>
try try
{ {
var user = await unitOfWork.UsersRepository.GetByIdAsync(command.Id); var user = await unitOfWork.UsersRepository.GetByIdAsync(command.Id);
unitOfWork.UsersRepository.UpdateEmail(user,command.User.Email);
unitOfWork.UsersRepository.UpdateEmail(user, command.User.Email);
await unitOfWork.SaveChangesAsync(); await unitOfWork.SaveChangesAsync();
var updatedUser = mapper.Map<User, UserDto>(user); var updatedUser = mapper.Map<User, UserDto>(user);
logger.LogInformation($"Email of the user with id {user.Id} has been updated successfully"); logger.LogInformation($"Email of the user with id {user.Id} has been updated successfully");

+ 1
- 1
BlackRock.Reporting.API/Mediator/UserMediator/Queries/GetAllUsersQuery.cs Целия файл

using AutoMapper; using AutoMapper;
using BlackRock.Reporting.API.Core;
using BlackRock.Reporting.API.Core.Interfaces;
using BlackRock.Reporting.API.Core.Models; using BlackRock.Reporting.API.Core.Models;
using BlackRock.Reporting.API.Mediator.UserMediator.Model; using BlackRock.Reporting.API.Mediator.UserMediator.Model;
using BlackRock.Reporting.API.Mediator.UserMediator.Dto; using BlackRock.Reporting.API.Mediator.UserMediator.Dto;

+ 1
- 2
BlackRock.Reporting.API/Mediator/UserMediator/Queries/GetUserQuery.cs Целия файл

using AutoMapper; using AutoMapper;
using BlackRock.Reporting.API.Mediator.UserMediator.Dto; using BlackRock.Reporting.API.Mediator.UserMediator.Dto;
using BlackRock.Reporting.API.Mediator.UserMediator.Model; using BlackRock.Reporting.API.Mediator.UserMediator.Model;
using BlackRock.Reporting.API.Core;
using BlackRock.Reporting.API.Core.Models; using BlackRock.Reporting.API.Core.Models;
using MediatR; using MediatR;
using BlackRock.Reporting.API.Core.Repositories;
using BlackRock.Reporting.API.Core.Interfaces;


namespace BlackRock.Reporting.API.Mediator.UserMediator.Queries namespace BlackRock.Reporting.API.Mediator.UserMediator.Queries
{ {

+ 1
- 1
BlackRock.Reporting.API/Persistence/PdfGenerator.cs Целия файл

using BlackRock.Reporting.API.Core;
using BlackRock.Reporting.API.Core.Interfaces;
using iTextSharp.text; using iTextSharp.text;
using iTextSharp.text.pdf; using iTextSharp.text.pdf;
using PuppeteerSharp; using PuppeteerSharp;

+ 1
- 1
BlackRock.Reporting.API/Persistence/Repositories/EFRepository.cs Целия файл

using BlackRock.Reporting.API.Core.Repositories;
using BlackRock.Reporting.API.Core.Interfaces;
using BlackRock.Reporting.API.Core.Models; using BlackRock.Reporting.API.Core.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;



+ 1
- 1
BlackRock.Reporting.API/Persistence/Repositories/UsersRepository.cs Целия файл

using System.Linq.Expressions; using System.Linq.Expressions;
using BlackRock.Reporting.API.Core.Repositories;
using BlackRock.Reporting.API.Core.Interfaces;
using BlackRock.Reporting.API.Core.Extensions; using BlackRock.Reporting.API.Core.Extensions;
using BlackRock.Reporting.API.Core.Models; using BlackRock.Reporting.API.Core.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;

+ 1
- 1
BlackRock.Reporting.API/Persistence/UnitOfWork.cs Целия файл

using BlackRock.Reporting.API.Core; using BlackRock.Reporting.API.Core;
using BlackRock.Reporting.API.Core.Repositories;
using BlackRock.Reporting.API.Core.Interfaces;


namespace BlackRock.Reporting.API.Persistence namespace BlackRock.Reporting.API.Persistence
{ {

+ 5
- 5
BlackRock.Reporting.API/Program.cs Целия файл

using BlackRock.Reporting.API.Authentication; using BlackRock.Reporting.API.Authentication;
using BlackRock.Reporting.API.Core;
using BlackRock.Reporting.API.Core.Models; using BlackRock.Reporting.API.Core.Models;
using BlackRock.Reporting.API.Core.Repositories;
using BlackRock.Reporting.API.Core.Interfaces;
using BlackRock.Reporting.API.Persistence; using BlackRock.Reporting.API.Persistence;
using BlackRock.Reporting.API.Persistence.Repositories; using BlackRock.Reporting.API.Persistence.Repositories;
using MediatR; using MediatR;
builder.Services.AddControllers(); builder.Services.AddControllers();
builder.Services.AddAutoMapper(typeof(Program)); builder.Services.AddAutoMapper(typeof(Program));
builder.Services.AddIdentity<ApplicationUser, IdentityRole>() builder.Services.AddIdentity<ApplicationUser, IdentityRole>()
.AddTokenProvider("MyApp",typeof(DataProtectorTokenProvider<ApplicationUser>))
.AddTokenProvider("MyApp", typeof(DataProtectorTokenProvider<ApplicationUser>))
.AddEntityFrameworkStores<BRDbContext>() .AddEntityFrameworkStores<BRDbContext>()
.AddDefaultTokenProviders(); .AddDefaultTokenProviders();
builder.Services.AddAuthentication(options => builder.Services.AddAuthentication(options =>
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen( builder.Services.AddSwaggerGen(
c => {
c =>
{
c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "BlackRock.Service.API", Version = "v1" }); c.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "BlackRock.Service.API", Version = "v1" });
c.AddSecurityDefinition("Bearer", new Microsoft.OpenApi.Models.OpenApiSecurityScheme c.AddSecurityDefinition("Bearer", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
{ {
var app = builder.Build(); var app = builder.Build();


// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
app.ConfigureExceptionHandler(builder.Logging);
// app.ConfigureExceptionHandler(builder.Logging);
app.UseCors(options => app.UseCors(options =>
options.AllowAnyHeader() options.AllowAnyHeader()
.AllowAnyMethod() .AllowAnyMethod()

Loading…
Отказ
Запис