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

VIH-11099 Resolved all sonar cloud issues #167

Merged
merged 3 commits into from
Nov 11, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private Task<string> GenerateApiToken()

private string GenerateCallbackToken()
{
return new CustomJwtTokenProvider().GenerateTokenForCallbackEndpoint(_notifyConfiguration.CallbackSecret, 60);
return CustomJwtTokenProvider.GenerateTokenForCallbackEndpoint(_notifyConfiguration.CallbackSecret, 60);
}

private void RegisterSettings()
Expand Down
128 changes: 64 additions & 64 deletions NotificationApi/NotificationApi.Client/NotificationApiClient.cs

Large diffs are not rendered by default.

18 changes: 5 additions & 13 deletions NotificationApi/NotificationApi.Common/BadRequestException.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
using System;
using System.Runtime.Serialization;

namespace NotificationApi.Common
{
/// <summary>
/// Exception to throw when input data passed downstream from the api input is in an invalid format
/// </summary>
[Serializable]
public class BadRequestException : Exception
{
protected BadRequestException(SerializationInfo info, StreamingContext context) : base(info, context) { }
namespace NotificationApi.Common;

public BadRequestException(string message) : base(message) { }
}
}
/// <summary>
/// Exception to throw when input data passed downstream from the api input is in an invalid format
/// </summary>
public class BadRequestException(string message) : Exception(message);
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public Dictionary<string, object> ConvertToDictionary(object input, string path
return result;
}

IterateTypeProperties(input, path, debth, type, result);

return result;
}

private void IterateTypeProperties(object input, string path, int debth, Type type, Dictionary<string, object> result)
{
foreach (var property in type.GetProperties())
{
var value = property.GetValue(input);
Expand All @@ -48,18 +55,16 @@ public Dictionary<string, object> ConvertToDictionary(object input, string path
result.Add(GetPath(path, property.Name), value);
}
}

return result;
}

private string GetPath(string path, string property) => $"{path}{(string.IsNullOrEmpty(path) ? string.Empty : ".")}{property}";
private static string GetPath(string path, string property) => $"{path}{(string.IsNullOrEmpty(path) ? string.Empty : ".")}{property}";

/// <summary>
/// Pass in type to see if we should recuse deeper
/// Not generic due to use case.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
private bool IsCustomType(Type type) => !type.IsEnum && type.AssemblyQualifiedName.StartsWith(this.GetType().AssemblyQualifiedName.Split('.')[0]);
private bool IsCustomType(Type type) => !type.IsEnum && type.AssemblyQualifiedName!.StartsWith(GetType().AssemblyQualifiedName!.Split('.')[0]);
}
}

This file was deleted.

12 changes: 5 additions & 7 deletions NotificationApi/NotificationApi.Contract/MessageType.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
namespace NotificationApi.Contract
namespace NotificationApi.Contract;

public enum MessageType
{
// Public contract for NotificationApi.Domain.Enums.MessageType
public enum MessageType
{
Email = 1,
SMS = 2
}
Email = 1,
SMS = 2
}
116 changes: 57 additions & 59 deletions NotificationApi/NotificationApi.Contract/NotificationType.cs
Original file line number Diff line number Diff line change
@@ -1,61 +1,59 @@
namespace NotificationApi.Contract
namespace NotificationApi.Contract;

