Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/201 Agregación de un linter para el proyecto #212

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AppServices/AppServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.6" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
10 changes: 6 additions & 4 deletions AppServices/Data/Extensions/QueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public static IQueryable<T> FullTextSearch<T>(this IQueryable<T> queryable, stri
return FullTextSearch(queryable, searchKey, false);
}


/// <summary>
/// Searches in all string properties for the specifed search key.
/// It is also able to search for several words. If the searchKey is for example 'John Travolta' then
Expand All @@ -45,7 +44,6 @@ public static IQueryable<T> FullTextSearch<T>(this IQueryable<T> queryable, stri

var indexOfMethod = typeof(string).GetMethod("IndexOf", new[] { typeof(string), typeof(StringComparison) });


var publicProperties = typeof(T)
.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
.Where(p => p.PropertyType == typeof(string));
Expand Down Expand Up @@ -79,8 +77,8 @@ private static IOrderedQueryable<T> OrderingHelper<T>(IQueryable<T> source, stri
ParameterExpression param = Expression.Parameter(typeof(T), string.Empty);

#region Sort by sub properties
//This part is what sorts by sub properties
//For example: Manufacturer.Name
// This part is what sorts by sub properties
// For example: Manufacturer.Name
var parts = propertyName.Split('.');

Expression parent = param;
Expand All @@ -102,18 +100,22 @@ private static IOrderedQueryable<T> OrderingHelper<T>(IQueryable<T> source, stri

return (IOrderedQueryable<T>)source.Provider.CreateQuery<T>(call);
}

public static IOrderedQueryable<T> OrderBy<T>(this IQueryable<T> source, string propertyName)
{
return OrderingHelper(source, propertyName, false, false);
}

public static IOrderedQueryable<T> OrderByDescending<T>(this IQueryable<T> source, string propertyName)
{
return OrderingHelper(source, propertyName, true, false);
}

public static IOrderedQueryable<T> ThenBy<T>(this IOrderedQueryable<T> source, string propertyName)
{
return OrderingHelper(source, propertyName, false, true);
}

public static IOrderedQueryable<T> ThenByDescending<T>(this IOrderedQueryable<T> source, string propertyName)
{
return OrderingHelper(source, propertyName, true, true);
Expand Down
1 change: 1 addition & 0 deletions AppServices/Data/Repositories/BaseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public virtual T Update(T entity, int id)
entry.State = EntityState.Modified;
}
}

return entity;
}

Expand Down
2 changes: 1 addition & 1 deletion AppServices/Data/Repositories/UsersRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public UsersRepository(EmpleaDbContext database) : base(database)
}
}

public interface IUsersRepository: IBaseRepository<User> { }
public interface IUsersRepository : IBaseRepository<User> { }
}
1 change: 1 addition & 0 deletions AppServices/Data/TableConfigurations/TableConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protected void CommonColumnsConfiguration(EntityTypeBuilder<T> builder)
builder.Property(p => p.CreatedAt).IsRequired();
builder.Property(p => p.IsActive).IsRequired();
}

public abstract void Configure(EntityTypeBuilder<T> builder);
}
}
1 change: 0 additions & 1 deletion AppServices/Framework/TaskResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public TaskResult()
_messages = new List<string>();
}


public void AddErrorMessage(string message)
{
_success = false;
Expand Down
12 changes: 8 additions & 4 deletions AppServices/Services/BaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ public TaskResult<T> Create(T entity)
_mainRepository.CommitChanges();
taskResult.AddMessage("Registro agregado exitosamente");
}
catch(Exception ex)
catch (Exception ex)
{
taskResult.AddErrorMessage(ex.Message);
if(ex.InnerException != null)
if (ex.InnerException != null)
taskResult.AddErrorMessage(ex.InnerException.Message);

}
}

return taskResult;
}

public TaskResult<T> Update(T entity)
{
var taskResult = ValidateOnUpdate(entity);
Expand All @@ -60,6 +61,7 @@ public TaskResult<T> Update(T entity)
taskResult.AddErrorMessage(ex.InnerException.Message);
}
}

return taskResult;
}

Expand All @@ -82,15 +84,17 @@ public TaskResult Delete(T entity)
taskResult.AddErrorMessage(ex.InnerException.Message);
}
}

return taskResult;
}

public virtual List<T> GetAll()
{
return _mainRepository.Get(x => x.IsActive).ToList();
}
}

