Skip to content

Commit

Permalink
Merge pull request #52 from TunNetCom/ProfileUser
Browse files Browse the repository at this point in the history
Add profile user consumer
  • Loading branch information
Nieze-BenMansour authored Sep 9, 2024
2 parents fd8e5d8 + f892b69 commit efb710c
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public static IServiceCollection AddApplicationService(this IServiceCollection s
{
x.SetDefaultEndpointNameFormatter();
_ = x.AddConsumer<ProfileUserConsumer>();
x.SetDefaultEndpointNameFormatter();

x.UsingRabbitMq((context, cfg) =>
{
Expand All @@ -27,8 +28,6 @@ public static IServiceCollection AddApplicationService(this IServiceCollection s
e.SetQueueArgument("x-message-ttl", 60000);
e.ConfigureConsumer<ProfileUserConsumer>(context);
});

cfg.ConfigureEndpoints(context, new DefaultEndpointNameFormatter("dev", false));
});
});
_ = services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(Assembly.GetExecutingAssembly()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace AzureDevopsService.Application.Featurs.MessageBroker.Producer.ProfileUser;

public record class ProfileUserCommend(BaseRequest BaseRequest) : IRequest<OneOf<UserAccount?, CustomProblemDetailsResponce?>>;
public record class ProfileUserCommend(BaseRequest BaseRequest) : IRequest;
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
using MediatR;
using MassTransit;
using MediatR;

namespace AzureDevopsService.Application.Featurs.MessageBroker.Producer.ProfileUser;

public class ProfileUserCommendHandler(IUserProfileApiClient userProfileApiClient) :
IRequestHandler<ProfileUserCommend, OneOf<UserAccount?, CustomProblemDetailsResponce?>>
public class ProfileUserCommendHandler(IUserProfileApiClient userProfileApiClient, ISendEndpointProvider sendEndpointProvider) :
IRequestHandler<ProfileUserCommend>
{
private readonly IUserProfileApiClient _userProfileApiClient = userProfileApiClient;

public async Task<OneOf<UserAccount?, CustomProblemDetailsResponce?>> Handle(ProfileUserCommend request, CancellationToken cancellationToken)
private readonly ISendEndpointProvider _sendEndpointProvider = sendEndpointProvider;

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

OneOf<UserProfile?, CustomProblemDetailsResponce?> result = await _userProfileApiClient.GetAdminInfo(request.BaseRequest);
if (result.IsT0)
{
Expand All @@ -21,22 +26,28 @@ public class ProfileUserCommendHandler(IUserProfileApiClient userProfileApiClien
MemberId = result.AsT0.Id,
Path = result.AsT0.Path,
});
#pragma warning disable CS8634 // The type cannot be used as type parameter in the generic type or method. Nullability of type argument doesn't match 'class' constraint.
await endpoint.Send(res.AsT0, cancellationToken);
#pragma warning restore CS8634 // The type cannot be used as type parameter in the generic type or method. Nullability of type argument doesn't match 'class' constraint.

#pragma warning restore CS8601 // Possible null reference assignment.
#pragma warning restore CS8602 // Dereference of a possibly null reference.

return res;
}

else
{
#pragma warning disable CS8602 // Dereference of a possibly null reference.
#pragma warning disable CS8601 // Possible null reference assignment.
return new CustomProblemDetailsResponce
{
Detail = result.AsT1.Detail,
Email = result.AsT1.Email,
Path = result.AsT1.Path,
Status = result.AsT1.Status,
};
await endpoint.Send(
new CustomProblemDetailsResponce
{
Detail = result.AsT1.Detail,
Email = result.AsT1.Email,
Path = result.AsT1.Path,
Status = result.AsT1.Status,
},
cancellationToken);
#pragma warning restore CS8601 // Possible null reference assignment.
#pragma warning restore CS8602 // Dereference of a possibly null reference.
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using AzureDevopsService.Contracts.AzureRequestResourceModel;
using TimeLogService;
using TimeLogService.API;
using TimeLogService.API.Controllers;
Expand All @@ -6,9 +7,8 @@
using TimeLogService.Application.Feature.OrganizationAction.Commands.UpdateOrganization;
using TimeLogService.Application.Feature.OrganizationAction.Queries.GetOrganization;
using TimeLogService.Application.Feature.OrganizationAction.Queries.GetOrganizationById;
using TimeLogService.Application.Feature.RabbitMqConsumer.Producer.ProfileUser;
using TimeLogService.Contracts.DTOs.Request;
using TunNetCom;
using TunNetCom.AionTime;

namespace TimeLogService.API.Controllers;

Expand All @@ -25,6 +25,14 @@ public async Task<IActionResult> CreateOrganization(OrganizationRequest organiza
return Ok(await _mediator.Send(new AddOrganizationCommand(organization)));
}

[HttpPost]
[Route("ProfileUser")]
public async Task<IActionResult> CreateOrganization(BaseRequest BaseRequest)
{
await _mediator.Send(new ProfileUserCommend(BaseRequest));
return Ok();
}

[HttpPost]
[Route("UpdateOrganization")]
public async Task<IActionResult> UpdateOrganization(OrganizationRequest organization)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using TimeLogService;
using TimeLogService.API;
using TimeLogService.API;
using TunNetCom;
using TunNetCom.AionTime;

namespace TimeLogService.API;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using TimeLogService.API;
using TimeLogService.API.Middelware;
using TimeLogService.API.Middelware;
using TunNetCom;
using TunNetCom.AionTime;

namespace TimeLogService.API.Middelware;

Expand Down
1 change: 0 additions & 1 deletion src/TimeLogService/TimeLogService.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using TimeLogService.API;
using TimeLogService.API.Middelware;
using TimeLogService.Application;
using TimeLogService.Application.Feature.RabbitMqConsumer.WebhookConsumer;
using TimeLogService.Contracts.Settings;
using TimeLogService.Infrastructure;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace TimeLogService.Application
using TimeLogService.Application.Feature.RabbitMqConsumer.Consumer.ProfileUser;
using TimeLogService.Application.Feature.RabbitMqConsumer.Consumer.WebhookConsumer;

namespace TimeLogService.Application
{
public static class ApplicationServiceRegistration
{
Expand All @@ -13,6 +16,7 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection
_ = x.AddConsumer<PipelineEventConsumer>();
_ = x.AddConsumer<BuildAndReleasEventsConsumer>();
_ = x.AddConsumer<CodeEventsConsumer>();
_ = x.AddConsumer<ProfileUserConsumer>();
x.SetDefaultEndpointNameFormatter();
x.UsingRabbitMq((context, config) =>
{
Expand Down Expand Up @@ -43,6 +47,11 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection
e.SetQueueArgument("x-message-ttl", 60000);
e.ConfigureConsumer<CodeEventsConsumer>(context);
});
config.ReceiveEndpoint("ProfileUserResponce", e =>
{
e.SetQueueArgument("x-message-ttl", 60000);
e.ConfigureConsumer<ProfileUserConsumer>(context);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using AzureDevopsService.Contracts.AzureResponceModel;
using OneOf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TimeLogService.Application.Feature.RabbitMqConsumer.Consumer.ProfileUser
{
public class ProfileUserConsumer : IConsumer<UserAccount>, IConsumer<CustomProblemDetailsResponce>
{
#pragma warning disable format
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public async Task Consume(ConsumeContext<UserAccount> context)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
#pragma warning restore format
{
string jsonMessage = JsonConvert.SerializeObject(context.Message);
Console.WriteLine($"AzureWebhookModelEvent message: {jsonMessage}");
}

#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
{
string jsonMessage = JsonConvert.SerializeObject(context.Message);
Console.WriteLine($"AzureWebhookModelEvent message: {jsonMessage}");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
namespace TimeLogService.Application.Feature.RabbitMqConsumer.WebhookConsumer;
using TimeLogService;
using TimeLogService.Application;
using TimeLogService.Application.Feature;
using TimeLogService.Application.Feature.RabbitMqConsumer;
using TimeLogService.Application.Feature.RabbitMqConsumer.Consumer.WebhookConsumer;

namespace TimeLogService.Application.Feature.RabbitMqConsumer.Consumer.WebhookConsumer;

public class BuildAndReleasEventsConsumer : IConsumer<AzureWebhookModelEvent<BuildAndReleaseResource>>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
namespace TimeLogService.Application.Feature.RabbitMqConsumer.WebhookConsumer;
using TimeLogService;
using TimeLogService.Application;
using TimeLogService.Application.Feature;
using TimeLogService.Application.Feature.RabbitMqConsumer;
using TimeLogService.Application.Feature.RabbitMqConsumer.Consumer.WebhookConsumer;

namespace TimeLogService.Application.Feature.RabbitMqConsumer.Consumer.WebhookConsumer;

public class CodeEventsConsumer : IConsumer<AzureWebhookModelEvent<CodeResource>>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
namespace TimeLogService.Application.Feature.RabbitMqConsumer.WebhookConsumer
using TimeLogService;
using TimeLogService.Application;
using TimeLogService.Application.Feature;
using TimeLogService.Application.Feature.RabbitMqConsumer;
using TimeLogService.Application.Feature.RabbitMqConsumer.Consumer.WebhookConsumer;

namespace TimeLogService.Application.Feature.RabbitMqConsumer.Consumer.WebhookConsumer
{
public class PipelineEventConsumer : IConsumer<AzureWebhookModelEvent<PipeLinesResource>>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
namespace TimeLogService.Application.Feature.RabbitMqConsumer.WebhookConsumer;
using TimeLogService;
using TimeLogService.Application;
using TimeLogService.Application.Feature;
using TimeLogService.Application.Feature.RabbitMqConsumer;
using TimeLogService.Application.Feature.RabbitMqConsumer.Consumer.WebhookConsumer;

namespace TimeLogService.Application.Feature.RabbitMqConsumer.Consumer.WebhookConsumer;

public class WorkItemEventConsumer : IConsumer<AzureWebhookModelEvent<WorkItemResource>>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using AzureDevopsService.Contracts.AzureRequestResourceModel;

namespace TimeLogService.Application.Feature.RabbitMqConsumer.Producer.ProfileUser;

public record class ProfileUserCommend(BaseRequest BaseRequest) : IRequest;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using AzureDevopsService.Contracts.AzureResponceModel;
using OneOf;
using System.Threading;
using System.Threading.Tasks;

namespace TimeLogService.Application.Feature.RabbitMqConsumer.Producer.ProfileUser
{
public class ProfileUserCommendHandler(ISendEndpointProvider sendEndpointProvider) :
IRequestHandler<ProfileUserCommend>
{
private readonly ISendEndpointProvider _sendEndpointProvider = sendEndpointProvider;

public async Task Handle(ProfileUserCommend request, CancellationToken cancellationToken)
{
ISendEndpoint endpoint = await _sendEndpointProvider.GetSendEndpoint(new Uri("rabbitmq://rabbitmq/ProfileUser"));
await endpoint.Send(request.BaseRequest, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
global using System.Reflection;
global using TimeLogService;
global using TimeLogService.Application;
global using TimeLogService.Application.Feature.RabbitMqConsumer.WebhookConsumer;
global using TimeLogService.Application.Feature.RabbitMqConsumer.Consumer.WebhookConsumer;
global using TimeLogService.Contracts.DTOs.Request;
global using TimeLogService.Contracts.Settings;
global using TimeLogService.Domain.Interfaces.Repositories;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="AzureDevopsService.Contracts" Version="1.0.1" />
<PackageReference Include="MassTransit" Version="8.2.4-develop.1856" />
<PackageReference Include="MassTransit.RabbitMQ" Version="8.2.4-develop.1856" />
<PackageReference Include="MediatR" Version="12.3.0" />
<PackageReference Include="OneOf" Version="3.0.271" />
<PackageReference Include="WebhookService.Contracts" Version="1.0.1" />
</ItemGroup>

Expand Down

0 comments on commit efb710c

Please sign in to comment.