Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
refactor(back-end): General code cleanup
Browse files Browse the repository at this point in the history
All backend files are cleaned up. Spelling errors were corrected, some functions were simplified, among other refactorings
  • Loading branch information
CarlosPavajeau committed Jan 22, 2021
1 parent 8c9f54d commit 263150a
Show file tree
Hide file tree
Showing 45 changed files with 135 additions and 223 deletions.
17 changes: 0 additions & 17 deletions Core.Test/Defines/TimeConstantsTest.cs

This file was deleted.

9 changes: 0 additions & 9 deletions Core/Defines/TimeConstants.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Core/Domain/IDomainEventDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Kaizen.Core.Domain
{
public interface IDomainEventDispatcher
{
Task Dispatch(IDomainEvent devent);
Task Dispatch(IDomainEvent @event);
}
}
2 changes: 1 addition & 1 deletion Core/Domain/IRepositoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Kaizen.Core.Domain
{
public interface IRepositoryBase<T, TKey> where T : class
public interface IRepositoryBase<T, in TKey> where T : class
{
IQueryable<T> GetAll();
IQueryable<T> Where(Expression<Func<T, bool>> expression);
Expand Down
5 changes: 0 additions & 5 deletions Core/Exceptions/HttpException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,5 @@ protected HttpException(SerializationInfo info, StreamingContext context) : base
}

public int StatusCode { get; set; }

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
}
}
5 changes: 0 additions & 5 deletions Core/Exceptions/UnspecifiedDataProviderException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ public UnspecifiedDataProviderException() : base("The Data Provider entry in app
protected UnspecifiedDataProviderException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
}
}
5 changes: 0 additions & 5 deletions Core/Exceptions/User/IncorrectPasswordException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ public IncorrectPasswordException() : base(400, "Contraseña incorrecta, intente
protected IncorrectPasswordException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
}
}
5 changes: 0 additions & 5 deletions Core/Exceptions/User/UserDoesNotExistsException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ public UserDoesNotExistsException() : base(400, "Usuario no registrado")
protected UserDoesNotExistsException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
}
}
5 changes: 0 additions & 5 deletions Core/Exceptions/User/UserNotCreateException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ public UserNotCreateException() : base(400, "Usuario no creado")
protected UserNotCreateException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}

public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
}
}
2 changes: 1 addition & 1 deletion Core/Services/IMailTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Kaizen.Core.Services
{
public interface IMailTemplate
{
protected const string EMAIL_TEMPLATES_FOLDER = "EmailTemplates";
protected const string EmailTemplatesFolder = "EmailTemplates";

string LoadTemplate(string templateName, params string[] args);
}
Expand Down
2 changes: 1 addition & 1 deletion Domain.Test/Data/ProvidersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void Init()
c.Provider = (DataProvider)Enum.Parse(typeof(DataProvider), configuration["Data:Provider"]);
});
services.Configure<ConnectionStrings>(configuration.GetSection("ConnectionStrings"));
services.AddEntityFramework(configuration);
services.RegisterDbContext(configuration);

ServiceProvider serviceProvider = services.BuildServiceProvider();
dbContext = serviceProvider.GetService<ApplicationDbContext>();
Expand Down
18 changes: 5 additions & 13 deletions Domain/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,25 @@ namespace Kaizen.Domain.Extensions
{
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddEntityFramework(this IServiceCollection services, IConfiguration configuration)
public static IServiceCollection RegisterDbContext(this IServiceCollection services, IConfiguration configuration)
{
string dataProviderConfig = configuration.GetSection("Data")["Provider"];
string connectionStringConfig = configuration.GetConnectionString("DefaultConnection");
Assembly currentAssenbly = typeof(ServiceCollectionExtensions).GetTypeInfo().Assembly;
IEnumerable<IDataProvider> dataProviders = currentAssenbly.GetImplementationsOf<IDataProvider>();
Assembly currentAssembly = typeof(ServiceCollectionExtensions).GetTypeInfo().Assembly;
IEnumerable<IDataProvider> dataProviders = currentAssembly.GetImplementationsOf<IDataProvider>();

IDataProvider dataProvider = dataProviders.SingleOrDefault(x => x.Provider.ToString() == dataProviderConfig);

return dataProvider.RegisterDbContext(services, connectionStringConfig);
return dataProvider?.RegisterDbContext(services, connectionStringConfig);
}

private static IEnumerable<T> GetImplementationsOf<T>(this Assembly assembly)
{
List<T> result = new List<T>();

List<Type> types = assembly.GetTypes()
.Where(t => t.GetTypeInfo().IsClass && !t.GetTypeInfo().IsAbstract && typeof(T).IsAssignableFrom(t))
.ToList();

foreach (Type type in types)
{
T instance = (T)Activator.CreateInstance(type);
result.Add(instance);
}

return result;
return types.Select(type => (T)Activator.CreateInstance(type)).ToList();
}
}
}
2 changes: 1 addition & 1 deletion Domain/Repositories/IApplicationUserRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IApplicationUserRepository : IRepositoryBase<ApplicationUser, s
Task<string> GenerateEmailConfirmationTokenAsync(ApplicationUser user);

