diff options
| author | transtrike <transtrike@gmail.com> | 2021-02-15 19:06:14 +0200 |
|---|---|---|
| committer | transtrike <transtrike@gmail.com> | 2021-02-15 19:06:14 +0200 |
| commit | 4c03712af14c37718b7be5b23fcadeb86f2a2191 (patch) | |
| tree | 0c6b5a592244e5b2574afa9e4919d4a3111eea34 /src | |
| parent | 09fc4603e82f69c926f9457085aa3fa48bb3939c (diff) | |
| download | DevHive-4c03712af14c37718b7be5b23fcadeb86f2a2191.tar DevHive-4c03712af14c37718b7be5b23fcadeb86f2a2191.tar.gz DevHive-4c03712af14c37718b7be5b23fcadeb86f2a2191.zip | |
Code Analyzer added to all csproj; Removed unnessessary code; Fixed formatting
Diffstat (limited to 'src')
34 files changed, 145 insertions, 171 deletions
diff --git a/src/Common/DevHive.Common.Models/DevHive.Common.csproj b/src/Common/DevHive.Common.Models/DevHive.Common.csproj index 4829c80..f6d662c 100644 --- a/src/Common/DevHive.Common.Models/DevHive.Common.csproj +++ b/src/Common/DevHive.Common.Models/DevHive.Common.csproj @@ -4,6 +4,7 @@ </PropertyGroup> <ItemGroup> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/> </ItemGroup> <PropertyGroup> <EnableNETAnalyzers>true</EnableNETAnalyzers> diff --git a/src/Data/DevHive.Data.Models/DevHive.Data.Models.csproj b/src/Data/DevHive.Data.Models/DevHive.Data.Models.csproj index e58a6d8..e9dc644 100644 --- a/src/Data/DevHive.Data.Models/DevHive.Data.Models.csproj +++ b/src/Data/DevHive.Data.Models/DevHive.Data.Models.csproj @@ -5,5 +5,6 @@ <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0"/> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.3"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/> </ItemGroup> </Project>
\ No newline at end of file diff --git a/src/Data/DevHive.Data.Tests/DevHive.Data.Tests.csproj b/src/Data/DevHive.Data.Tests/DevHive.Data.Tests.csproj index 568edda..2af369f 100644 --- a/src/Data/DevHive.Data.Tests/DevHive.Data.Tests.csproj +++ b/src/Data/DevHive.Data.Tests/DevHive.Data.Tests.csproj @@ -4,14 +4,15 @@ <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> - <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.3" /> - <PackageReference Include="Moq" Version="4.16.0" /> - <PackageReference Include="NUnit" Version="3.13.1" /> - <PackageReference Include="NUnit3TestAdapter" Version="3.17.0" /> - <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" /> + <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.3"/> + <PackageReference Include="Moq" Version="4.16.0"/> + <PackageReference Include="NUnit" Version="3.13.1"/> + <PackageReference Include="NUnit3TestAdapter" Version="3.17.0"/> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/> </ItemGroup> <ItemGroup> - <ProjectReference Include="..\DevHive.Data\DevHive.Data.csproj" /> + <ProjectReference Include="..\DevHive.Data\DevHive.Data.csproj"/> </ItemGroup> <PropertyGroup> <EnableNETAnalyzers>true</EnableNETAnalyzers> diff --git a/src/Data/DevHive.Data/DevHive.Data.csproj b/src/Data/DevHive.Data/DevHive.Data.csproj index fac1581..46928c6 100644 --- a/src/Data/DevHive.Data/DevHive.Data.csproj +++ b/src/Data/DevHive.Data/DevHive.Data.csproj @@ -12,6 +12,7 @@ </PackageReference> <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0"/> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/> </ItemGroup> <ItemGroup> <ProjectReference Include="..\DevHive.Data.Models\DevHive.Data.Models.csproj"/> diff --git a/src/Services/DevHive.Services.Models/DevHive.Services.Models.csproj b/src/Services/DevHive.Services.Models/DevHive.Services.Models.csproj index 3f0eadf..914efe0 100644 --- a/src/Services/DevHive.Services.Models/DevHive.Services.Models.csproj +++ b/src/Services/DevHive.Services.Models/DevHive.Services.Models.csproj @@ -2,12 +2,11 @@ <PropertyGroup> <TargetFramework>net5.0</TargetFramework> </PropertyGroup> - <ItemGroup> - <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" /> + <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/> </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\..\Common\DevHive.Common.Models\DevHive.Common.csproj" /> + <ProjectReference Include="..\..\Common\DevHive.Common.Models\DevHive.Common.csproj"/> </ItemGroup> -</Project> +</Project>
\ No newline at end of file diff --git a/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj b/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj index eb33d07..bdfb2bb 100644 --- a/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj +++ b/src/Services/DevHive.Services.Tests/DevHive.Services.Tests.csproj @@ -4,14 +4,15 @@ <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> - <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.3" /> - <PackageReference Include="Moq" Version="4.16.0" /> - <PackageReference Include="NUnit" Version="3.13.1" /> - <PackageReference Include="NUnit3TestAdapter" Version="3.17.0" /> - <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" /> + <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="5.0.3"/> + <PackageReference Include="Moq" Version="4.16.0"/> + <PackageReference Include="NUnit" Version="3.13.1"/> + <PackageReference Include="NUnit3TestAdapter" Version="3.17.0"/> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/> </ItemGroup> <ItemGroup> - <ProjectReference Include="..\DevHive.Services\DevHive.Services.csproj" /> + <ProjectReference Include="..\DevHive.Services\DevHive.Services.csproj"/> </ItemGroup> <PropertyGroup> <EnableNETAnalyzers>true</EnableNETAnalyzers> diff --git a/src/Services/DevHive.Services.Tests/UserService.Tests.cs b/src/Services/DevHive.Services.Tests/UserService.Tests.cs index 8fddce7..ce997c1 100644 --- a/src/Services/DevHive.Services.Tests/UserService.Tests.cs +++ b/src/Services/DevHive.Services.Tests/UserService.Tests.cs @@ -29,7 +29,7 @@ namespace DevHive.Services.Tests private Mock<ILanguageRepository> LanguageRepositoryMock { get; set; } private Mock<ITechnologyRepository> TechnologyRepositoryMock { get; set; } private Mock<IMapper> MapperMock { get; set; } - private JWTOptions JWTOptions { get; set; } + private JwtOptions JwtOptions { get; set; } private UserService UserService { get; set; } #region SetUps @@ -41,10 +41,10 @@ namespace DevHive.Services.Tests this.CloudServiceMock = new Mock<ICloudService>(); this.LanguageRepositoryMock = new Mock<ILanguageRepository>(); this.TechnologyRepositoryMock = new Mock<ITechnologyRepository>(); - this.JWTOptions = new JWTOptions("gXfQlU6qpDleFWyimscjYcT3tgFsQg3yoFjcvSLxG56n1Vu2yptdIUq254wlJWjm"); + this.JwtOptions = new JwtOptions("gXfQlU6qpDleFWyimscjYcT3tgFsQg3yoFjcvSLxG56n1Vu2yptdIUq254wlJWjm"); this.MapperMock = new Mock<IMapper>(); // TODO: give actual UserManager and RoleManager to UserService - this.UserService = new UserService(this.UserRepositoryMock.Object, this.LanguageRepositoryMock.Object, this.RoleRepositoryMock.Object, this.TechnologyRepositoryMock.Object, null, null, this.MapperMock.Object, this.JWTOptions, this.CloudServiceMock.Object); + this.UserService = new UserService(this.UserRepositoryMock.Object, this.LanguageRepositoryMock.Object, this.RoleRepositoryMock.Object, this.TechnologyRepositoryMock.Object, null, null, this.MapperMock.Object, this.JwtOptions, this.CloudServiceMock.Object); } #endregion @@ -364,7 +364,7 @@ namespace DevHive.Services.Tests #region HelperMethods private string WriteJWTSecurityToken(Guid userId, string username, HashSet<Role> roles) { - byte[] signingKey = Encoding.ASCII.GetBytes(this.JWTOptions.Secret); + byte[] signingKey = Encoding.ASCII.GetBytes(this.JwtOptions.Secret); HashSet<Claim> claims = new() { new Claim("ID", $"{userId}"), diff --git a/src/Services/DevHive.Services/Configurations/Mapping/PostMappings.cs b/src/Services/DevHive.Services/Configurations/Mapping/PostMappings.cs index 9362f90..1d7d88b 100644 --- a/src/Services/DevHive.Services/Configurations/Mapping/PostMappings.cs +++ b/src/Services/DevHive.Services/Configurations/Mapping/PostMappings.cs @@ -12,7 +12,6 @@ namespace DevHive.Services.Configurations.Mapping public PostMappings() { CreateMap<CreatePostServiceModel, Post>(); - // .ForMember(dest => dest.Files, src => src.Ignore()); CreateMap<UpdatePostServiceModel, Post>() .ForMember(dest => dest.Id, src => src.MapFrom(p => p.PostId)) // .ForMember(dest => dest.Files, src => src.Ignore()) diff --git a/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs b/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs index 1dbb7b4..fefa6d8 100644 --- a/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs +++ b/src/Services/DevHive.Services/Configurations/Mapping/RatingMappings.cs @@ -8,8 +8,6 @@ namespace DevHive.Services.Configurations.Mapping { public RatingMappings() { - // CreateMap<Rating, ReadPostRatingServiceModel>() - // .ForMember(dest => dest.PostId, src => src.MapFrom(p => p.Post.Id)); } } } diff --git a/src/Services/DevHive.Services/DevHive.Services.csproj b/src/Services/DevHive.Services/DevHive.Services.csproj index b09c46d..650a304 100644 --- a/src/Services/DevHive.Services/DevHive.Services.csproj +++ b/src/Services/DevHive.Services/DevHive.Services.csproj @@ -3,22 +3,23 @@ <TargetFramework>net5.0</TargetFramework> </PropertyGroup> <ItemGroup> - <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" /> + <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0"/> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> - <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" /> - <PackageReference Include="AutoMapper" Version="10.1.1" /> - <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" /> - <PackageReference Include="CloudinaryDotNet" Version="1.14.0" /> + <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0"/> + <PackageReference Include="AutoMapper" Version="10.1.1"/> + <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1"/> + <PackageReference Include="CloudinaryDotNet" Version="1.14.0"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/> </ItemGroup> <ItemGroup> - <ProjectReference Include="..\..\Data\DevHive.Data\DevHive.Data.csproj" /> - <ProjectReference Include="..\DevHive.Services.Models\DevHive.Services.Models.csproj" /> + <ProjectReference Include="..\..\Data\DevHive.Data\DevHive.Data.csproj"/> + <ProjectReference Include="..\DevHive.Services.Models\DevHive.Services.Models.csproj"/> </ItemGroup> <PropertyGroup> <EnableNETAnalyzers>true</EnableNETAnalyzers> <AnalysisLevel>latest</AnalysisLevel> </PropertyGroup> -</Project> +</Project>
\ No newline at end of file diff --git a/src/Services/DevHive.Services/Interfaces/ICloudService.cs b/src/Services/DevHive.Services/Interfaces/ICloudService.cs index 3ae7a24..040729f 100644 --- a/src/Services/DevHive.Services/Interfaces/ICloudService.cs +++ b/src/Services/DevHive.Services/Interfaces/ICloudService.cs @@ -9,8 +9,6 @@ namespace DevHive.Services.Interfaces { Task<List<string>> UploadFilesToCloud(List<IFormFile> formFiles); - // Task<List<FileContentResult>> GetFilesFromCloud(List<string> fileUrls); - Task<bool> RemoveFilesFromCloud(List<string> fileUrls); } } diff --git a/src/Services/DevHive.Services/Interfaces/IRoleService.cs b/src/Services/DevHive.Services/Interfaces/IRoleService.cs index 2c31b06..05df917 100644 --- a/src/Services/DevHive.Services/Interfaces/IRoleService.cs +++ b/src/Services/DevHive.Services/Interfaces/IRoleService.cs @@ -6,7 +6,7 @@ namespace DevHive.Services.Interfaces { public interface IRoleService { - Task<Guid> CreateRole(CreateRoleServiceModel roleServiceModel); + Task<Guid> CreateRole(CreateRoleServiceModel createRoleServiceModel); Task<RoleServiceModel> GetRoleById(Guid id); diff --git a/src/Services/DevHive.Services/Options/JWTOptions.cs b/src/Services/DevHive.Services/Options/JwtOptions.cs index 95458f5..d973f45 100644 --- a/src/Services/DevHive.Services/Options/JWTOptions.cs +++ b/src/Services/DevHive.Services/Options/JwtOptions.cs @@ -2,9 +2,9 @@ using Microsoft.Extensions.Options; namespace DevHive.Services.Options { - public class JWTOptions + public class JwtOptions { - public JWTOptions(string secret) + public JwtOptions(string secret) { this.Secret = secret; } diff --git a/src/Services/DevHive.Services/Services/FeedService.cs b/src/Services/DevHive.Services/Services/FeedService.cs index 5feef6e..17cc43f 100644 --- a/src/Services/DevHive.Services/Services/FeedService.cs +++ b/src/Services/DevHive.Services/Services/FeedService.cs @@ -57,7 +57,7 @@ namespace DevHive.Services.Services /// <summary> /// This method is used in the profile pages. - /// See the FeedRepository "GetUsersPosts" menthod for more information on how it works. + /// See the FeedRepository "GetUsersPosts" method for more information on how it works. /// </summary> public async Task<ReadPageServiceModel> GetUserPage(GetPageServiceModel model) { diff --git a/src/Services/DevHive.Services/Services/PostService.cs b/src/Services/DevHive.Services/Services/PostService.cs index 0becd9f..a3d5117 100644 --- a/src/Services/DevHive.Services/Services/PostService.cs +++ b/src/Services/DevHive.Services/Services/PostService.cs @@ -41,7 +41,7 @@ namespace DevHive.Services.Services if (createPostServiceModel.Files.Count != 0) { List<string> fileUrls = await _cloudService.UploadFilesToCloud(createPostServiceModel.Files); - post.Attachments = this.GetPostAttachmentsFromUrls(post, fileUrls); + post.Attachments = GetPostAttachmentsFromUrls(post, fileUrls); } post.Creator = await this._userRepository.GetByIdAsync(createPostServiceModel.CreatorId); @@ -105,8 +105,8 @@ namespace DevHive.Services.Services } List<string> fileUrls = await _cloudService.UploadFilesToCloud(updatePostServiceModel.Files) ?? - throw new ArgumentNullException("Unable to upload images to cloud"); - post.Attachments = this.GetPostAttachmentsFromUrls(post, fileUrls); + throw new ArgumentException("Unable to upload images to cloud!"); + post.Attachments = GetPostAttachmentsFromUrls(post, fileUrls); } post.Creator = await this._userRepository.GetByIdAsync(updatePostServiceModel.CreatorId); @@ -202,8 +202,7 @@ namespace DevHive.Services.Services { JwtSecurityToken jwt = new JwtSecurityTokenHandler().ReadJwtToken(rawTokenData.Remove(0, 7)); - Guid jwtUserId = Guid.Parse(this.GetClaimTypeValues("ID", jwt.Claims).First()); - //HashSet<string> jwtRoleNames = this.GetClaimTypeValues("role", jwt.Claims); + Guid jwtUserId = Guid.Parse(GetClaimTypeValues("ID", jwt.Claims).First()); User user = await this._userRepository.GetByIdAsync(jwtUserId) ?? throw new ArgumentException("User does not exist!"); @@ -214,7 +213,7 @@ namespace DevHive.Services.Services /// <summary> /// Returns all values from a given claim type /// </summary> - private List<string> GetClaimTypeValues(string type, IEnumerable<Claim> claims) + private static List<string> GetClaimTypeValues(string type, IEnumerable<Claim> claims) { List<string> toReturn = new(); @@ -227,9 +226,9 @@ namespace DevHive.Services.Services #endregion #region Misc - private List<PostAttachments> GetPostAttachmentsFromUrls(Post post, List<string> fileUrls) + private static List<PostAttachments> GetPostAttachmentsFromUrls(Post post, List<string> fileUrls) { - List<PostAttachments> postAttachments = new List<PostAttachments>(); + List<PostAttachments> postAttachments = new(); foreach (string url in fileUrls) postAttachments.Add(new PostAttachments { Post = post, FileUrl = url }); return postAttachments; diff --git a/src/Services/DevHive.Services/Services/RateService.cs b/src/Services/DevHive.Services/Services/RateService.cs index d423d8c..5e924ab 100644 --- a/src/Services/DevHive.Services/Services/RateService.cs +++ b/src/Services/DevHive.Services/Services/RateService.cs @@ -28,7 +28,7 @@ namespace DevHive.Services.Services { throw new NotImplementedException(); // if (!await this._postRepository.DoesPostExist(ratePostServiceModel.PostId)) - // throw new ArgumentException("Post does not exist!"); + // throw new ArgumentException("Post does not exist!"); // if (!await this._userRepository.DoesUserExistAsync(ratePostServiceModel.UserId)) // throw new ArgumentException("User does not exist!"); diff --git a/src/Services/DevHive.Services/Services/RoleService.cs b/src/Services/DevHive.Services/Services/RoleService.cs index 5472e44..1285421 100644 --- a/src/Services/DevHive.Services/Services/RoleService.cs +++ b/src/Services/DevHive.Services/Services/RoleService.cs @@ -5,7 +5,6 @@ using DevHive.Data.Interfaces; using DevHive.Data.Models; using DevHive.Services.Interfaces; using DevHive.Services.Models.Role; -using DevHive.Services.Models.Language; namespace DevHive.Services.Services { @@ -20,17 +19,17 @@ namespace DevHive.Services.Services this._roleMapper = mapper; } - public async Task<Guid> CreateRole(CreateRoleServiceModel roleServiceModel) + public async Task<Guid> CreateRole(CreateRoleServiceModel createRoleServiceModel) { - if (await this._roleRepository.DoesNameExist(roleServiceModel.Name)) + if (await this._roleRepository.DoesNameExist(createRoleServiceModel.Name)) throw new ArgumentException("Role already exists!"); - Role role = this._roleMapper.Map<Role>(roleServiceModel); + Role role = this._roleMapper.Map<Role>(createRoleServiceModel); bool success = await this._roleRepository.AddAsync(role); if (success) { - Role newRole = await this._roleRepository.GetByNameAsync(roleServiceModel.Name); + Role newRole = await this._roleRepository.GetByNameAsync(createRoleServiceModel.Name); return newRole.Id; } else diff --git a/src/Services/DevHive.Services/Services/UserService.cs b/src/Services/DevHive.Services/Services/UserService.cs index 9a63853..e31eb8d 100644 --- a/src/Services/DevHive.Services/Services/UserService.cs +++ b/src/Services/DevHive.Services/Services/UserService.cs @@ -28,7 +28,7 @@ namespace DevHive.Services.Services private readonly UserManager<User> _userManager; private readonly RoleManager<Role> _roleManager; private readonly IMapper _userMapper; - private readonly JWTOptions _jwtOptions; + private readonly JwtOptions _jwtOptions; private readonly ICloudService _cloudService; public UserService(IUserRepository userRepository, @@ -38,7 +38,7 @@ namespace DevHive.Services.Services UserManager<User> userManager, RoleManager<Role> roleManager, IMapper mapper, - JWTOptions jwtOptions, + JwtOptions jwtOptions, ICloudService cloudService) { this._userRepository = userRepository; @@ -128,7 +128,7 @@ namespace DevHive.Services.Services User currentUser = await this._userRepository.GetByIdAsync(updateUserServiceModel.Id); await this.PopulateUserModel(currentUser, updateUserServiceModel); - if (updateUserServiceModel.Friends.Count() > 0) + if (updateUserServiceModel.Friends.Count > 0) await this.CreateRelationToFriends(currentUser, updateUserServiceModel.Friends.ToList()); else currentUser.Friends.Clear(); @@ -157,7 +157,7 @@ namespace DevHive.Services.Services } string fileUrl = (await this._cloudService.UploadFilesToCloud(new List<IFormFile> { updateProfilePictureServiceModel.Picture }))[0] ?? - throw new ArgumentNullException("Unable to upload profile picture to cloud"); + throw new ArgumentException("Unable to upload profile picture to cloud"); bool successful = await this._userRepository.UpdateProfilePicture(updateProfilePictureServiceModel.UserId, fileUrl); @@ -201,16 +201,13 @@ namespace DevHive.Services.Services /* Check if user is trying to do something to himself, unless he's an admin */ /* Check roles */ - if (!jwtRoleNames.Contains(Role.AdminRole)) - if (user.Id != id) - return false; + if (!jwtRoleNames.Contains(Role.AdminRole) && user.Id != id) + return false; // Check if jwt contains all user roles (if it doesn't, jwt is either old or tampered with) foreach (var role in user.Roles) - { if (!jwtRoleNames.Contains(role.Name)) return false; - } // Check if jwt contains only roles of user if (jwtRoleNames.Count != user.Roles.Count) diff --git a/src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs b/src/Web/DevHive.Web.Models/Attributes/GoodPasswordAttribute.cs index 5ecb41a..c452499 100644 --- a/src/Web/DevHive.Web.Models/Attributes/GoodPasswordModelValidation.cs +++ b/src/Web/DevHive.Web.Models/Attributes/GoodPasswordAttribute.cs @@ -1,9 +1,8 @@ -using System; using System.ComponentModel.DataAnnotations; namespace DevHive.Web.Models.Attributes { - public class GoodPassword : ValidationAttribute + public class GoodPasswordAttribute : ValidationAttribute { public override bool IsValid(object value) { @@ -11,7 +10,7 @@ namespace DevHive.Web.Models.Attributes for (int i = 0; i < stringValue.Length; i++) { - if (Char.IsDigit(stringValue[i])) + if (char.IsDigit(stringValue[i])) { base.ErrorMessage = "Password must be atleast 5 characters long!"; return stringValue.Length >= 5; diff --git a/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs b/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs index 0f6adb1..faaeee4 100644 --- a/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs +++ b/src/Web/DevHive.Web.Models/Attributes/OnlyLettersModelValidation.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations; namespace DevHive.Web.Models.Attributes { - public class OnlyLetters : ValidationAttribute + public class OnlyLettersAttribute : ValidationAttribute { public override bool IsValid(object value) { @@ -11,7 +11,7 @@ namespace DevHive.Web.Models.Attributes foreach (char ch in stringValue) { - if (!Char.IsLetter(ch)) + if (!char.IsLetter(ch)) return false; } return true; diff --git a/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj b/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj index ca49b8c..64d0bd0 100644 --- a/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj +++ b/src/Web/DevHive.Web.Models/DevHive.Web.Models.csproj @@ -3,10 +3,10 @@ <TargetFramework>net5.0</TargetFramework> </PropertyGroup> <ItemGroup> - <ProjectReference Include="..\..\Common\DevHive.Common.Models\DevHive.Common.csproj" /> + <ProjectReference Include="..\..\Common\DevHive.Common.Models\DevHive.Common.csproj"/> </ItemGroup> - <ItemGroup> - <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" /> + <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/> </ItemGroup> -</Project> +</Project>
\ No newline at end of file diff --git a/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs b/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs index 8238f47..3ae93aa 100644 --- a/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs +++ b/src/Web/DevHive.Web.Models/Post/ReadPostWebModel.cs @@ -21,6 +21,5 @@ namespace DevHive.Web.Models.Post public List<IdModel> Comments { get; set; } public List<string> FileUrls { get; set; } - // public List<FileContentResult> Files { get; set; } } } diff --git a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs index 3a03f1a..98397e7 100644 --- a/src/Web/DevHive.Web.Tests/CommentController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/CommentController.Tests.cs @@ -35,11 +35,11 @@ namespace DevHive.Web.Tests public void AddComment_ReturnsOkObjectResult_WhenCommentIsSuccessfullyCreated() { Guid id = Guid.NewGuid(); - CreateCommentWebModel createCommentWebModel = new CreateCommentWebModel + CreateCommentWebModel createCommentWebModel = new() { Message = MESSAGE }; - CreateCommentServiceModel createCommentServiceModel = new CreateCommentServiceModel + CreateCommentServiceModel createCommentServiceModel = new() { Message = MESSAGE }; @@ -67,11 +67,11 @@ namespace DevHive.Web.Tests public void AddComment_ReturnsBadRequestObjectResult_WhenCommentIsNotCreatedSuccessfully() { Guid id = Guid.NewGuid(); - CreateCommentWebModel createCommentWebModel = new CreateCommentWebModel + CreateCommentWebModel createCommentWebModel = new() { Message = MESSAGE }; - CreateCommentServiceModel createCommentServiceModel = new CreateCommentServiceModel + CreateCommentServiceModel createCommentServiceModel = new() { Message = MESSAGE }; @@ -86,8 +86,8 @@ namespace DevHive.Web.Tests Assert.IsInstanceOf<BadRequestObjectResult>(result); - BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult; - string resultMessage = badRequsetObjectResult.Value.ToString(); + BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; + string resultMessage = badRequestObjectResult.Value.ToString(); Assert.AreEqual(errorMessage, resultMessage); } @@ -95,8 +95,7 @@ namespace DevHive.Web.Tests [Test] public void AddComment_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - Guid id = Guid.NewGuid(); - CreateCommentWebModel createCommentWebModel = new CreateCommentWebModel + CreateCommentWebModel createCommentWebModel = new() { Message = MESSAGE }; @@ -115,11 +114,11 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - ReadCommentServiceModel readCommentServiceModel = new ReadCommentServiceModel + ReadCommentServiceModel readCommentServiceModel = new() { Message = MESSAGE }; - ReadCommentWebModel readCommentWebModel = new ReadCommentWebModel + ReadCommentWebModel readCommentWebModel = new() { Message = MESSAGE }; @@ -132,7 +131,7 @@ namespace DevHive.Web.Tests Assert.IsInstanceOf<OkObjectResult>(result); OkObjectResult okObjectResult = result as OkObjectResult; - ReadCommentWebModel resultModel = okObjectResult.Value as Models.Comment.ReadCommentWebModel; + ReadCommentWebModel resultModel = okObjectResult.Value as ReadCommentWebModel; Assert.AreEqual(MESSAGE, resultModel.Message); } @@ -143,11 +142,11 @@ namespace DevHive.Web.Tests public void Update_ShouldReturnOkResult_WhenCommentIsUpdatedSuccessfully() { Guid id = Guid.NewGuid(); - UpdateCommentWebModel updateCommentWebModel = new UpdateCommentWebModel + UpdateCommentWebModel updateCommentWebModel = new() { NewMessage = MESSAGE }; - UpdateCommentServiceModel updateCommentServiceModel = new UpdateCommentServiceModel + UpdateCommentServiceModel updateCommentServiceModel = new() { NewMessage = MESSAGE }; @@ -171,11 +170,11 @@ namespace DevHive.Web.Tests public void Update_ShouldReturnBadObjectResult_WhenCommentIsNotUpdatedSuccessfully() { string message = "Unable to update comment!"; - UpdateCommentWebModel updateCommentWebModel = new UpdateCommentWebModel + UpdateCommentWebModel updateCommentWebModel = new() { NewMessage = MESSAGE }; - UpdateCommentServiceModel updateCommentServiceModel = new UpdateCommentServiceModel + UpdateCommentServiceModel updateCommentServiceModel = new() { NewMessage = MESSAGE }; @@ -196,7 +195,7 @@ namespace DevHive.Web.Tests [Test] public void Update_ShouldReturnUnauthorizedResult_WhenUserIsNotAuthorized() { - UpdateCommentWebModel updateCommentWebModel = new UpdateCommentWebModel + UpdateCommentWebModel updateCommentWebModel = new() { NewMessage = MESSAGE }; @@ -224,7 +223,7 @@ namespace DevHive.Web.Tests } [Test] - public void DeletComment_ReturnsBadRequestObjectResult_WhenCommentIsNotDeletedSuccessfully() + public void DeleteComment_ReturnsBadRequestObjectResult_WhenCommentIsNotDeletedSuccessfully() { string message = "Could not delete Comment"; Guid id = Guid.NewGuid(); @@ -243,7 +242,7 @@ namespace DevHive.Web.Tests } [Test] - public void DeletComment_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() + public void DeleteComment_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { this.CommentServiceMock.Setup(p => p.ValidateJwtForComment(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(false)); diff --git a/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj b/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj index f8390de..465698c 100644 --- a/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj +++ b/src/Web/DevHive.Web.Tests/DevHive.Web.Tests.csproj @@ -4,13 +4,14 @@ <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> - <PackageReference Include="Moq" Version="4.16.0" /> - <PackageReference Include="NUnit" Version="3.13.1" /> - <PackageReference Include="NUnit3TestAdapter" Version="3.17.0" /> - <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" /> + <PackageReference Include="Moq" Version="4.16.0"/> + <PackageReference Include="NUnit" Version="3.13.1"/> + <PackageReference Include="NUnit3TestAdapter" Version="3.17.0"/> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/> </ItemGroup> <ItemGroup> - <ProjectReference Include="..\DevHive.Web\DevHive.Web.csproj" /> + <ProjectReference Include="..\DevHive.Web\DevHive.Web.csproj"/> </ItemGroup> <PropertyGroup> <EnableNETAnalyzers>true</EnableNETAnalyzers> diff --git a/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs b/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs index 7c8d64e..af4672a 100644 --- a/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/LanguageController.Tests.cs @@ -81,8 +81,8 @@ namespace DevHive.Web.Tests Assert.IsInstanceOf<BadRequestObjectResult>(result); - BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult; - string resultMessage = badRequsetObjectResult.Value.ToString(); + BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; + string resultMessage = badRequestObjectResult.Value.ToString(); Assert.AreEqual(errorMessage, resultMessage); } diff --git a/src/Web/DevHive.Web.Tests/PostController.Tests.cs b/src/Web/DevHive.Web.Tests/PostController.Tests.cs index 96b0356..f10f8dd 100644 --- a/src/Web/DevHive.Web.Tests/PostController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/PostController.Tests.cs @@ -32,11 +32,11 @@ namespace DevHive.Web.Tests [Test] public void CreatePost_ReturnsOkObjectResult_WhenPostIsSuccessfullyCreated() { - CreatePostWebModel createPostWebModel = new CreatePostWebModel + CreatePostWebModel createPostWebModel = new() { Message = MESSAGE }; - CreatePostServiceModel createPostServiceModel = new CreatePostServiceModel + CreatePostServiceModel createPostServiceModel = new() { Message = MESSAGE }; @@ -64,11 +64,11 @@ namespace DevHive.Web.Tests [Test] public void CreatePost_ReturnsBadRequestObjectResult_WhenPostIsNotCreatedSuccessfully() { - CreatePostWebModel createTechnologyWebModel = new CreatePostWebModel + CreatePostWebModel createTechnologyWebModel = new() { Message = MESSAGE }; - CreatePostServiceModel createTechnologyServiceModel = new CreatePostServiceModel + CreatePostServiceModel createTechnologyServiceModel = new() { Message = MESSAGE }; @@ -83,8 +83,8 @@ namespace DevHive.Web.Tests Assert.IsInstanceOf<BadRequestObjectResult>(result); - BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult; - string resultMessage = badRequsetObjectResult.Value.ToString(); + BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; + string resultMessage = badRequestObjectResult.Value.ToString(); Assert.AreEqual(errorMessage, resultMessage); } @@ -92,8 +92,7 @@ namespace DevHive.Web.Tests [Test] public void CreatePost_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - Guid id = Guid.NewGuid(); - CreatePostWebModel createPostWebModel = new CreatePostWebModel + CreatePostWebModel createPostWebModel = new() { Message = MESSAGE }; @@ -112,11 +111,11 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - ReadPostServiceModel readPostServiceModel = new ReadPostServiceModel + ReadPostServiceModel readPostServiceModel = new() { Message = MESSAGE }; - ReadPostWebModel readPostWebModel = new ReadPostWebModel + ReadPostWebModel readPostWebModel = new() { Message = MESSAGE }; @@ -140,11 +139,11 @@ namespace DevHive.Web.Tests public void Update_ShouldReturnOkResult_WhenPostIsUpdatedSuccessfully() { Guid id = Guid.NewGuid(); - UpdatePostWebModel updatePostWebModel = new UpdatePostWebModel + UpdatePostWebModel updatePostWebModel = new() { NewMessage = MESSAGE }; - UpdatePostServiceModel updatePostServiceModel = new UpdatePostServiceModel + UpdatePostServiceModel updatePostServiceModel = new() { NewMessage = MESSAGE }; @@ -163,11 +162,11 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); string message = "Could not update post!"; - UpdatePostWebModel updatePostWebModel = new UpdatePostWebModel + UpdatePostWebModel updatePostWebModel = new() { NewMessage = MESSAGE }; - UpdatePostServiceModel updatePostServiceModel = new UpdatePostServiceModel + UpdatePostServiceModel updatePostServiceModel = new() { NewMessage = MESSAGE }; @@ -188,7 +187,7 @@ namespace DevHive.Web.Tests [Test] public void Update_ShouldReturnUnauthorizedResult_WhenUserIsNotAuthorized() { - UpdatePostWebModel updatePostWebModel = new UpdatePostWebModel + UpdatePostWebModel updatePostWebModel = new() { NewMessage = MESSAGE }; diff --git a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs index 64e3f11..ff80dc0 100644 --- a/src/Web/DevHive.Web.Tests/RoleController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/RoleController.Tests.cs @@ -81,8 +81,8 @@ namespace DevHive.Web.Tests Assert.IsInstanceOf<BadRequestObjectResult>(result); - BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult; - string resultMessage = badRequsetObjectResult.Value.ToString(); + BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; + string resultMessage = badRequestObjectResult.Value.ToString(); Assert.AreEqual(errorMessage, resultMessage); } diff --git a/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs b/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs index 164bcbf..a00f1db 100644 --- a/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/TechnologyController.Tests.cs @@ -84,8 +84,8 @@ namespace DevHive.Web.Tests Assert.IsInstanceOf<BadRequestObjectResult>(result); - BadRequestObjectResult badRequsetObjectResult = result as BadRequestObjectResult; - string resultMessage = badRequsetObjectResult.Value.ToString(); + BadRequestObjectResult badRequestObjectResult = result as BadRequestObjectResult; + string resultMessage = badRequestObjectResult.Value.ToString(); Assert.AreEqual(errorMessage, resultMessage); } diff --git a/src/Web/DevHive.Web.Tests/UserController.Tests.cs b/src/Web/DevHive.Web.Tests/UserController.Tests.cs index 7457ad7..13f618e 100644 --- a/src/Web/DevHive.Web.Tests/UserController.Tests.cs +++ b/src/Web/DevHive.Web.Tests/UserController.Tests.cs @@ -33,17 +33,17 @@ namespace DevHive.Web.Tests public void LoginUser_ReturnsOkObjectResult_WhenUserIsSuccessfullyLoggedIn() { Guid id = Guid.NewGuid(); - LoginWebModel loginWebModel = new LoginWebModel + LoginWebModel loginWebModel = new() { UserName = USERNAME }; - LoginServiceModel loginServiceModel = new LoginServiceModel + LoginServiceModel loginServiceModel = new() { UserName = USERNAME }; string token = "goshotrapov"; - TokenModel tokenModel = new TokenModel(token); - TokenWebModel tokenWebModel = new TokenWebModel(token); + TokenModel tokenModel = new(token); + TokenWebModel tokenWebModel = new(token); this.MapperMock.Setup(p => p.Map<LoginServiceModel>(It.IsAny<LoginWebModel>())).Returns(loginServiceModel); this.MapperMock.Setup(p => p.Map<TokenWebModel>(It.IsAny<TokenModel>())).Returns(tokenWebModel); @@ -61,18 +61,17 @@ namespace DevHive.Web.Tests [Test] public void RegisterUser_ReturnsOkObjectResult_WhenUserIsSuccessfullyRegistered() { - Guid id = Guid.NewGuid(); - RegisterWebModel registerWebModel = new RegisterWebModel + RegisterWebModel registerWebModel = new() { UserName = USERNAME }; - RegisterServiceModel registerServiceModel = new RegisterServiceModel + RegisterServiceModel registerServiceModel = new() { UserName = USERNAME }; string token = "goshotrapov"; - TokenModel tokenModel = new TokenModel(token); - TokenWebModel tokenWebModel = new TokenWebModel(token); + TokenModel tokenModel = new(token); + TokenWebModel tokenWebModel = new(token); this.MapperMock.Setup(p => p.Map<RegisterServiceModel>(It.IsAny<RegisterWebModel>())).Returns(registerServiceModel); this.MapperMock.Setup(p => p.Map<TokenWebModel>(It.IsAny<TokenModel>())).Returns(tokenWebModel); @@ -95,11 +94,11 @@ namespace DevHive.Web.Tests { Guid id = Guid.NewGuid(); - UserServiceModel userServiceModel = new UserServiceModel + UserServiceModel userServiceModel = new() { UserName = USERNAME }; - UserWebModel userWebModel = new UserWebModel + UserWebModel userWebModel = new() { UserName = USERNAME }; @@ -121,12 +120,6 @@ namespace DevHive.Web.Tests [Test] public void GetById_ReturnsUnauthorizedResult_WhenUserIsNotAuthorized() { - Guid id = Guid.NewGuid(); - UserWebModel userWebModel = new UserWebModel - { - UserName = USERNAME - }; - this.UserServiceMock.Setup(p => p.ValidJWT(It.IsAny<Guid>(), It.IsAny<string>())).Returns(Task.FromResult(false)); IActionResult result = this.UserController.GetById(Guid.NewGuid(), null).Result; @@ -137,12 +130,11 @@ namespace DevHive.Web.Tests [Test] public void GetUser_ReturnsTheUser_WhenItExists() { - Guid id = Guid.NewGuid(); - UserWebModel userWebModel = new UserWebModel + UserWebModel userWebModel = new() { UserName = USERNAME }; - UserServiceModel userServiceModel = new UserServiceModel + UserServiceModel userServiceModel = new() { UserName = USERNAME }; @@ -166,15 +158,15 @@ namespace DevHive.Web.Tests public void Update_ShouldReturnOkResult_WhenUserIsUpdatedSuccessfully() { Guid id = Guid.NewGuid(); - UpdateUserWebModel updateUserWebModel = new UpdateUserWebModel + UpdateUserWebModel updateUserWebModel = new() { UserName = USERNAME }; - UpdateUserServiceModel updateUserServiceModel = new UpdateUserServiceModel + UpdateUserServiceModel updateUserServiceModel = new() { UserName = USERNAME }; - UserServiceModel userServiceModel = new UserServiceModel + UserServiceModel userServiceModel = new() { UserName = USERNAME }; @@ -192,13 +184,13 @@ namespace DevHive.Web.Tests public void UpdateProfilePicture_ShouldReturnOkObjectResult_WhenProfilePictureIsUpdatedSuccessfully() { string profilePictureURL = "goshotrapov"; - UpdateProfilePictureWebModel updateProfilePictureWebModel = new UpdateProfilePictureWebModel(); - UpdateProfilePictureServiceModel updateProfilePictureServiceModel = new UpdateProfilePictureServiceModel(); - ProfilePictureServiceModel profilePictureServiceModel = new ProfilePictureServiceModel + UpdateProfilePictureWebModel updateProfilePictureWebModel = new(); + UpdateProfilePictureServiceModel updateProfilePictureServiceModel = new(); + ProfilePictureServiceModel profilePictureServiceModel = new() { ProfilePictureURL = profilePictureURL }; - ProfilePictureWebModel profilePictureWebModel = new ProfilePictureWebModel + ProfilePictureWebModel profilePictureWebModel = new() { ProfilePictureURL = profilePictureURL }; diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs index 8b7d657..0b8194e 100644 --- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs +++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureAutoMapper.cs @@ -1,6 +1,5 @@ using System; using AutoMapper; -//using AutoMapper.Configuration; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; @@ -15,10 +14,10 @@ namespace DevHive.Web.Configurations.Extensions public static void UseAutoMapperConfiguration(this IApplicationBuilder app) { - var config = new MapperConfiguration(cfg => + _ = new MapperConfiguration(cfg => { cfg.AllowNullCollections = true; }); } } -}
\ No newline at end of file +} diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs index 286727f..c017a8c 100644 --- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs +++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureExceptionHandlerMiddleware.cs @@ -6,8 +6,6 @@ namespace DevHive.Web.Configurations.Extensions { public static class ConfigureExceptionHandlerMiddleware { - public static void ExceptionHandlerMiddlewareConfiguration(this IServiceCollection services) { } - public static void UseExceptionHandlerMiddlewareConfiguration(this IApplicationBuilder app) { app.UseMiddleware<ExceptionMiddleware>(); diff --git a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs index d422bc8..03d4b11 100644 --- a/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJWT.cs +++ b/src/Web/DevHive.Web/Configurations/Extensions/ConfigureJwt.cs @@ -8,11 +8,11 @@ using Microsoft.IdentityModel.Tokens; namespace DevHive.Web.Configurations.Extensions { - public static class JWTExtensions + public static class ConfigureJwt { public static void JWTConfiguration(this IServiceCollection services, IConfiguration configuration) { - services.AddSingleton(new JWTOptions(configuration + services.AddSingleton(new JwtOptions(configuration .GetSection("AppSettings") .GetSection("Secret") .Value)); @@ -51,4 +51,4 @@ namespace DevHive.Web.Configurations.Extensions }); } } -}
\ No newline at end of file +} diff --git a/src/Web/DevHive.Web/DevHive.Web.csproj b/src/Web/DevHive.Web/DevHive.Web.csproj index 6f78b69..6511c37 100644 --- a/src/Web/DevHive.Web/DevHive.Web.csproj +++ b/src/Web/DevHive.Web/DevHive.Web.csproj @@ -7,21 +7,22 @@ <AnalysisLevel>latest</AnalysisLevel> </PropertyGroup> <ItemGroup> - <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.3" NoWarn="NU1605" /> - <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.3" NoWarn="NU1605" /> + <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.3" NoWarn="NU1605"/> + <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.3" NoWarn="NU1605"/> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> - <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" /> - <PackageReference Include="Swashbuckle.AspNetCore" Version="6.0.5" /> - <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" /> - <PackageReference Include="AutoMapper" Version="10.1.1" /> - <PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> - <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.3" /> + <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2"/> + <PackageReference Include="Swashbuckle.AspNetCore" Version="6.0.5"/> + <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1"/> + <PackageReference Include="AutoMapper" Version="10.1.1"/> + <PackageReference Include="Newtonsoft.Json" Version="12.0.3"/> + <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.3"/> + <PackageReference Include="SonarAnalyzer.CSharp" Version="8.18.0.27296"/> </ItemGroup> <ItemGroup> - <ProjectReference Include="..\DevHive.Web.Models\DevHive.Web.Models.csproj" /> - <ProjectReference Include="..\..\Services\DevHive.Services\DevHive.Services.csproj" /> + <ProjectReference Include="..\DevHive.Web.Models\DevHive.Web.Models.csproj"/> + <ProjectReference Include="..\..\Services\DevHive.Services\DevHive.Services.csproj"/> </ItemGroup> </Project>
\ No newline at end of file diff --git a/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs b/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs index cb6d4ca..f159b69 100644 --- a/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs +++ b/src/Web/DevHive.Web/Middleware/ExceptionMiddleware.cs @@ -9,18 +9,11 @@ namespace DevHive.Web.Middleware public class ExceptionMiddleware { private readonly RequestDelegate _next; - // private readonly ILogger _logger; public ExceptionMiddleware(RequestDelegate next) { this._next = next; - // this._logger = logger; } - // public ExceptionMiddleware(RequestDelegate next, ILogger logger) - // { - // this._logger = logger; - // this._next = next; - // } public async Task InvokeAsync(HttpContext httpContext) { @@ -30,20 +23,19 @@ namespace DevHive.Web.Middleware } catch (Exception ex) { - // this._logger.LogError($"Something went wrong: {ex}"); await HandleExceptionAsync(httpContext, ex); } } - private Task HandleExceptionAsync(HttpContext context, Exception exception) + private static Task HandleExceptionAsync(HttpContext context, Exception exception) { context.Response.ContentType = "application/json"; context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return context.Response.WriteAsync(new { - StatusCode = context.Response.StatusCode, - Message = exception.Message + context.Response.StatusCode, + exception.Message }.ToString()); } } |