public enum NotificationType
{
// Public contract for NotificationApi.Domain.Enums.NotificationType
public enum NotificationType
{
CreateIndividual = 1,
CreateRepresentative = 2,
PasswordReset = 3,
HearingConfirmationLip = 4,
HearingConfirmationRepresentative = 5,
HearingConfirmationJudge = 6,
HearingConfirmationJoh = 7,
HearingConfirmationLipMultiDay = 8,
HearingConfirmationRepresentativeMultiDay = 9,
HearingConfirmationJudgeMultiDay = 10,
HearingConfirmationJohMultiDay = 11,
HearingAmendmentLip = 12,
HearingAmendmentRepresentative = 13,
HearingAmendmentJudge = 14,
HearingAmendmentJoh = 15,
HearingReminderLip = 16,
HearingReminderRepresentative = 17,
HearingReminderJoh = 18,
HearingConfirmationEJudJudge = 19,
HearingConfirmationEJudJudgeMultiDay = 20,
HearingAmendmentEJudJudge = 21,
HearingAmendmentEJudJoh = 22,
HearingReminderEJudJoh = 23,
HearingConfirmationEJudJoh = 24,
HearingConfirmationEJudJohMultiDay = 25,
EJudJohDemoOrTest = 26,
EJudJudgeDemoOrTest = 27,
JudgeDemoOrTest = 28,
ParticipantDemoOrTest = 29,
TelephoneHearingConfirmation = 30,
TelephoneHearingConfirmationMultiDay = 31,
CreateStaffMember = 32,
HearingAmendmentStaffMember = 33,
HearingConfirmationStaffMember = 34,
HearingConfirmationStaffMemberMultiDay = 35,
StaffMemberDemoOrTest = 36,
NewHearingReminderLIP = 37,
NewHearingReminderRepresentative = 38,
NewHearingReminderJOH = 39,
NewHearingReminderEJudJoh = 40,
NewUserLipWelcome = 41,
NewUserLipConfirmation = 42,
NewUserLipConfirmationMultiDay = 43,
ExistingUserLipConfirmation = 44,
ExistingUserLipConfirmationMultiDay = 45,
NewHearingReminderLipSingleDay = 46,
NewHearingReminderLipMultiDay = 47,
NewUserRepresentativeWelcome = 48,
NewUserRepresentativeConfirmation = 49,
NewUserRepresentativeConfirmationMultiDay = 50,
ExistingUserRepresentativeConfirmation = 51,
ExistingUserRepresentativeConfirmationMultiDay = 52,
NewHearingReminderRepresentativeSingleDay = 53,
NewHearingReminderRepresentativeMultiDay = 54,
}
CreateIndividual = 1,
CreateRepresentative = 2,
PasswordReset = 3,
HearingConfirmationLip = 4,
HearingConfirmationRepresentative = 5,
HearingConfirmationJudge = 6,
HearingConfirmationJoh = 7,
HearingConfirmationLipMultiDay = 8,
HearingConfirmationRepresentativeMultiDay = 9,
HearingConfirmationJudgeMultiDay = 10,
HearingConfirmationJohMultiDay = 11,
HearingAmendmentLip = 12,
HearingAmendmentRepresentative = 13,
HearingAmendmentJudge = 14,
HearingAmendmentJoh = 15,
HearingReminderLip = 16,
HearingReminderRepresentative = 17,
HearingReminderJoh = 18,
HearingConfirmationEJudJudge = 19,
HearingConfirmationEJudJudgeMultiDay = 20,
HearingAmendmentEJudJudge = 21,
HearingAmendmentEJudJoh = 22,
HearingReminderEJudJoh = 23,
HearingConfirmationEJudJoh = 24,
HearingConfirmationEJudJohMultiDay = 25,
EJudJohDemoOrTest = 26,
EJudJudgeDemoOrTest = 27,
JudgeDemoOrTest = 28,
ParticipantDemoOrTest = 29,
TelephoneHearingConfirmation = 30,
TelephoneHearingConfirmationMultiDay = 31,
CreateStaffMember = 32,
HearingAmendmentStaffMember = 33,
HearingConfirmationStaffMember = 34,
HearingConfirmationStaffMemberMultiDay = 35,
StaffMemberDemoOrTest = 36,
NewHearingReminderLIP = 37,
NewHearingReminderRepresentative = 38,
NewHearingReminderJOH = 39,
NewHearingReminderEJudJoh = 40,
NewUserLipWelcome = 41,
NewUserLipConfirmation = 42,
NewUserLipConfirmationMultiDay = 43,
ExistingUserLipConfirmation = 44,
ExistingUserLipConfirmationMultiDay = 45,
NewHearingReminderLipSingleDay = 46,
NewHearingReminderLipMultiDay = 47,
NewUserRepresentativeWelcome = 48,
NewUserRepresentativeConfirmation = 49,
NewUserRepresentativeConfirmationMultiDay = 50,
ExistingUserRepresentativeConfirmation = 51,
ExistingUserRepresentativeConfirmationMultiDay = 52,
NewHearingReminderRepresentativeSingleDay = 53,
NewHearingReminderRepresentativeMultiDay = 54,
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,25 @@
using Microsoft.Extensions.Logging;
using NotificationApi.Common.Helpers;

namespace NotificationApi.DAL.Commands.Core
namespace NotificationApi.DAL.Commands.Core;

public class CommandHandlerLoggingDecorator<TCommand>(
ICommandHandler<TCommand> underlyingHandler,
ILogger<TCommand> logger,
ILoggingDataExtractor loggingDataExtractor)
: ICommandHandler<TCommand>
where TCommand : ICommand
{
public class CommandHandlerLoggingDecorator<TCommand> : ICommandHandler<TCommand> where TCommand : ICommand
public async Task Handle(TCommand command)
{
private readonly ICommandHandler<TCommand> _underlyingHandler;

private readonly ILogger<TCommand> _logger;

private readonly ILoggingDataExtractor _loggingDataExtractor;

public CommandHandlerLoggingDecorator(ICommandHandler<TCommand> underlyingHandler, ILogger<TCommand> logger, ILoggingDataExtractor loggingDataExtractor)
{
_logger = logger;
_underlyingHandler = underlyingHandler;
_loggingDataExtractor = loggingDataExtractor;
}

public async Task Handle(TCommand command)
var properties = loggingDataExtractor.ConvertToDictionary(command);
properties.Add(nameof(TCommand), typeof(TCommand).Name);
using (logger.BeginScope(properties))
{
var properties = _loggingDataExtractor.ConvertToDictionary(command);
properties.Add(nameof(TCommand), typeof(TCommand).Name);
using (_logger.BeginScope(properties))
{
_logger.LogDebug("Handling command");
var sw = Stopwatch.StartNew();
await _underlyingHandler.Handle(command);
_logger.LogDebug("Handled command in {ElapsedMilliseconds}ms", sw.ElapsedMilliseconds);
}
logger.LogDebug("Handling command");
var sw = Stopwatch.StartNew();
await underlyingHandler.Handle(command);
logger.LogDebug("Handled command in {ElapsedMilliseconds}ms", sw.ElapsedMilliseconds);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
using System;
using System.Runtime.Serialization;
using NotificationApi.Domain.Enums;

namespace NotificationApi.DAL.Exceptions
{
namespace NotificationApi.DAL.Exceptions;

[Serializable]
public class DuplicateNotificationTemplateException : Exception
{
public DuplicateNotificationTemplateException(NotificationType notificationType) : base(
$"Duplicate entry for notification type {notificationType} found")
{
}

protected DuplicateNotificationTemplateException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
public class DuplicateNotificationTemplateException(NotificationType notificationType)
: Exception($"Duplicate entry for notification type {notificationType} found");
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
using System.Threading.Tasks;

namespace NotificationApi.DAL.Queries.Core
namespace NotificationApi.DAL.Queries.Core;

public class QueryHandler(IQueryHandlerFactory queryHandlerFactory) : IQueryHandler
{
public class QueryHandler : IQueryHandler
public Task<TResult> Handle<TQuery, TResult>(TQuery query) where TQuery : IQuery where TResult : class
{
private readonly IQueryHandlerFactory _queryHandlerFactory;

public QueryHandler(IQueryHandlerFactory queryHandlerFactory)
{
_queryHandlerFactory = queryHandlerFactory;
}

public Task<TResult> Handle<TQuery, TResult>(TQuery query) where TQuery : IQuery where TResult : class
{
var handler = _queryHandlerFactory.Create<TQuery, TResult>(query);
return handler.Handle(query);
}
var handler = queryHandlerFactory.Create<TQuery, TResult>(query);
return handler.Handle(query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,29 @@
using Microsoft.Extensions.Logging;
using NotificationApi.Common.Helpers;

namespace NotificationApi.DAL.Queries.Core
namespace NotificationApi.DAL.Queries.Core;

public class QueryHandlerLoggingDecorator<TQuery, TResult>(
IQueryHandler<TQuery, TResult> underlyingHandler,
ILogger<TQuery> logger,
ILoggingDataExtractor loggingDataExtractor)
: IQueryHandler<TQuery, TResult>
where TQuery : IQuery
where TResult : class
{
public class QueryHandlerLoggingDecorator<TQuery, TResult> : IQueryHandler<TQuery, TResult> where TQuery : IQuery where TResult : class
public async Task<TResult> Handle(TQuery query)
{
private readonly IQueryHandler<TQuery, TResult> _underlyingHandler;

private readonly ILogger<TQuery> _logger;

private readonly ILoggingDataExtractor _loggingDataExtractor;

public QueryHandlerLoggingDecorator(IQueryHandler<TQuery, TResult> underlyingHandler, ILogger<TQuery> logger, ILoggingDataExtractor loggingDataExtractor)
{
_logger = logger;
_underlyingHandler = underlyingHandler;
_loggingDataExtractor = loggingDataExtractor;
}

public async Task<TResult> Handle(TQuery query)
var properties = loggingDataExtractor.ConvertToDictionary(query);
properties.Add(nameof(TQuery), typeof(TQuery).Name);
properties.Add(nameof(TResult), typeof(TResult).Name);
using (logger.BeginScope(properties))
{
var properties = _loggingDataExtractor.ConvertToDictionary(query);
properties.Add(nameof(TQuery), typeof(TQuery).Name);
properties.Add(nameof(TResult), typeof(TResult).Name);
using (_logger.BeginScope(properties))
{
// Unfortunetely this scope wont apply to the underlying handler as its already been resolved from the logger factory.
_logger.LogDebug("Handling query");
var sw = Stopwatch.StartNew();
var result = await _underlyingHandler.Handle(query);
_logger.LogDebug("Handled query in {ElapsedMilliseconds}ms", sw.ElapsedMilliseconds);
return result;
}
// Unfortunately this scope won't apply to the underlying handler as its already been resolved from the logger factory.
logger.LogDebug("Handling query");
var sw = Stopwatch.StartNew();
var result = await underlyingHandler.Handle(query);
logger.LogDebug("Handled query in {ElapsedMilliseconds}ms", sw.ElapsedMilliseconds);
return result;
}
}
}
Loading
Loading