Skip to content

Commit

Permalink
baseController TModule
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEggenberger committed Nov 27, 2024
1 parent 294f2cc commit ec92ab4
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@ public class ChannelsController : BaseController
public ChannelsController(IServiceProvider serviceProvider) : base(serviceProvider) { }

[HttpGet]
public async Task<List<ChannelDTO>> GetChannels(CancellationToken cancellationToken)
public async Task<ActionResult> GetChannels(CancellationToken cancellationToken)
{
List<Channel> channels = await queryDispatcher.DispatchAsync<GetAllChannels, List<Channel>>(new GetAllChannels(), cancellationToken);
return mapper.Map<List<ChannelDTO>>(channels);
var channels = await queryDispatcher.DispatchAsync<GetAllChannels, List<Channel>>(new GetAllChannels(), cancellationToken);

return Ok(channels);
}

[HttpGet("{id}")]
public async Task<ChannelDTO> GetChannelById([FromRoute] Guid id, CancellationToken cancellationToken)
public async Task<ActionResult> GetChannelById([FromRoute] Guid id, CancellationToken cancellationToken)
{
Channel channel = await queryDispatcher.DispatchAsync<GetChannelById, Channel>(new GetChannelById() { Id = id }, cancellationToken);
return mapper.Map<ChannelDTO>(channel);
var channel = await queryDispatcher.DispatchAsync<GetChannelById, Channel>(new GetChannelById() { Id = id }, cancellationToken);

return Ok(channel);
}

[HttpPost]
public async Task CreateChannel([FromBody] ChannelDTO createChannelDTO, CancellationToken cancellationToken)
{
CreateChannel createChannelCommand = mapper.Map<CreateChannel>(createChannelDTO);
var createChannelCommand = mapper.Map<CreateChannel>(createChannelDTO);
await commandDispatcher.DispatchAsync(createChannelCommand, cancellationToken);
}

Expand Down
29 changes: 10 additions & 19 deletions Source/Modules/Subscriptions/Web/Server/WebHooks/StripeWebhook.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
using Shared.Modules.Layers.Application.Messaging.Command;
using Shared.Modules.Layers.Features.StripeIntegration;
using Shared.Modules.Layers.Features.StripeIntegration.Commands;
using Shared.Modules.Layers.Features.StripeIntegration.Configuration;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Stripe;
using System.IO;
using Shared.Features.Server;
using Modules.Subscriptions.Features;