public interface IBaseService<T, U> where T:Entity where U:IBaseRepository<T>
public interface IBaseService<T, U> where T : Entity where U : IBaseRepository<T>
{
List<T> GetAll();
TaskResult<T> Create(T entity);
Expand Down
1 change: 0 additions & 1 deletion AppServices/Services/CategoriesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ protected override TaskResult<Category> ValidateOnUpdate(Category entity)

public interface ICategoriesService : IBaseService<Category, ICategoriesRepository>
{

}
}
8 changes: 4 additions & 4 deletions AppServices/Services/CompaniesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public CompaniesService(ICompaniesRepository mainRepository) : base(mainReposito

public List<Company> GetByUserId(int userId)
{
return _mainRepository.Get(x=>x.IsActive && x.UserId == userId).ToList();
return _mainRepository.Get(x => x.IsActive && x.UserId == userId).ToList();
}

public Company GetById(int id)
public Company GetById(int id)
{
return _mainRepository.Get(x=>x.IsActive && x.Id == id).FirstOrDefault();
return _mainRepository.Get(x => x.IsActive && x.Id == id).FirstOrDefault();
}

protected override TaskResult<Company> ValidateOnCreate(Company entity)
Expand All @@ -43,6 +43,6 @@ protected override TaskResult<Company> ValidateOnUpdate(Company entity)
public interface ICompaniesService : IBaseService<Company, ICompaniesRepository>
{
List<Company> GetByUserId(int userId);
Company GetById(int id);
Company GetById(int id);
}
}
1 change: 0 additions & 1 deletion AppServices/Services/HireTypesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ protected override TaskResult<HireType> ValidateOnUpdate(HireType entity)

public interface IHireTypesService : IBaseService<HireType, IHireTypesRepository>
{

}
}
1 change: 0 additions & 1 deletion AppServices/Services/LocationsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ protected override TaskResult<Location> ValidateOnUpdate(Location entity)

public interface ILocationsService : IBaseService<Location, ILocationsRepository>
{

}
}
2 changes: 1 addition & 1 deletion AppServices/Services/LoginsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public LoginsService(ILoginsRepository mainRepository) : base(mainRepository)

public Login GetLogin(string provider, string socialId)
{
return _mainRepository.Get(x=>x.ProviderKey== socialId && x.LoginProvider == provider).FirstOrDefault();
return _mainRepository.Get(x => x.ProviderKey == socialId && x.LoginProvider == provider).FirstOrDefault();
}

protected override TaskResult<Login> ValidateOnCreate(Login entity)
Expand Down
25 changes: 11 additions & 14 deletions AppServices/Services/TwitterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// <summary>
/// Simple class for sending tweets to Twitter using Single-user OAuth.
/// https://dev.twitter.com/oauth/overview/single-user
///
///
/// Get your access keys by creating an app at apps.twitter.com then visiting the
/// "Keys and Access Tokens" section for your app. They can be found under the
/// "Your Access Token" heading.
Expand All @@ -23,18 +23,18 @@ public class TwitterService : ITwitterService
readonly string consumerKey, consumerKeySecret, accessToken, accessTokenSecret;
readonly HMACSHA1 sigHasher;
readonly DateTime epochUtc = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
//readonly IOptions<TwitterConfig> appSettings;
// readonly IOptions<TwitterConfig> appSettings;

/// <summary>
/// Creates an object for sending tweets to Twitter using Single-user OAuth.
///
///
/// Get your access keys by creating an app at apps.twitter.com then visiting the
/// "Keys and Access Tokens" section for your app. They can be found under the
/// "Your Access Token" heading.
/// </summary>
public TwitterService(IOptions<TwitterConfig> app)
{
//validateConfig(app);
// validateConfig(app);
this.consumerKey = app.Value.consumerKey;
this.consumerKeySecret = app.Value.consumerKeySecret;
this.accessToken = app.Value.accessToken;
Expand All @@ -61,7 +61,7 @@ Task<string> SendRequest(string url, Dictionary<string, string> data)
var fullUrl = TwitterApiBaseUrl + url;

// Timestamps are in seconds since 1/1/1970.
var timestamp = (int)((DateTime.UtcNow - epochUtc).TotalSeconds);
var timestamp = (int)(DateTime.UtcNow - epochUtc).TotalSeconds;

// Add all the OAuth headers we'll need to use when constructing the hash.
data.Add("oauth_consumer_key", consumerKey);
Expand Down Expand Up @@ -93,15 +93,13 @@ string GenerateSignature(string url, Dictionary<string, string> data)
data
.Union(data)
.Select(kvp => string.Format("{0}={1}", Uri.EscapeDataString(kvp.Key), Uri.EscapeDataString(kvp.Value)))
.OrderBy(s => s)
);
.OrderBy(s => s));