Task<ApplicationUser> ConfirmEmailAsync(ApplicationUser user, string token);
Task<IdentityResult> ChangePassswordAsync(ApplicationUser user, string oldPassword, string newPassword);
Task<IdentityResult> ChangePasswordAsync(ApplicationUser user, string oldPassword, string newPassword);

Task<string> GeneratePasswordResetTokenAsync(ApplicationUser user);
Task<bool> SendPasswordResetTokenAsync(ApplicationUser user, string resetPasswordLink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public async Task ChangePassowrd_Without_ResetToken()
ApplicationUser applicationUser = await applicationUserRepository.FindByNameOrEmailAsync("admin");
Assert.IsNotNull(applicationUser);

IdentityResult result = await applicationUserRepository.ChangePassswordAsync(applicationUser, "ThisisaSecurePassword321*", "ThisIsMyNewPassword123.");
IdentityResult result = await applicationUserRepository.ChangePasswordAsync(applicationUser, "ThisisaSecurePassword321*", "ThisIsMyNewPassword123.");

Assert.IsTrue(result.Succeeded);
}
Expand Down
2 changes: 1 addition & 1 deletion Infrastructure.Test/Repositories/BaseRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Init()
c.Provider = (DataProvider)Enum.Parse(typeof(DataProvider), configuration["Data:Provider"]);
});
services.Configure<ConnectionStrings>(configuration.GetSection("ConnectionStrings"));
services.AddEntityFramework(configuration);
services.RegisterDbContext(configuration);
services.ConfigureRepositories();
services.AddIdentityConfig();
services.AddLogging();
Expand Down
7 changes: 5 additions & 2 deletions Infrastructure/Extensions/ApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;

