From 5c5f12b123807af1e38b5db8d3b7e45604b377bc Mon Sep 17 00:00:00 2001 From: msaad Date: Tue, 17 Sep 2024 15:25:36 +0100 Subject: [PATCH] optimisation --- .../ProjectService.cs | 2 +- .../UserProfileApiClient.cs | 2 +- .../WorkItem/WorkItemExternalService.cs | 4 +- .../ProfileUser/ProfileUserCommandHandler.cs | 14 +++--- .../ProjectResource/ProjectCommandHandler.cs | 4 +- .../WorkItemCommandHandler.cs | 4 +- .../AzureDevopsService.Contracts.csproj | 2 +- .../AllProjectUnderOrganizationRequest.cs | 9 ++-- .../AzureRequestResourceModel/BaseRequest.cs | 4 +- .../AzureRequestResourceModel/WiqlRequest.cs | 27 +++++------ .../WorkItemRequest.cs | 11 ++--- .../AzureResponceModel/AllProjectResponce.cs | 21 ++++---- .../CustomProblemDetailsResponce.cs | 11 ++--- .../AzureResponceModel/Project.cs | 35 +++++++------- .../AzureResponceModel/UserAccount.cs | 19 +++----- .../AzureResponceModel/UserOrganization.cs | 6 +-- .../AzureResponceModel/UserProfile.cs | 10 ++-- .../WiqlBadRequestResponce.cs | 12 ++--- .../ProfileUser/ProfileUserConsumer.cs | 48 +++++++++---------- .../GlobalUsings.cs | 8 +++- .../AionTimeSubscriptionConfiguration.cs | 8 ++-- ...ionTimeSubscriptionHistoryConfiguration.cs | 8 ++-- .../OrganizationConfiguration.cs | 16 +++---- .../Configurations/ProjectConfiguration.cs | 16 +++---- .../Configurations/UserConfiguration.cs | 12 ++--- .../Configurations/WorkItemConfiguration.cs | 6 +-- .../WorkItemHistoryConfiguration.cs | 6 +-- .../WorkItemTimeLogConfiguration.cs | 12 ++--- .../TimeLogServiceDataBaseContext.cs | 23 ++++----- 29 files changed, 171 insertions(+), 189 deletions(-) diff --git a/src/AzureDevopsService/AzureDevopsService.Application/AzureDevopsExternalResourceService/OrganizationProjectService/ProjectService.cs b/src/AzureDevopsService/AzureDevopsService.Application/AzureDevopsExternalResourceService/OrganizationProjectService/ProjectService.cs index e84744e..a338511 100644 --- a/src/AzureDevopsService/AzureDevopsService.Application/AzureDevopsExternalResourceService/OrganizationProjectService/ProjectService.cs +++ b/src/AzureDevopsService/AzureDevopsService.Application/AzureDevopsExternalResourceService/OrganizationProjectService/ProjectService.cs @@ -14,7 +14,7 @@ public async Task> AllPr if (projectsResult.StatusCode == HttpStatusCode.OK) { AllProjectResponce projects = await projectsResult.Content.ReadFromJsonAsync(); - projects.Path = request.Path; + projects!.Path = request.Path; projects.Email = request.Email; return projects; diff --git a/src/AzureDevopsService/AzureDevopsService.Application/AzureDevopsExternalResourceService/ProfileUserService/UserProfileApiClient.cs b/src/AzureDevopsService/AzureDevopsService.Application/AzureDevopsExternalResourceService/ProfileUserService/UserProfileApiClient.cs index fe0c788..1ddb87d 100644 --- a/src/AzureDevopsService/AzureDevopsService.Application/AzureDevopsExternalResourceService/ProfileUserService/UserProfileApiClient.cs +++ b/src/AzureDevopsService/AzureDevopsService.Application/AzureDevopsExternalResourceService/ProfileUserService/UserProfileApiClient.cs @@ -40,7 +40,7 @@ public async Task> GeUserOrgani if (userOrganizationResult.StatusCode == HttpStatusCode.OK) { UserAccount responce = await userOrganizationResult.Content.ReadFromJsonAsync(); - responce.Path = request.Path; + responce!.Path = request.Path; responce.Email = request.Email; return responce; diff --git a/src/AzureDevopsService/AzureDevopsService.Application/AzureDevopsExternalResourceService/WorkItem/WorkItemExternalService.cs b/src/AzureDevopsService/AzureDevopsService.Application/AzureDevopsExternalResourceService/WorkItem/WorkItemExternalService.cs index 1521406..c79a9fd 100644 --- a/src/AzureDevopsService/AzureDevopsService.Application/AzureDevopsExternalResourceService/WorkItem/WorkItemExternalService.cs +++ b/src/AzureDevopsService/AzureDevopsService.Application/AzureDevopsExternalResourceService/WorkItem/WorkItemExternalService.cs @@ -18,7 +18,7 @@ public async Task> GetWorkItemByUse if (workItemResponse.StatusCode == HttpStatusCode.OK) { WiqlResponses? wiqlResponses = await workItemResponse.Content.ReadFromJsonAsync(); - wiqlResponses.Email = wiqlRequest.Email; + wiqlResponses!.Email = wiqlRequest.Email; wiqlResponses.Path = wiqlRequest.Path; return wiqlResponses; } @@ -28,7 +28,7 @@ public async Task> GetWorkItemByUse if (workItemResponse.StatusCode == HttpStatusCode.BadRequest) { WiqlBadRequestResponce wiqlBadResponses = await workItemResponse.Content.ReadFromJsonAsync(); - wiqlBadResponses.Path = wiqlRequest.Path; + wiqlBadResponses!.Path = wiqlRequest.Path; wiqlBadResponses.Email = wiqlRequest.Email; return wiqlBadResponses; diff --git a/src/AzureDevopsService/AzureDevopsService.Application/Featurs/MessageBroker/Producer/ProfileUser/ProfileUserCommandHandler.cs b/src/AzureDevopsService/AzureDevopsService.Application/Featurs/MessageBroker/Producer/ProfileUser/ProfileUserCommandHandler.cs index c38db91..828dc02 100644 --- a/src/AzureDevopsService/AzureDevopsService.Application/Featurs/MessageBroker/Producer/ProfileUser/ProfileUserCommandHandler.cs +++ b/src/AzureDevopsService/AzureDevopsService.Application/Featurs/MessageBroker/Producer/ProfileUser/ProfileUserCommandHandler.cs @@ -18,9 +18,9 @@ public async Task Handle(ProfileUserCommand request, CancellationToken cancellat OneOf organizationResponce = await _userProfileApiClient.GeUserOrganizations( new GetUserOrganizationRequest { - Email = adminInfoResponse!.AsT0!.Email, - MemberId = adminInfoResponse!.AsT0!.Id, - Path = adminInfoResponse!.AsT0!.Path, + Email = adminInfoResponse.AsT0.Email, + MemberId = adminInfoResponse.AsT0.Id, + Path = adminInfoResponse.AsT0.Path, }); adminInfoResponse.AsT0.UserAccount = organizationResponce.AsT0; @@ -31,10 +31,10 @@ public async Task Handle(ProfileUserCommand request, CancellationToken cancellat await endpoint.Send( new CustomProblemDetailsResponce { - Detail = adminInfoResponse!.AsT1!.Detail, - Email = adminInfoResponse!.AsT1!.Email, - Path = adminInfoResponse!.AsT1!.Path, - Status = adminInfoResponse!.AsT1!.Status, + Detail = adminInfoResponse.AsT1.Detail, + Email = adminInfoResponse.AsT1.Email, + Path = adminInfoResponse.AsT1.Path, + Status = adminInfoResponse.AsT1.Status, }, cancellationToken); } diff --git a/src/AzureDevopsService/AzureDevopsService.Application/Featurs/MessageBroker/Producer/ProjectResource/ProjectCommandHandler.cs b/src/AzureDevopsService/AzureDevopsService.Application/Featurs/MessageBroker/Producer/ProjectResource/ProjectCommandHandler.cs index 9bbbdd4..c4138f5 100644 --- a/src/AzureDevopsService/AzureDevopsService.Application/Featurs/MessageBroker/Producer/ProjectResource/ProjectCommandHandler.cs +++ b/src/AzureDevopsService/AzureDevopsService.Application/Featurs/MessageBroker/Producer/ProjectResource/ProjectCommandHandler.cs @@ -12,11 +12,11 @@ public async Task Handle(ProjectCommand request, CancellationToken cancellationT OneOf projectsResponse = await _projectService.AllProjectUnderOrganization(request.Request); if (projectsResponse.IsT0) { - await endpoint.Send(projectsResponse!.AsT0, cancellationToken); + await endpoint.Send(projectsResponse.AsT0, cancellationToken); } else { - await endpoint.Send(projectsResponse!.AsT1, cancellationToken); + await endpoint.Send(projectsResponse.AsT1, cancellationToken); } } } \ No newline at end of file diff --git a/src/AzureDevopsService/AzureDevopsService.Application/Featurs/MessageBroker/Producer/WorkItemResource/WorkItemCommandHandler.cs b/src/AzureDevopsService/AzureDevopsService.Application/Featurs/MessageBroker/Producer/WorkItemResource/WorkItemCommandHandler.cs index 70d55c4..83071bc 100644 --- a/src/AzureDevopsService/AzureDevopsService.Application/Featurs/MessageBroker/Producer/WorkItemResource/WorkItemCommandHandler.cs +++ b/src/AzureDevopsService/AzureDevopsService.Application/Featurs/MessageBroker/Producer/WorkItemResource/WorkItemCommandHandler.cs @@ -13,11 +13,11 @@ public async Task Handle(WorkItemCommand request, CancellationToken cancellation if (workItemResponse.IsT0) { - await endpoint.Send(workItemResponse!.AsT0, cancellationToken); + await endpoint.Send(workItemResponse.AsT0, cancellationToken); } else { - await endpoint.Send(workItemResponse!.AsT1, cancellationToken); + await endpoint.Send(workItemResponse.AsT1, cancellationToken); } } } \ No newline at end of file diff --git a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureDevopsService.Contracts.csproj b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureDevopsService.Contracts.csproj index c54f296..57ad568 100644 --- a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureDevopsService.Contracts.csproj +++ b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureDevopsService.Contracts.csproj @@ -3,7 +3,7 @@ net8.0 enable - 1.0.3 + 1.0.4 enable diff --git a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/AllProjectUnderOrganizationRequest.cs b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/AllProjectUnderOrganizationRequest.cs index 74fa05d..845d238 100644 --- a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/AllProjectUnderOrganizationRequest.cs +++ b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/AllProjectUnderOrganizationRequest.cs @@ -1,7 +1,6 @@ -namespace AzureDevopsService.Contracts.AzureRequestResourceModel +namespace AzureDevopsService.Contracts.AzureRequestResourceModel; + +public class AllProjectUnderOrganizationRequest : BaseRequest { - public class AllProjectUnderOrganizationRequest : BaseRequest - { - public required string OrganizationName { get; set; } - } + public required string OrganizationName { get; set; } } \ No newline at end of file diff --git a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/BaseRequest.cs b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/BaseRequest.cs index b4224de..4088ce5 100644 --- a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/BaseRequest.cs +++ b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/BaseRequest.cs @@ -2,7 +2,7 @@ public class BaseRequest { - public string Email { get; set; } + public string Email { get; set; } = string.Empty; - public string Path { get; set; } + public string Path { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/WiqlRequest.cs b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/WiqlRequest.cs index abf9328..ac2ed5d 100644 --- a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/WiqlRequest.cs +++ b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/WiqlRequest.cs @@ -1,22 +1,21 @@ using AzureDevopsService.Contracts.AzureRequestResourceModel; -namespace AzureDevopsService.Contracts.AzureRequestResourceModel +namespace AzureDevopsService.Contracts.AzureRequestResourceModel; + +public class WiqlRequest : BaseRequest { - public class WiqlRequest : BaseRequest - { - [JsonProperty("query")] - public string Query { get; set; } = string.Empty; + [JsonProperty("query")] + public string Query { get; set; } = string.Empty; - [JsonProperty("organization")] - public string Organization { get; set; } = string.Empty; + [JsonProperty("organization")] + public string Organization { get; set; } = string.Empty; - [JsonProperty("project")] - public string Project { get; set; } = string.Empty; + [JsonProperty("project")] + public string Project { get; set; } = string.Empty; - [JsonProperty("team")] - public string Team { get; set; } = string.Empty; + [JsonProperty("team")] + public string Team { get; set; } = string.Empty; - [JsonProperty("apiVersion")] - public string ApiVersion { get; set; } = string.Empty; - } + [JsonProperty("apiVersion")] + public string ApiVersion { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/WorkItemRequest.cs b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/WorkItemRequest.cs index d0ab0fe..3dea2b4 100644 --- a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/WorkItemRequest.cs +++ b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureRequestResourceModel/WorkItemRequest.cs @@ -1,9 +1,8 @@ -namespace AzureDevopsService.Contracts.AzureRequestResourceModel +namespace AzureDevopsService.Contracts.AzureRequestResourceModel; + +public class WorkItemRequest : BaseRequest { - public class WorkItemRequest : BaseRequest - { - public required string OrganisationName { get; set; } + public required string OrganisationName { get; set; } - public required string ProjectName { get; set; } - } + public required string ProjectName { get; set; } } \ No newline at end of file diff --git a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/AllProjectResponce.cs b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/AllProjectResponce.cs index 2d96187..d64ae35 100644 --- a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/AllProjectResponce.cs +++ b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/AllProjectResponce.cs @@ -1,15 +1,12 @@ -namespace AzureDevopsService.Contracts.AzureResponceModel +using System.Collections; + +namespace AzureDevopsService.Contracts.AzureResponceModel; + +public class AllProjectResponce : BaseRequest { - public class AllProjectResponce : BaseRequest - { - [property: JsonProperty(PropertyName = "count", NullValueHandling = NullValueHandling.Ignore)] - public int? Count { get; set; } + [property: JsonProperty(PropertyName = "count", NullValueHandling = NullValueHandling.Ignore)] + public int Count { get; set; } - [property: JsonProperty(PropertyName = "value", NullValueHandling = NullValueHandling.Ignore)] -#pragma warning disable CA1002 // Do not expose generic lists -#pragma warning disable CA2227 // Collection properties should be read only - public List? Value { get; set; } -#pragma warning restore CA2227 // Collection properties should be read only -#pragma warning restore CA1002 // Do not expose generic lists - } + [property: JsonProperty(PropertyName = "value", NullValueHandling = NullValueHandling.Ignore)] + public IEnumerable Value { get; set; } = Enumerable.Empty(); } \ No newline at end of file diff --git a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/CustomProblemDetailsResponce.cs b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/CustomProblemDetailsResponce.cs index c7c6115..6926798 100644 --- a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/CustomProblemDetailsResponce.cs +++ b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/CustomProblemDetailsResponce.cs @@ -1,9 +1,8 @@ -namespace AzureDevopsService.Contracts.AzureResponceModel +namespace AzureDevopsService.Contracts.AzureResponceModel; + +public class CustomProblemDetailsResponce : ProblemDetails { - public class CustomProblemDetailsResponce : ProblemDetails - { - public string? Email { get; set; } + public string Email { get; set; } = string.Empty; - public string? Path { get; set; } - } + public string Path { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/Project.cs b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/Project.cs index f67b99c..a355fb7 100644 --- a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/Project.cs +++ b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/Project.cs @@ -1,26 +1,25 @@ -namespace AzureDevopsService.Contracts.AzureResponceModel +namespace AzureDevopsService.Contracts.AzureResponceModel; + +public class Project { - public class Project - { - [JsonProperty("id")] - public Guid Id { get; set; } + [JsonProperty("id")] + public Guid Id { get; set; } - [JsonProperty("name")] - public string? Name { get; set; } + [JsonProperty("name")] + public string Name { get; set; } = string.Empty; - [JsonProperty("url")] - public Uri? Url { get; set; } + [JsonProperty("url")] + public Uri? Url { get; set; } - [JsonProperty("state")] - public string? State { get; set; } + [JsonProperty("state")] + public string State { get; set; } = string.Empty; - [JsonProperty("revision")] - public int Revision { get; set; } + [JsonProperty("revision")] + public int Revision { get; set; } - [JsonProperty("visibility")] - public string? Visibility { get; set; } + [JsonProperty("visibility")] + public string Visibility { get; set; } = string.Empty; - [JsonProperty("lastUpdateTime")] - public DateTime LastUpdateTime { get; set; } - } + [JsonProperty("lastUpdateTime")] + public DateTime LastUpdateTime { get; set; } } \ No newline at end of file diff --git a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/UserAccount.cs b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/UserAccount.cs index ad7fe34..2367f51 100644 --- a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/UserAccount.cs +++ b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/UserAccount.cs @@ -1,15 +1,10 @@ -namespace AzureDevopsService.Contracts.AzureResponceModel +namespace AzureDevopsService.Contracts.AzureResponceModel; + +public class UserAccount : BaseRequest { - public class UserAccount : BaseRequest - { - [property: JsonProperty(PropertyName = "count", NullValueHandling = NullValueHandling.Ignore)] - public int? Count { get; set; } + [property: JsonProperty(PropertyName = "count", NullValueHandling = NullValueHandling.Ignore)] + public int Count { get; set; } - [property: JsonProperty(PropertyName = "value", NullValueHandling = NullValueHandling.Ignore)] -#pragma warning disable CA1002 // Do not expose generic lists -#pragma warning disable CA2227 // Collection properties should be read only - public List? Value { get; set; } -#pragma warning restore CA2227 // Collection properties should be read only -#pragma warning restore CA1002 // Do not expose generic lists - } + [property: JsonProperty(PropertyName = "value", NullValueHandling = NullValueHandling.Ignore)] + public IEnumerable Value { get; set; } = Enumerable.Empty(); } \ No newline at end of file diff --git a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/UserOrganization.cs b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/UserOrganization.cs index b5e43b6..1be17cb 100644 --- a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/UserOrganization.cs +++ b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/UserOrganization.cs @@ -3,11 +3,11 @@ public class UserOrganization { [JsonProperty("accountId")] - public string? AccountId { get; set; } + public string AccountId { get; set; } = string.Empty; [JsonProperty("accountUri")] - public Uri? AccountUri { get; set; } + public Uri? AccountUri { get; set; }; [JsonProperty("accountName")] - public string? AccountName { get; set; } + public string AccountName { get; set; } = string.Empty; } \ No newline at end of file diff --git a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/UserProfile.cs b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/UserProfile.cs index 192f736..7d01c4d 100644 --- a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/UserProfile.cs +++ b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/UserProfile.cs @@ -3,13 +3,13 @@ public class UserProfile : BaseRequest { [JsonProperty("displayName")] - public string? DisplayName { get; set; } + public string DisplayName { get; set; } = string.Empty; [JsonProperty("publicAlias")] - public string? PublicAlias { get; set; } + public string PublicAlias { get; set; } = string.Empty; [JsonProperty("emailAddress")] - public string? EmailAddress { get; set; } + public string EmailAddress { get; set; } = string.Empty; [JsonProperty("coreRevision")] public int CoreRevision { get; set; } @@ -18,11 +18,11 @@ public class UserProfile : BaseRequest public DateTime TimeStamp { get; set; } [JsonProperty("id")] - public string? Id { get; set; } + public string Id { get; set; } = string.Empty; [JsonProperty("revision")] public int Revision { get; set; } [JsonProperty("UserAccount")] - public UserAccount? UserAccount { get; set; } + public UserAccount? UserAccount { get; set; }; } \ No newline at end of file diff --git a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/WiqlBadRequestResponce.cs b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/WiqlBadRequestResponce.cs index 77e8ec9..e808c1e 100644 --- a/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/WiqlBadRequestResponce.cs +++ b/src/AzureDevopsService/AzureDevopsService.Contracts/AzureResponceModel/WiqlBadRequestResponce.cs @@ -6,20 +6,20 @@ public class WiqlBadRequestResponce : BaseRequest public string? Id { get; set; } = string.Empty; [JsonProperty("innerException")] - public string? InnerException { get; set; } = string.Empty; + public string InnerException { get; set; } = string.Empty; [JsonProperty("message")] - public string? Message { get; set; } = string.Empty; + public string Message { get; set; } = string.Empty; [JsonProperty("typeName")] - public string? TypeName { get; set; } = string.Empty; + public string TypeName { get; set; } = string.Empty; [JsonProperty("typeKey")] - public string? TypeKey { get; set; } = string.Empty; + public string TypeKey { get; set; } = string.Empty; [JsonProperty("errorCode")] - public int? ErrorCode { get; set; } + public int ErrorCode { get; set; } [JsonProperty("eventId")] - public int? EventId { get; set; } + public int EventId { get; set; } } \ No newline at end of file diff --git a/src/TimeLogService/TimeLogService.Application/Feature/MessageBroker/Consumer/ProfileUser/ProfileUserConsumer.cs b/src/TimeLogService/TimeLogService.Application/Feature/MessageBroker/Consumer/ProfileUser/ProfileUserConsumer.cs index a5b9337..2efcd14 100644 --- a/src/TimeLogService/TimeLogService.Application/Feature/MessageBroker/Consumer/ProfileUser/ProfileUserConsumer.cs +++ b/src/TimeLogService/TimeLogService.Application/Feature/MessageBroker/Consumer/ProfileUser/ProfileUserConsumer.cs @@ -1,9 +1,4 @@ -using System.Collections.Generic; -using TimeLogService.Application.Feature.OrganizationAction.Commands.AddOrganization; -using TimeLogService.Application.Feature.OrganizationAction.Commands.AddOrganizationList; -using TimeLogService.Application.Feature.UserAction.Commands.AddUser; - -namespace TimeLogService.Application.Feature.MessageBroker.Consumer.ProfileUser; +namespace TimeLogService.Application.Feature.MessageBroker.Consumer.ProfileUser; public class ProfileUserConsumer(ILogger logger, IMediator mediator, IRepository repository, IRepository repositoryOrganization) : IConsumer, IConsumer { @@ -19,37 +14,38 @@ public async Task Consume(ConsumeContext context) if (user is null) { await _mediator.Send(new AddUserCommand(context.Message)); + } - if (context.Message.UserAccount.Count > 0) - { - IReadOnlyList organizationList = await _repositoryOrganization.GetManyAsync(x => x.UserId == context.Message!.Id); + if (context.Message.UserAccount is not null and context.Message.UserAccount!.Count > 0) + { + IReadOnlyList organizationList = await _repositoryOrganization.GetManyAsync(x => x.UserId == context.Message!.Id); - var existingAccountIds = new HashSet(organizationList.Select(x => x.AccountId)); + var existingAccountIds = new HashSet(organizationList.Select(x => x.AccountId)); - List organizations = new List(); + List organizations = new List(); - foreach (UserOrganization org in context.Message.UserAccount!.Value) + foreach (UserOrganization org in context.Message.UserAccount!.Value) + { + if (!existingAccountIds.Contains(org.AccountId)) { - if (!existingAccountIds.Contains(org.AccountId)) + organizations.Add(new Organization { - organizations.Add(new Organization - { - AccountId = org.AccountId, - AccountUri = org.AccountUri.ToString(), - Name = org.AccountName, - UserId = context.Message.Id, - IsAionTimeApproved = false, - }); - } + AccountId = org.AccountId, + AccountUri = org.AccountUri.ToString(), + Name = org.AccountName, + UserId = context.Message.Id, + IsAionTimeApproved = false, + }); } + } - if (organizations.Count > 0) - { - await _mediator.Send(new AddOrganizationListCommand(organizations)); - } + if (organizations.Count > 0) + { + await _mediator.Send(new AddOrganizationListCommand(organizations)); } } + _logger.LogInformation(JsonConvert.SerializeObject(context.Message)); } diff --git a/src/TimeLogService/TimeLogService.Application/GlobalUsings.cs b/src/TimeLogService/TimeLogService.Application/GlobalUsings.cs index 2797a78..be08d3c 100644 --- a/src/TimeLogService/TimeLogService.Application/GlobalUsings.cs +++ b/src/TimeLogService/TimeLogService.Application/GlobalUsings.cs @@ -8,6 +8,7 @@ global using Microsoft.Extensions.Logging; global using Microsoft.Extensions.Options; global using Newtonsoft.Json; +global using System.Collections.Generic; global using System.Reflection; global using TimeLogService; global using TimeLogService.Application; @@ -15,14 +16,17 @@ global using TimeLogService.Application.Feature.MessageBroker.Consumer.Project; global using TimeLogService.Application.Feature.MessageBroker.Consumer.WebhookConsumer; global using TimeLogService.Application.Feature.MessageBroker.Consumer.WorkItem; +global using TimeLogService.Application.Feature.OrganizationAction.Commands.AddOrganization; +global using TimeLogService.Application.Feature.OrganizationAction.Commands.AddOrganizationList; +global using TimeLogService.Application.Feature.UserAction.Commands.AddUser; global using TimeLogService.Contracts.DTOs.Request; global using TimeLogService.Contracts.Settings; global using TimeLogService.Domain.Interfaces.Repositories; +global using TimeLogService.Domain.Models; global using TimeLogService.Domain.Models.Dbo; global using WebhookService.Contracts; global using WebhookService.Contracts.EventModels.SharedModels; global using WebhookService.Contracts.EventModels.SharedModels.ResourcesModels; global using static MassTransit.Logging.OperationName; global using static Org.BouncyCastle.Math.EC.ECCurve; -global using RabbitMqSettings = TimeLogService.Contracts.Settings.RabbitMqSettings; -global using TimeLogService.Domain.Models; \ No newline at end of file +global using RabbitMqSettings = TimeLogService.Contracts.Settings.RabbitMqSettings; \ No newline at end of file diff --git a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/AionTimeSubscriptionConfiguration.cs b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/AionTimeSubscriptionConfiguration.cs index 0f78b5f..c29b41c 100644 --- a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/AionTimeSubscriptionConfiguration.cs +++ b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/AionTimeSubscriptionConfiguration.cs @@ -4,12 +4,12 @@ public partial class AionTimeSubscriptionConfiguration : IEntityTypeConfiguratio { public void Configure(EntityTypeBuilder entity) { - entity.ToTable("AionTimeSubscription"); + _ = entity.ToTable("AionTimeSubscription"); - entity.Property(e => e.ExpirationDate).HasColumnType("datetime"); - entity.Property(e => e.SubsecriptionDate).HasColumnType("datetime"); + _ = entity.Property(e => e.ExpirationDate).HasColumnType("datetime"); + _ = entity.Property(e => e.SubsecriptionDate).HasColumnType("datetime"); - entity.HasOne(d => d.Organization).WithMany(p => p.AionTimeSubscriptions) + _ = entity.HasOne(d => d.Organization).WithMany(p => p.AionTimeSubscriptions) .HasForeignKey(d => d.OrganizationId) .HasConstraintName("FKOrganizationSubscription"); diff --git a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/AionTimeSubscriptionHistoryConfiguration.cs b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/AionTimeSubscriptionHistoryConfiguration.cs index 8884902..0f84a0c 100644 --- a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/AionTimeSubscriptionHistoryConfiguration.cs +++ b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/AionTimeSubscriptionHistoryConfiguration.cs @@ -4,12 +4,12 @@ public partial class AionTimeSubscriptionHistoryConfiguration : IEntityTypeConfi { public void Configure(EntityTypeBuilder entity) { - entity.ToTable("AionTimeSubscriptionHistory"); + _ = entity.ToTable("AionTimeSubscriptionHistory"); - entity.Property(e => e.Id).ValueGeneratedNever(); - entity.Property(e => e.SubscriptionDate).HasColumnType("date"); + _ = entity.Property(e => e.Id).ValueGeneratedNever(); + _ = entity.Property(e => e.SubscriptionDate).HasColumnType("date"); - entity.HasOne(d => d.Subscription).WithMany(p => p.AionTimeSubscriptionHistories) + _ = entity.HasOne(d => d.Subscription).WithMany(p => p.AionTimeSubscriptionHistories) .HasForeignKey(d => d.SubscriptionId) .HasConstraintName("FKSubscriptionSubscriptionHistory"); diff --git a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/OrganizationConfiguration.cs b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/OrganizationConfiguration.cs index e258bdd..f7297e0 100644 --- a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/OrganizationConfiguration.cs +++ b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/OrganizationConfiguration.cs @@ -4,22 +4,22 @@ public partial class OrganizationConfiguration : IEntityTypeConfiguration entity) { - entity.ToTable("Organization"); + _ = entity.ToTable("Organization"); - entity.HasIndex(e => e.AccountId, "IX_Organization_AccountId").IsUnique(); + _ = entity.HasIndex(e => e.AccountId, "IX_Organization_AccountId").IsUnique(); - entity.HasIndex(e => e.Name, "IX_Organization_Name_Unique").IsUnique(); + _ = entity.HasIndex(e => e.Name, "IX_Organization_Name_Unique").IsUnique(); - entity.Property(e => e.AccountId).HasMaxLength(100); - entity.Property(e => e.AccountUri) + _ = entity.Property(e => e.AccountId).HasMaxLength(100); + _ = entity.Property(e => e.AccountUri) .HasMaxLength(200) .IsUnicode(false); - entity.Property(e => e.Name) + _ = entity.Property(e => e.Name) .HasMaxLength(255) .IsUnicode(false); - entity.Property(e => e.UserId).HasMaxLength(100); + _ = entity.Property(e => e.UserId).HasMaxLength(100); - entity.HasOne(d => d.User).WithMany(p => p.Organizations) + _ = entity.HasOne(d => d.User).WithMany(p => p.Organizations) .HasPrincipalKey(p => p.UserId) .HasForeignKey(d => d.UserId) .HasConstraintName("FKUserOrganization"); diff --git a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/ProjectConfiguration.cs b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/ProjectConfiguration.cs index a7c0cc9..22698a7 100644 --- a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/ProjectConfiguration.cs +++ b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/ProjectConfiguration.cs @@ -4,23 +4,23 @@ public partial class ProjectConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder entity) { - entity.ToTable("Project"); + _ = entity.ToTable("Project"); - entity.HasIndex(e => e.ProjectId, "IX_Project_ProjectId").IsUnique(); + _ = entity.HasIndex(e => e.ProjectId, "IX_Project_ProjectId").IsUnique(); - entity.Property(e => e.LastUpdateTime).HasColumnType("datetime"); - entity.Property(e => e.Name) + _ = entity.Property(e => e.LastUpdateTime).HasColumnType("datetime"); + _ = entity.Property(e => e.Name) .HasMaxLength(50) .IsUnicode(false); - entity.Property(e => e.ProjectId).HasMaxLength(100); - entity.Property(e => e.Url) + _ = entity.Property(e => e.ProjectId).HasMaxLength(100); + _ = entity.Property(e => e.Url) .HasMaxLength(200) .IsUnicode(false); - entity.Property(e => e.Visibility) + _ = entity.Property(e => e.Visibility) .HasMaxLength(50) .IsUnicode(false); - entity.HasOne(d => d.Organization).WithMany(p => p.Projects) + _ = entity.HasOne(d => d.Organization).WithMany(p => p.Projects) .HasForeignKey(d => d.OrganizationId) .HasConstraintName("FKOrganisationProject"); diff --git a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/UserConfiguration.cs b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/UserConfiguration.cs index 49266ce..3eaf1e7 100644 --- a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/UserConfiguration.cs +++ b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/UserConfiguration.cs @@ -4,16 +4,16 @@ public partial class UserConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder entity) { - entity.ToTable("User"); + _ = entity.ToTable("User"); - entity.HasIndex(e => e.UserId, "IX_User_UserId").IsUnique(); + _ = entity.HasIndex(e => e.UserId, "IX_User_UserId").IsUnique(); - entity.Property(e => e.EmailAddress) + _ = entity.Property(e => e.EmailAddress) .HasMaxLength(50) .IsUnicode(false); - entity.Property(e => e.PublicAlias).HasMaxLength(100); - entity.Property(e => e.TimeStamp).HasColumnType("datetime"); - entity.Property(e => e.UserId).HasMaxLength(100); + _ = entity.Property(e => e.PublicAlias).HasMaxLength(100); + _ = entity.Property(e => e.TimeStamp).HasColumnType("datetime"); + _ = entity.Property(e => e.UserId).HasMaxLength(100); OnConfigurePartial(entity); } diff --git a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/WorkItemConfiguration.cs b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/WorkItemConfiguration.cs index 5bef4c3..b140f41 100644 --- a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/WorkItemConfiguration.cs +++ b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/WorkItemConfiguration.cs @@ -4,13 +4,13 @@ public partial class WorkItemConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder entity) { - entity.ToTable("WorkItem"); + _ = entity.ToTable("WorkItem"); - entity.Property(e => e.Discription) + _ = entity.Property(e => e.Discription) .HasMaxLength(1000) .IsUnicode(false); - entity.HasOne(d => d.Project).WithMany(p => p.WorkItems) + _ = entity.HasOne(d => d.Project).WithMany(p => p.WorkItems) .HasForeignKey(d => d.ProjectId) .HasConstraintName("FKProjectTicket"); diff --git a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/WorkItemHistoryConfiguration.cs b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/WorkItemHistoryConfiguration.cs index 5ccfbd9..4961dbe 100644 --- a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/WorkItemHistoryConfiguration.cs +++ b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/WorkItemHistoryConfiguration.cs @@ -4,13 +4,13 @@ public partial class WorkItemHistoryConfiguration : IEntityTypeConfiguration entity) { - entity.ToTable("WorkItemHistory"); + _ = entity.ToTable("WorkItemHistory"); - entity.Property(e => e.History) + _ = entity.Property(e => e.History) .HasMaxLength(1000) .IsUnicode(false); - entity.HasOne(d => d.WorkItem).WithMany(p => p.WorkItemHistories) + _ = entity.HasOne(d => d.WorkItem).WithMany(p => p.WorkItemHistories) .HasForeignKey(d => d.WorkItemId) .HasConstraintName("FKTicketHistory"); diff --git a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/WorkItemTimeLogConfiguration.cs b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/WorkItemTimeLogConfiguration.cs index 0a8e40e..754fd51 100644 --- a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/WorkItemTimeLogConfiguration.cs +++ b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/Configurations/WorkItemTimeLogConfiguration.cs @@ -2,20 +2,20 @@ { public partial class WorkItemTimeLogConfiguration : IEntityTypeConfiguration { - public void Configure(EntityTypeBuilder entity) + public void Configure(EntityTypeBuilder builder) { - entity.ToTable("WorkItemTimeLog"); + _ = builder.ToTable("WorkItemTimeLog"); - entity.Property(e => e.Description) + _ = builder.Property(e => e.Description) .HasMaxLength(200) .IsUnicode(false); - entity.Property(e => e.Time).HasColumnType("datetime"); + _ = builder.Property(e => e.Time).HasColumnType("datetime"); - entity.HasOne(d => d.WorkItem).WithMany(p => p.WorkItemTimeLogs) + _ = builder.HasOne(d => d.WorkItem).WithMany(p => p.WorkItemTimeLogs) .HasForeignKey(d => d.WorkItemId) .HasConstraintName("FKProjectTicketLog"); - OnConfigurePartial(entity); + OnConfigurePartial(builder); } partial void OnConfigurePartial(EntityTypeBuilder entity); diff --git a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/TimeLogServiceDataBaseContext.cs b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/TimeLogServiceDataBaseContext.cs index 6b113a4..1cafe01 100644 --- a/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/TimeLogServiceDataBaseContext.cs +++ b/src/TimeLogService/TimeLogService.Infrastructure/AionTimeContext/TimeLogServiceDataBaseContext.cs @@ -1,12 +1,7 @@ using TimeLogService.Infrastructure.AionTimeContext.Configurations; -public partial class TimeLogServiceDataBaseContext : DbContext +public partial class TimeLogServiceDataBaseContext(DbContextOptions options) : DbContext(options) { - public TimeLogServiceDataBaseContext(DbContextOptions options) - : base(options) - { - } - public virtual DbSet AionTimeSubscriptions { get; set; } public virtual DbSet AionTimeSubscriptionHistories { get; set; } @@ -25,14 +20,14 @@ public TimeLogServiceDataBaseContext(DbContextOptions