Skip to content

Commit 2cca2c1

Browse files
committed
fix: resolve remaining SonarQube issues
- Remove operator == and != overloads from Entity<T> - Replace Count() with Any() in RecommendationService for performance - Change ToActionResult return type from IActionResult to ObjectResult - Rename userClaims to user in AuthService to match interface - Extract GetSigningKey() method in JwtTokenService to reduce direct config access
1 parent c707c94 commit 2cca2c1

5 files changed

Lines changed: 17 additions & 33 deletions

File tree

EventFlow.Application/Services/AuthService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public class AuthService(
5757
};
5858
}
5959

60-
public async Task<bool> UpdatePasswordAsync(ClaimsPrincipal userClaims, UserPasswordUpdateDto dto)
60+
public async Task<bool> UpdatePasswordAsync(ClaimsPrincipal user, UserPasswordUpdateDto dto)
6161
{
62-
var email = userClaims.FindFirstValue(ClaimTypes.Email);
62+
var email = user.FindFirstValue(ClaimTypes.Email);
6363
if (string.IsNullOrEmpty(email)) return false;
6464

6565
var entity = await userRepository.GetByEmailAsync(email);

EventFlow.Application/Services/RecommendationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public async Task<IEnumerable<EventDTO>> GetRecommendedEventsAsync(int participa
2121

2222
var allParticipants = await _participantRepository.GetAllParticipantsWithEventsAsync();
2323
var similarParticipants = allParticipants
24-
.Where(p => p.Id != participantId && p.Events != null && p.Events.Count(e => participantEventsIds.Contains(e.Id)) > 0)
24+
.Where(p => p.Id != participantId && p.Events != null && p.Events.Any(e => participantEventsIds.Contains(e.Id)))
2525
.ToList();
2626

2727
var recommendedEvents = similarParticipants

EventFlow.Core/Primitives/Entity.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,4 @@ public override int GetHashCode()
4848
return (GetType().ToString() + Id).GetHashCode();
4949
}
5050

51-
public static bool operator ==(Entity<TId>? a, Entity<TId>? b)
52-
{
53-
if (ReferenceEquals(a, b))
54-
return true;
55-
56-
if (a is null || b is null)
57-
return false;
58-
59-
return a.Equals(b);
60-
}
61-
62-
public static bool operator !=(Entity<TId>? a, Entity<TId>? b)
63-
{
64-
return !(a == b);
65-
}
6651
}

EventFlow.Infrastructure/Services/JwtTokenService.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@ public JwtTokenService(IConfiguration configuration)
1919
public string GenerateToken(int userId, string username, string email)
2020
{
2121
var tokenHandler = new JwtSecurityTokenHandler();
22-
var jwtKey = _configuration["Jwt:Key"]
23-
?? throw new InvalidOperationException("JWT Key is not configured.");
24-
25-
if (jwtKey.Length < 32)
26-
throw new InvalidOperationException("JWT Key must be at least 32 characters long.");
27-
28-
var key = Encoding.ASCII.GetBytes(jwtKey);
22+
var key = GetSigningKey();
2923

3024
var tokenDescriptor = new SecurityTokenDescriptor
3125
{
@@ -51,13 +45,7 @@ public string GenerateToken(int userId, string username, string email)
5145
public ClaimsPrincipal? ValidateToken(string token)
5246
{
5347
var tokenHandler = new JwtSecurityTokenHandler();
54-
var jwtKey = _configuration["Jwt:Key"]
55-
?? throw new InvalidOperationException("JWT Key is not configured.");
56-
57-
if (jwtKey.Length < 32)
58-
throw new InvalidOperationException("JWT Key must be at least 32 characters long.");
59-
60-
var key = Encoding.ASCII.GetBytes(jwtKey);
48+
var key = GetSigningKey();
6149

6250
try
6351
{
@@ -79,4 +67,15 @@ public string GenerateToken(int userId, string username, string email)
7967
return null;
8068
}
8169
}
70+
71+
private byte[] GetSigningKey()
72+
{
73+
var jwtKey = _configuration["Jwt:Key"]
74+
?? throw new InvalidOperationException("JWT Key is not configured.");
75+
76+
if (jwtKey.Length < 32)
77+
throw new InvalidOperationException("JWT Key must be at least 32 characters long.");
78+
79+
return Encoding.ASCII.GetBytes(jwtKey);
80+
}
8281
}

EventFlow.Presentation/Extensions/ResultExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static IActionResult ToActionResult(this Result result)
1818
: result.Error.ToActionResult();
1919
}
2020

21-
private static IActionResult ToActionResult(this Error error)
21+
private static ObjectResult ToActionResult(this Error error)
2222
{
2323
return error.Type switch
2424
{

0 commit comments

Comments
 (0)