var fullSigData = string.Format(
"{0}&{1}&{2}",
"POST",
Uri.EscapeDataString(url),
Uri.EscapeDataString(sigString.ToString())
);
Uri.EscapeDataString(sigString.ToString()));

return Convert.ToBase64String(sigHasher.ComputeHash(new System.Text.ASCIIEncoding().GetBytes(fullSigData.ToString())));
}
Expand All @@ -116,8 +114,7 @@ string GenerateOAuthHeader(Dictionary<string, string> data)
data
.Where(kvp => kvp.Key.StartsWith("oauth_"))
.Select(kvp => string.Format("{0}=\"{1}\"", Uri.EscapeDataString(kvp.Key), Uri.EscapeDataString(kvp.Value)))
.OrderBy(s => s)
);
.OrderBy(s => s));
}

/// <summary>
Expand All @@ -138,21 +135,21 @@ async Task<string> SendRequest(string fullUrl, string oAuthHeader, FormUrlEncode

void validateConfig(IOptions<TwitterConfig> app)
{
if(String.IsNullOrEmpty(app.Value.consumerKey)||String.IsNullOrEmpty(app.Value.consumerKeySecret) || String.IsNullOrEmpty(app.Value.accessToken) || String.IsNullOrEmpty(app.Value.accessTokenSecret))
if (string.IsNullOrEmpty(app.Value.consumerKey) || string.IsNullOrEmpty(app.Value.consumerKeySecret) || string.IsNullOrEmpty(app.Value.accessToken) || string.IsNullOrEmpty(app.Value.accessTokenSecret))
throw new ArgumentException("Twitter configuration setting are required");
}
}

public interface ITwitterService
{
Task<string> Tweet(string text);

}

public class TwitterConfig
{
public string consumerKey { get; set; }
public string consumerKeySecret { get; set; }
public string accessToken { get; set; }
public string accessTokenSecret { get; set; }

}
}
1 change: 0 additions & 1 deletion AppServices/Services/UsersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ protected override TaskResult<User> ValidateOnUpdate(User entity)

public interface IUsersService : IBaseService<User, IUsersRepository>
{

}
}
9 changes: 9 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>
<!-- StyleCop Analyzers configuration -->
<PropertyGroup>
<CodeAnalysisRuleSet>$(SolutionDir)StyleCop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions Domain/Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
<Compile Remove="Framework\Dto\NearbyJobOpportunityLocation.cs" />
<Compile Remove="Framework\ApplicationUser.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion Domain/Entities/Company.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
namespace Domain.Entities

{
public class Company : Entity
{
Expand Down
1 change: 0 additions & 1 deletion Domain/Entities/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
namespace Domain.Entities

{
public class Entity
{
Expand Down
1 change: 0 additions & 1 deletion Domain/Entities/HireType.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
namespace Domain.Entities

{
public class HireType : Entity
{
Expand Down
7 changes: 1 addition & 6 deletions Domain/Entities/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace Domain.Entities

{
public class Job : Entity
{
Expand All @@ -15,7 +14,7 @@ public class Job : Entity

public int ViewCount { get; set; }

public int Likes { get; set; } = 0;
public int Likes { get; set; } = 0;

public bool IsRemote { get; set; } = false;

Expand All @@ -25,7 +24,6 @@ public class Job : Entity

public DateTime PublishedDate { get; set; }


// Relationships with other entities

public int CategoryId { get; set; }
Expand All @@ -45,8 +43,5 @@ public class Job : Entity

public int? UserId { get; set; }
public virtual User User { get; set; }



}
}
1 change: 0 additions & 1 deletion Domain/Entities/JoelTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
namespace Domain.Entities

{
public class JoelTest : Entity
{
Expand Down
1 change: 0 additions & 1 deletion Domain/Entities/Location.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
namespace Domain.Entities

{
public class Location : Entity
{
Expand Down
1 change: 0 additions & 1 deletion Domain/Entities/Login.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
namespace Domain.Entities

{
public class Login : Entity
{
Expand Down
1 change: 0 additions & 1 deletion Domain/Entities/Permission.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
namespace Domain.Entities

{
public class Permission : Entity
{
Expand Down
Loading