namespace Kaizen.Infrastructure.Extensions
{
public static class ApplicationBuilderExtensions
{
private const string SwaggerUrl = "/swagger/v1/swagger.json";
private const string SwaggerApiName = "My API version-1";

public static IApplicationBuilder UseSwaggerApiDocumentation(this IApplicationBuilder app)
{
app.UseSwagger();
app.UseSwaggerUI(s =>
{
s.SwaggerEndpoint("/swagger/v1/swagger.json", "My API version-1");
s.SwaggerEndpoint(SwaggerUrl, SwaggerApiName);
});

return app;
Expand Down
46 changes: 23 additions & 23 deletions Infrastructure/Identity/SpanishIdentityErrorDescriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ public class SpanishIdentityErrorDescriber : IdentityErrorDescriber
{
public override IdentityError DefaultError()
{
return new IdentityError
return new()
{
Code = nameof(DefaultError),
Description = $"Ha ocurrido un error."
Description = "Ha ocurrido un error."
};
}

public override IdentityError ConcurrencyFailure()
{
return new IdentityError
return new()
{
Code = nameof(ConcurrencyFailure),
Description = "Ha ocurrido un error, el objeto ya ha sido modificado (Optimistic concurrency failure)."
Expand All @@ -24,25 +24,25 @@ public override IdentityError ConcurrencyFailure()

public override IdentityError PasswordMismatch()
{
return new IdentityError
return new()
{
Code = nameof(PasswordMismatch),
Description = "Contraseña Incorrecta."
Description = "Contraseña incorrecta."
};
}

public override IdentityError InvalidToken()
{
return new IdentityError
return new()
{
Code = nameof(InvalidToken),
Description = "Ha ingresado un código Inválido."
Description = "Ha ingresado un código inválido."
};
}

public override IdentityError LoginAlreadyAssociated()
{
return new IdentityError
return new()
{
Code = nameof(LoginAlreadyAssociated),
Description = "Un usuario con ese nombre ya existe."
Expand All @@ -51,7 +51,7 @@ public override IdentityError LoginAlreadyAssociated()

public override IdentityError InvalidUserName(string userName)
{
return new IdentityError
return new()
{
Code = nameof(InvalidUserName),
Description = $"El nombre de usuario '{userName}' es inválido. Solo puede contener letras y números."
Expand All @@ -60,7 +60,7 @@ public override IdentityError InvalidUserName(string userName)

public override IdentityError InvalidEmail(string email)
{
return new IdentityError
return new()
{
Code = nameof(InvalidEmail),
Description = $"La dirección de email '{email}' es incorrecta."
Expand All @@ -69,7 +69,7 @@ public override IdentityError InvalidEmail(string email)

public override IdentityError DuplicateUserName(string userName)
{
return new IdentityError
return new()
{
Code = nameof(DuplicateUserName),
Description = $"El usuario '{userName}' ya existe, por favor ingrese un nombre diferente."
Expand All @@ -78,7 +78,7 @@ public override IdentityError DuplicateUserName(string userName)

public override IdentityError DuplicateEmail(string email)
{
return new IdentityError
return new()
{
Code = nameof(DuplicateEmail),
Description = $"La direccion de email '{email}' ya se encuentra registrada. Puede recupar su contraseña para ingresar nuevamente al sistema."
Expand All @@ -87,7 +87,7 @@ public override IdentityError DuplicateEmail(string email)

public override IdentityError InvalidRoleName(string role)
{
return new IdentityError
return new()
{
Code = nameof(InvalidRoleName),
Description = $"El nombre de rol '{role}' es inválido."
Expand All @@ -96,7 +96,7 @@ public override IdentityError InvalidRoleName(string role)

public override IdentityError DuplicateRoleName(string role)
{
return new IdentityError
return new()
{
Code = nameof(DuplicateRoleName),
Description = $"El nombre de rol '{role}' ya existe."
Expand All @@ -105,7 +105,7 @@ public override IdentityError DuplicateRoleName(string role)

public override IdentityError UserAlreadyHasPassword()
{
return new IdentityError
return new()
{
Code = nameof(UserAlreadyHasPassword),
Description = "El usuario ya tiene contraseña."
Expand All @@ -114,7 +114,7 @@ public override IdentityError UserAlreadyHasPassword()

public override IdentityError UserLockoutNotEnabled()
{
return new IdentityError
return new()
{
Code = nameof(UserLockoutNotEnabled),
Description = "El bloqueo no esta habilitado para este usuario."
Expand All @@ -123,7 +123,7 @@ public override IdentityError UserLockoutNotEnabled()

public override IdentityError UserAlreadyInRole(string role)
{
return new IdentityError
return new()
{
Code = nameof(UserAlreadyInRole),
Description = $"El usuario ya es parte del rol '{role}'."
Expand All @@ -132,7 +132,7 @@ public override IdentityError UserAlreadyInRole(string role)

public override IdentityError UserNotInRole(string role)
{
return new IdentityError
return new()
{
Code = nameof(UserNotInRole),
Description = $"El usuario no es parte del rol '{role}'."
Expand All @@ -141,7 +141,7 @@ public override IdentityError UserNotInRole(string role)

public override IdentityError PasswordTooShort(int length)
{
return new IdentityError
return new()
{
Code = nameof(PasswordTooShort),
Description = $"La contraseña deben tener un largo mínimo de {length} caracteres."
Expand All @@ -150,7 +150,7 @@ public override IdentityError PasswordTooShort(int length)

public override IdentityError PasswordRequiresNonAlphanumeric()
{
return new IdentityError
return new()
{
Code = nameof(PasswordRequiresNonAlphanumeric),
Description = "La contraseña debe contener al menos un caracter alfanumérico."
Expand All @@ -159,7 +159,7 @@ public override IdentityError PasswordRequiresNonAlphanumeric()

public override IdentityError PasswordRequiresDigit()
{
return new IdentityError
return new()
{
Code = nameof(PasswordRequiresDigit),
Description = "La contraseña debe incluir al menos un dígito ('0'-'9')."
Expand All @@ -168,7 +168,7 @@ public override IdentityError PasswordRequiresDigit()

public override IdentityError PasswordRequiresLower()
{
return new IdentityError
return new()
{
Code = nameof(PasswordRequiresLower),
Description = "La contraseña debe incluir al menos una letra minúscula ('a'-'z')."
Expand All @@ -177,7 +177,7 @@ public override IdentityError PasswordRequiresLower()

public override IdentityError PasswordRequiresUpper()
{
return new IdentityError
return new()
{
Code = nameof(PasswordRequiresUpper),
Description = "La contraseña debe incluir al menos una letra MAYÚSCULA ('A'-'Z')."
Expand Down
Loading

0 comments on commit 263150a

Please sign in to comment.