Skip to content

Commit

Permalink
fix code rules in time log and azure services
Browse files Browse the repository at this point in the history
  • Loading branch information
Nieze-BenMansour committed Dec 6, 2024
1 parent 79fb99f commit 35ef2ee
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

public class ProfileUserCommandHandler(
IUserProfileApiClient userProfileApiClient,
ISendEndpointProvider sendEndpointProvider,
IPublishEndpoint publishEndpoint) :
IRequestHandler<ProfileUserCommand>
{
private readonly IUserProfileApiClient _userProfileApiClient = userProfileApiClient;
private readonly ISendEndpointProvider _sendEndpointProvider = sendEndpointProvider;
private readonly IPublishEndpoint _publishEndpoint = publishEndpoint;

public async Task Handle(ProfileUserCommand request, CancellationToken cancellationToken)
{
ISendEndpoint endpoint = await _sendEndpointProvider.GetSendEndpoint(new Uri("rabbitmq://rabbitmq/ProfileUserResponce"));

OneOf<UserProfile, CustomProblemDetailsResponce> adminInfoResponse = await _userProfileApiClient.GetAdminInfo(request.BaseRequest);
// ISendEndpoint endpoint = await _sendEndpointProvider.GetSendEndpoint(new Uri("rabbitmq://rabbitmq/ProfileUserResponce"));
OneOf<UserProfile, CustomProblemDetailsResponce> adminInfoResponse =
await _userProfileApiClient.GetAdminInfo(request.BaseRequest);
if (adminInfoResponse.IsT0)
{
OneOf<UserAccount, CustomProblemDetailsResponce> organizationResponce = await _userProfileApiClient.GeUserOrganizations(
OneOf<UserAccount, CustomProblemDetailsResponce> organizationResponce =
await _userProfileApiClient.GeUserOrganizations(
new GetUserOrganizationRequest
{
Email = adminInfoResponse.AsT0.Email,
Expand All @@ -30,17 +29,5 @@ public async Task Handle(ProfileUserCommand request, CancellationToken cancellat
// await endpoint.Send(adminInfoResponse.AsT0, cancellationToken);
await _publishEndpoint.Publish(adminInfoResponse.AsT0);
}
else
{
//await endpoint.Send(
// new CustomProblemDetailsResponce
// {
// Detail = adminInfoResponse.AsT1.Detail,
// Email = adminInfoResponse.AsT1.Email,
// Path = adminInfoResponse.AsT1.Path,
// Status = adminInfoResponse.AsT1.Status,
// },
// cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ public static void AddEndpoints(this IEndpointRouteBuilder app)
return Results.Ok(userResponse);
});

_ = app.MapPost("/Login", async (IMediator _mediator, [FromBody] LoginCommand request) =>
_ = app.MapPost("/Login", async (
IMediator mediator,
[FromBody] LoginCommand request,
CancellationToken cancellationToken) =>
{
ApiResponse<LoginResponse> userResponse = await _mediator.Send(request);
ApiResponse<LoginResponse> userResponse = await mediator.Send(request, cancellationToken);
if (!userResponse.Succeeded)
{
return Results.BadRequest(userResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using MassTransit;
using MassTransit.Transports;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
namespace IdentityService.Application.Features.CreateAccount;

public class CreateAccountCommandHandler(UserManager<ApplicationUser> userManager, IMediator mediator)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
namespace TimeLogService.Application.Feature.MessageBroker.Consumer.ProfileUser;

public class ProfileUserConsumer(ILogger<ProfileUserConsumer> logger, IMediator mediator, IRepository<User> repository, IRepository<Organization> repositoryOrganization) : IConsumer<UserProfile>, IConsumer<CustomProblemDetailsResponce>
public class ProfileUserConsumer(
ILogger<ProfileUserConsumer> logger,
IMediator mediator,
IRepository<User> repository,
IRepository<Organization> repositoryOrganization)
: IConsumer<UserProfile>, IConsumer<CustomProblemDetailsResponce>
{
private readonly ILogger<ProfileUserConsumer> _logger = logger;
private readonly IMediator _mediator = mediator;
Expand All @@ -9,29 +14,31 @@ public class ProfileUserConsumer(ILogger<ProfileUserConsumer> logger, IMediator

public async Task Consume(ConsumeContext<UserProfile> context)
{
User user = await _repository.GetSingleAsync(x => x.UserId == context.Message!.Id);
User? user = await _repository.GetSingleAsync(x => x.UserId == context.Message!.Id);

if (user is null)
{
await _mediator.Send(new AddUserCommand(context.Message));
}

if (context.Message.UserAccount is not null && context.Message.UserAccount!.Count > 0)
if (context.Message.UserAccount is not null && context.Message.UserAccount.Count > 0)
{
IReadOnlyList<Organization> organizationList = await _repositoryOrganization.GetManyAsync(x => x.UserId == context.Message!.Id);
IReadOnlyList<Organization> organizationList = await _repositoryOrganization
.GetManyAsync(x => x.UserId == context.Message!.Id);

HashSet<string> existingAccountIds = new(organizationList.Select(x => x.AccountId));
HashSet<string> existingAccountIds = [.. organizationList.Select(x => x.AccountId)];

List<Organization> organizations = [];

foreach (UserOrganization org in context.Message.UserAccount!.Value)
{
if (!existingAccountIds.Contains(org.AccountId))
if (!existingAccountIds.Contains(org.AccountId)
&& org.AccountUri is not null)
{
organizations.Add(new Organization
{
AccountId = org!.AccountId,
AccountUri = org!.AccountUri!.ToString(),
AccountUri = org.AccountUri,
Name = org.AccountName,
UserId = context.Message!.Id,
IsAionTimeApproved = false,
Expand All @@ -48,12 +55,9 @@ public async Task Consume(ConsumeContext<UserProfile> context)
_logger.LogInformation(JsonConvert.SerializeObject(context.Message));
}

#pragma warning disable format
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public async Task Consume(ConsumeContext<CustomProblemDetailsResponce> context)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
#pragma warning restore format
{
await Task.Delay(1);
_logger.LogInformation(JsonConvert.SerializeObject(context.Message));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public partial class AionTimeSubscription : BaseEntity

public int OrganizationId { get; set; }

public virtual ICollection<AionTimeSubscriptionHistory>? AionTimeSubscriptionHistories { get; set; } // = new List<AionTimeSubscriptionHistory>();
public virtual ICollection<AionTimeSubscriptionHistory>? AionTimeSubscriptionHistories { get; private set; }

public virtual Organization? Organization { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ public partial class Organization : BaseEntity

public string AccountId { get; set; } = null!;

public string AccountUri { get; set; } = null!;
public required Uri AccountUri { get; set; }

public bool IsAionTimeApproved { get; set; }

public virtual ICollection<AionTimeSubscription>? AionTimeSubscriptions { get; set; }
public virtual ICollection<AionTimeSubscription>? AionTimeSubscriptions { get; private set; }

public virtual ICollection<Project>? Projects { get; set; }
public virtual ICollection<Project>? Projects { get; private set; }

public virtual User? User { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public partial class Project : BaseEntity

public DateTime? LastUpdateTime { get; set; }

public string Url { get; set; } = null!;
public required Uri Url { get; set; }

public virtual Organization? Organization { get; set; }

public virtual ICollection<WorkItem>? WorkItems { get; set; } // = new List<WorkItem>();
public virtual ICollection<WorkItem>? WorkItems { get; private set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ public partial class User : BaseEntity

public int Revision { get; set; }

public virtual ICollection<Organization>? Organizations { get; set; } // = new List<Organization>();
public virtual ICollection<Organization>? Organizations { get; private set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class WorkItem : BaseEntity

public virtual Project? Project { get; set; }

public virtual ICollection<WorkItemHistory>? WorkItemHistories { get; set; } // = new List<WorkItemHistory>();
public virtual ICollection<WorkItemHistory>? WorkItemHistories { get; private set; }

public virtual ICollection<WorkItemTimeLog>? WorkItemTimeLogs { get; set; } // = new List<WorkItemTimeLog>();
public virtual ICollection<WorkItemTimeLog>? WorkItemTimeLogs { get; private set; }
}

0 comments on commit 35ef2ee

Please sign in to comment.