namespace Web.Server.Controllers.Stripe
{
[Route("api/[controller]")]
[ApiController]
public class StripeWebhook : BaseController
public class StripeWebhook : BaseController<SubscriptionsModule>
{
private readonly StripeOptions stripeOptions;
public StripeWebhook(IOptions<StripeOptions> stripeOptions, ICommandDispatcher commandDispatcher)
{
this.stripeOptions = stripeOptions.Value;
this.commandDispatcher = commandDispatcher;
}

public StripeWebhook(IServiceProvider serviceProvider) : base(serviceProvider) { }

[HttpPost]
[IgnoreAntiforgeryToken]
Expand All @@ -34,28 +25,28 @@ public async Task<IActionResult> Index()
var stripeEvent = EventUtility.ParseEvent(json);
var signatureHeader = Request.Headers["Stripe-Signature"];
stripeEvent = EventUtility.ConstructEvent(json,
signatureHeader, stripeOptions.EndpointSecret);
signatureHeader, module.SubscriptionsConfiguration.StripeEndpointSecret);

//More Events Events.Checkout...
if (stripeEvent.Type == Events.CustomerSubscriptionCreated)
{
var subscription = stripeEvent.Data.Object as Subscription;
await commandDispatcher.DispatchAsync(new CreateSubscriptionCommand { Subscription = subscription });
await commandDispatcher.DispatchAsync(new CreateSubscription { Subscription = subscription });
}
else if (stripeEvent.Type == Events.CustomerSubscriptionUpdated)
{
var subscription = stripeEvent.Data.Object as Subscription;
await commandDispatcher.DispatchAsync(new UpdateSubscriptionCommand { Subscription = subscription });
await commandDispatcher.DispatchAsync(new UpdateSubscription { Subscription = subscription });
}
else if (stripeEvent.Type == Events.CustomerSubscriptionDeleted)
{
var subscription = stripeEvent.Data.Object as Subscription;
await commandDispatcher.DispatchAsync(new DeleteSubscriptionCommand { Subscription = subscription });
await commandDispatcher.DispatchAsync(new DeleteSubscription { Subscription = subscription });
}
else if (stripeEvent.Type == Events.CustomerSubscriptionTrialWillEnd)
{
var subscription = stripeEvent.Data.Object as Subscription;
await commandDispatcher.DispatchAsync(new SubscriptionTrialEndedCommand { Subscription = subscription });
await commandDispatcher.DispatchAsync(new SubscriptionTrialEnded { Subscription = subscription });
}
return Ok();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Shared/Client/Components/CustomErrorBoundary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

namespace Web.Client.Components
namespace Shared.Client.Components
{
public class CustomErrorBoundary : ErrorBoundary
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Shared/Client/Components/Diagrams/Nodes/UserNode.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Blazor.Diagrams.Core.Models;
using Modules.IdentityModule.Shared;
using Web.Client.Diagrams.Ports;
using Shared.Client.Diagrams.Ports;

namespace Web.Client.Diagrams.Nodes
namespace Shared.Client.Diagrams.Nodes
{
public class UserNode : NodeModel
{
Expand Down
5 changes: 3 additions & 2 deletions Source/Shared/Client/Components/Diagrams/Ports/NodePort.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Blazor.Diagrams.Core.Models;
using Blazor.Diagrams.Core.Models.Base;

namespace Web.Client.Diagrams.Ports
namespace Shared.Client.Diagrams.Ports
{
public class NodePort : PortModel
{
Expand All @@ -10,7 +11,7 @@ public NodePort(NodeModel parent, PortAlignment alignment = PortAlignment.Bottom

}

public override bool CanAttachTo(PortModel port)
public override bool CanAttachTo(ILinkable port)
{
// Avoid attaching to self port/node
if (!base.CanAttachTo(port))
Expand Down
4 changes: 4 additions & 0 deletions Source/Shared/Client/Shared.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
<ItemGroup>
<PackageReference Include="Blazored.Modal" Version="7.3.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.2" />
<PackageReference Include="Z.Blazor.Diagrams" Version="3.0.2" />
<PackageReference Include="Z.Blazor.Diagrams.Core" Version="3.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Modules\TenantIdentity\Shared\Modules.TenantIdentity.Shared.csproj" />
<ProjectReference Include="..\Kernel\Shared.Kernel.csproj" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions Source/Shared/Features/Domain/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public abstract class Entity : IAuditable, IIdentifiable, IConcurrent
[Key]
public Guid Id { get; set; }

public Guid UserId { get; set; }
public virtual Guid TenantId { get; set; }

[ConcurrencyCheck]
Expand Down

This file was deleted.

10 changes: 10 additions & 0 deletions Source/Shared/Features/Server/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

namespace Shared.Features.Server
{
public class BaseController<TModule> : BaseController
{
protected readonly TModule module;

public BaseController(IServiceProvider serviceProvider) : base(serviceProvider)
{
module = serviceProvider.GetService<TModule>();
}
}

public class BaseController : ControllerBase
{
protected readonly ICommandDispatcher commandDispatcher;
Expand Down
4 changes: 1 addition & 3 deletions Source/Web/Client/Web.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="6.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="6.0.2" />
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
<PackageReference Include="Z.Blazor.Diagrams" Version="2.1.6" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Modules\Channels\Shared\Modules.Channels.Shared.csproj" />
<ProjectReference Include="..\..\Modules\Channels\Web\Client\Modules.Channels.Web.Client.csproj" />
<ProjectReference Include="..\..\Modules\Subscription\Web\Client\Modules.Subscriptions.Web.Client.csproj" />
<ProjectReference Include="..\..\Modules\TenantIdentity\Shared\Modules.TenantIdentity.Shared.csproj" />
<ProjectReference Include="..\..\Modules\TenantIdentity\Web\Client\Modules.TenantIdentity.Web.Client.csproj" />
<ProjectReference Include="..\..\Shared\Kernel\Shared.Kernel.csproj" />
Expand Down

0 comments on commit ec92ab4

Please sign in to comment.