Skip to content

Commit 63533a2

Browse files
committed
Refactor and update dependencies and logging level
- Changed logging level in `appsettings.json` from "information" to "debug". - Downgraded `MongoDB.Driver` in `Genocs.Persistence.MongoDb.csproj` from 2.28.0 to 2.27.0. - Made `Role` and `AccessToken` properties nullable in `AuthDto.cs` and added a class-level comment. - Reformatted constructors in `RefreshToken.cs`, `InvalidNameException.cs`, and `AppException.cs` for readability. - Updated `GetCode` method in `ExceptionToResponseMapper.cs` to return a nullable string and reformatted the method. - Added null check for `users` in `Extensions.cs` and reformatted the code. - Reformatted `IJwtProvider.cs`, `JwtProvider.cs`, `MessageBroker.cs`, `Program.cs`, `CreateProductHandler.cs`, and `HubService.cs` for readability. - Updated comments in `GetOrderHandler.cs` for clarity. - Removed constructor from `CreateProduct.cs`. - Removed namespace declaration from `BrowseProductsHandler.cs`. - Added closing brace in `OperationUpdatedHandler.cs`.
1 parent c61eab2 commit 63533a2

File tree

21 files changed

+131
-100
lines changed

21 files changed

+131
-100
lines changed

src/Genocs.Core.Demo.WebApi/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"displayVersion": true
99
},
1010
"logger": {
11-
"level": "information",
11+
"level": "debug",
1212
"applicationName": "demo-service",
1313
"excludePaths": [ "/ping", "/metrics" ],
1414
"console": {

src/Genocs.Persistence.MongoDb/Genocs.Persistence.MongoDb.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
</ItemGroup>
5151

5252
<ItemGroup>
53-
<PackageReference Include="MongoDB.Driver" Version="2.28.0" />
53+
<PackageReference Include="MongoDB.Driver" Version="2.27.0" />
5454
<PackageReference Include="MongoDB.Driver.Core.Extensions.DiagnosticSources" Version="1.4.0" />
5555
</ItemGroup>
5656

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
namespace Genocs.Identities.Application.DTO;
22

3+
/// <summary>
4+
/// The AuthDto class.
5+
/// </summary>
36
public class AuthDto
47
{
58
public Guid UserId { get; set; }
69
public string Username { get; set; }
7-
public string Role { get; set; }
8-
public string AccessToken { get; set; }
10+
public string? Role { get; set; }
11+
public string? AccessToken { get; set; }
912
public string RefreshToken { get; set; }
1013
public long Expires { get; set; }
1114
}

src/apps/identity/Genocs.Identities.Application/Domain/Entities/RefreshToken.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ public class RefreshToken : AggregateRoot
1010
public DateTime? RevokedAt { get; private set; }
1111
public bool Revoked => RevokedAt.HasValue;
1212

13-
public RefreshToken(AggregateId id, AggregateId userId, string token, DateTime createdAt,
14-
DateTime? revokedAt = null) : base(id)
13+
public RefreshToken(
14+
AggregateId id,
15+
AggregateId userId,
16+
string token,
17+
DateTime createdAt,
18+
DateTime? revokedAt = null)
19+
: base(id)
1520
{
1621
if (string.IsNullOrWhiteSpace(token))
1722
{

src/apps/identity/Genocs.Identities.Application/Domain/Exceptions/InvalidNameException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ namespace Genocs.Identities.Application.Domain.Exceptions;
22

33
public class InvalidNameException : DomainException
44
{
5-
public InvalidNameException(string name) : base($"Invalid name: {name}.")
5+
public InvalidNameException(string name)
6+
: base($"Invalid name: {name}.")
67
{
78
}
89
}

src/apps/identity/Genocs.Identities.Application/Exceptions/AppException.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ namespace Genocs.Identities.Application.Exceptions;
22

33
public abstract class AppException : Exception
44
{
5-
protected AppException(string message) : base(message)
5+
protected AppException(string message)
6+
: base(message)
67
{
78
}
89
}

src/apps/identity/Genocs.Identities.Application/Exceptions/ExceptionToResponseMapper.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@ public class ExceptionToResponseMapper : IExceptionToResponseMapper
1313
public ExceptionResponse Map(Exception exception)
1414
=> exception switch
1515
{
16-
DomainException ex => new ExceptionResponse(new { code = GetCode(ex), reason = ex.Message },
17-
HttpStatusCode.BadRequest),
18-
AppException ex => new ExceptionResponse(new { code = GetCode(ex), reason = ex.Message },
19-
HttpStatusCode.BadRequest),
20-
_ => new ExceptionResponse(new { code = "error", reason = "There was an error." },
21-
HttpStatusCode.BadRequest)
16+
DomainException ex => new ExceptionResponse(new { code = GetCode(ex), reason = ex.Message }, HttpStatusCode.BadRequest),
17+
AppException ex => new ExceptionResponse(new { code = GetCode(ex), reason = ex.Message }, HttpStatusCode.BadRequest),
18+
_ => new ExceptionResponse(new { code = "error", reason = "There was an error." }, HttpStatusCode.BadRequest)
2219
};
2320

24-
private static string GetCode(Exception exception)
21+
private static string? GetCode(Exception exception)
2522
{
2623
var type = exception.GetType();
27-
if (Codes.TryGetValue(type, out var code))
24+
if (Codes.TryGetValue(type, out string? code))
2825
{
2926
return code;
3027
}
3128

32-
var exceptionCode = exception.GetType().Name.Underscore().Replace("_exception", string.Empty);
33-
Codes.TryAdd(type, exceptionCode);
29+
string? exceptionCode = exception.GetType().Name.Underscore()?.Replace("_exception", string.Empty);
30+
if (!string.IsNullOrWhiteSpace(exceptionCode))
31+
{
32+
Codes.TryAdd(type, exceptionCode);
33+
}
3434

3535
return exceptionCode;
3636
}

src/apps/identity/Genocs.Identities.Application/Mongo/Extensions.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,26 @@ public static class Extensions
1111
public static IApplicationBuilder UseMongo(this IApplicationBuilder builder)
1212
{
1313
using var scope = builder.ApplicationServices.CreateScope();
14-
var users = scope.ServiceProvider.GetService<IMongoRepository<UserDocument, Guid>>().Collection;
14+
var users = scope.ServiceProvider.GetService<IMongoRepository<UserDocument, Guid>>()?.Collection;
15+
16+
if (users is null)
17+
{
18+
return builder;
19+
}
20+
1521
var userBuilder = Builders<UserDocument>.IndexKeys;
22+
1623
Task.Run(async () => await users.Indexes.CreateManyAsync(
1724
new[]
1825
{
19-
new CreateIndexModel<UserDocument>(userBuilder.Ascending(i => i.Email),
26+
new CreateIndexModel<UserDocument>(
27+
userBuilder.Ascending(i => i.Email),
2028
new CreateIndexOptions
2129
{
2230
Unique = true
2331
}),
24-
new CreateIndexModel<UserDocument>(userBuilder.Ascending(i => i.Name),
32+
new CreateIndexModel<UserDocument>(
33+
userBuilder.Ascending(i => i.Name),
2534
new CreateIndexOptions
2635
{
2736
Unique = true

src/apps/identity/Genocs.Identities.Application/Services/IJwtProvider.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
namespace Genocs.Identities.Application.Services;
44

55
/// <summary>
6-
/// JwtProvider interface definition
6+
/// JwtProvider interface definition.
77
/// </summary>
88
public interface IJwtProvider
99
{
10-
AuthDto Create(Guid userId, string username, string role, string? audience = null,
11-
IDictionary<string, IEnumerable<string>>? claims = null);
10+
AuthDto Create(
11+
Guid userId,
12+
string username,
13+
string role,
14+
string? audience = null,
15+
IDictionary<string,
16+
IEnumerable<string>>? claims = null);
1217
}

src/apps/identity/Genocs.Identities.Application/Services/JwtProvider.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ public JwtProvider(IJwtHandler jwtHandler)
1212
_jwtHandler = jwtHandler;
1313
}
1414

15-
public AuthDto Create(Guid userId,
16-
string username,
17-
string role,
18-
string? audience = null,
19-
IDictionary<string, IEnumerable<string>>? claims = null)
15+
public AuthDto Create(
16+
Guid userId,
17+
string username,
18+
string role,
19+
string? audience = null,
20+
IDictionary<string, IEnumerable<string>>? claims = null)
2021
{
2122
var jwt = _jwtHandler.CreateToken(userId.ToString("N"), role, audience, claims);
2223

0 commit comments

Comments
 (0)