Skip to content

Commit

Permalink
Merge branch 'update-references' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutomi authored Mar 29, 2024
2 parents cf57e1f + bae2f7f commit adc1160
Show file tree
Hide file tree
Showing 71 changed files with 454 additions and 258 deletions.
12 changes: 7 additions & 5 deletions samples/WebhookNotifierApp/Controllers/SubscriptionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@

using Microsoft.AspNetCore.Mvc;

using MongoDB.Bson;

namespace Deveel.Webhooks.Controllers {
[ApiController]
[Route("subscriptions")]
[Produces("application/json")]
public class SubscriptionController : ControllerBase {
private readonly WebhookSubscriptionManager<MongoWebhookSubscription> subscriptionManager;
private readonly WebhookSubscriptionManager<MongoWebhookSubscription, ObjectId> subscriptionManager;

public SubscriptionController(WebhookSubscriptionManager<MongoWebhookSubscription> subscriptionManager) {
public SubscriptionController(WebhookSubscriptionManager<MongoWebhookSubscription, ObjectId> subscriptionManager) {
this.subscriptionManager = subscriptionManager;
}

[HttpGet("{id}")]
[ProducesResponseType(typeof(MongoWebhookSubscription), 200)]
public async Task<IActionResult> Get([FromRoute] string id) {
var subscription = await subscriptionManager.FindByKeyAsync(id);
var subscription = await subscriptionManager.FindAsync(ObjectId.Parse(id));
if (subscription == null)
return NotFound();

Expand All @@ -37,7 +39,7 @@ public async Task<IActionResult> Post([FromBody] WebhookSubscriptionModel model)
[HttpPut("{id}")]
[ProducesResponseType(typeof(MongoWebhookSubscription), 200)]
public async Task<IActionResult> Put([FromRoute] string id, [FromBody] WebhookSubscriptionModel model) {
var subscription = await subscriptionManager.FindByKeyAsync(id);
var subscription = await subscriptionManager.FindAsync(ObjectId.Parse(id));
if (subscription == null)
return NotFound();

Expand All @@ -51,7 +53,7 @@ public async Task<IActionResult> Put([FromRoute] string id, [FromBody] WebhookSu
[HttpDelete("{id}")]
[ProducesResponseType(204)]
public async Task<IActionResult> Delete([FromRoute] string id) {
var subscription = await subscriptionManager.FindByKeyAsync(id);
var subscription = await subscriptionManager.FindAsync(ObjectId.Parse(id));
if (subscription == null)
return NotFound();

Expand Down
4 changes: 3 additions & 1 deletion samples/WebhookNotifierApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using Finbuckle.MultiTenant;

using MongoDB.Bson;

namespace Deveel.Webhooks {
public class Program {
public static void Main(string[] args) {
Expand Down Expand Up @@ -33,7 +35,7 @@ public static void Main(string[] args) {
.UseWebhookFactory<UserCreatedWebhookFactory>()
.UseMongoSubscriptionResolver());

builder.Services.AddWebhookSubscriptions<MongoWebhookSubscription>()
builder.Services.AddWebhookSubscriptions<MongoWebhookSubscription, ObjectId>()
.UseMongoDb("WebhookSubscriptions");

var app = builder.Build();
Expand Down
1 change: 1 addition & 0 deletions samples/WebhookNotifierApp/WebhookNotifierApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Deveel.Webhooks</RootNamespace>
<UserSecretsId>3a4de43e-1557-46cd-9fda-1aac0a0ee895</UserSecretsId>
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Deveel.Webhooks</RootNamespace>
<UserSecretsId>f8a59592-accc-4b98-9cc1-46749b23096e</UserSecretsId>
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
1 change: 1 addition & 0 deletions samples/WebhookReceiverApp/WebhookReceiverApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Deveel.Webhooks</RootNamespace>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.2" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.10" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0"/>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Deveel.Webhooks.Signers\Deveel.Webhooks.Signers.csproj"/>
</ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/Deveel.Webhooks.Sender/Deveel.Webhooks.Sender.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="7.0.15" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
</ItemGroup>


<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Deveel.Repository.EntityFramework" Version="1.2.7" />
<PackageReference Include="Deveel.Repository.EntityFramework" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace Deveel.Webhooks {
/// <summary>
/// An implementation of <see cref="IWebhookDeliveryResultRepository{TResult}"/> that
/// An implementation of <see cref="IWebhookDeliveryResultRepository{TResult,TKey}"/> that
/// uses an Entity Framework Core <see cref="DbContext"/> to store the
/// delivery results of a webhook of type <see cref="DbWebhookDeliveryResult"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

namespace Deveel.Webhooks {
/// <summary>
/// An implementation of <see cref="IWebhookDeliveryResultRepository{TResult}"/> that
/// An implementation of <see cref="IWebhookDeliveryResultRepository{TResult,TKey}"/> that
/// uses an Entity Framework Core <see cref="DbContext"/> to store the
/// delivery results of a webhook.
/// </summary>
/// <typeparam name="TResult">
/// The type of delivery result to be stored in the database.
/// </typeparam>
public class EntityWebhookDeliveryResultRepository<TResult> : EntityRepository<TResult>,
IWebhookDeliveryResultRepository<TResult>
public class EntityWebhookDeliveryResultRepository<TResult> : EntityRepository<TResult, int>,
IWebhookDeliveryResultRepository<TResult, int>
where TResult : DbWebhookDeliveryResult {

/// <summary>
Expand All @@ -48,7 +48,7 @@ public EntityWebhookDeliveryResultRepository(WebhookDbContext context, ILogger<E
cancellationToken.ThrowIfCancellationRequested();

try {
return await this.FindFirstAsync<TResult>(x => x.Webhook.WebhookId == webhookId, cancellationToken);
return await this.FindFirstAsync<TResult, int>(x => x.Webhook.WebhookId == webhookId, cancellationToken);
} catch (Exception ex) {
throw new WebhookEntityException("Unable to query the database for results", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ namespace Deveel.Webhooks {
/// The type of the <see cref="DbWebhookSubscription"/> entity to use
/// </typeparam>
public sealed class EntityWebhookStorageBuilder<TSubscription> where TSubscription : DbWebhookSubscription {
private readonly WebhookSubscriptionBuilder<TSubscription> builder;
private readonly WebhookSubscriptionBuilder<TSubscription, string> builder;

internal EntityWebhookStorageBuilder(WebhookSubscriptionBuilder<TSubscription> builder) {
internal EntityWebhookStorageBuilder(WebhookSubscriptionBuilder<TSubscription, string> builder) {
this.builder = builder;

AddDefaultStorage();
Expand Down Expand Up @@ -144,7 +144,7 @@ public EntityWebhookStorageBuilder<TSubscription> UseSubscriptionRepository<TRep
Services.RemoveAll<IRepository<TSubscription>>();
Services.RemoveAll<IPageableRepository<TSubscription>>();
Services.RemoveAll<IQueryableRepository<TRepository>>();
Services.RemoveAll<IWebhookSubscriptionRepository<TSubscription>>();
Services.RemoveAll<IWebhookSubscriptionRepository<TSubscription, string>>();
Services.RemoveAll<EntityWebhookSubscriptionRepository<TSubscription>>();
Services.RemoveAll<EntityWebhookSubscriptionRepository>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

namespace Deveel.Webhooks {
/// <summary>
/// An implementation of <see cref="IWebhookSubscriptionRepository{TSubscription}"/> that
/// An implementation of <see cref="IWebhookSubscriptionRepository{TSubscription,TKey}"/> that
/// uses an <see cref="DbContext"/> to store the subscriptions.
/// </summary>
/// <typeparam name="TSubscription">
/// The type of the subscription entity to be stored.
/// </typeparam>
/// <seealso cref="IWebhookSubscriptionRepository{TSubscription}"/>"/>
/// <seealso cref="IWebhookSubscriptionRepository{TSubscription,TKey}"/>"/>
public class EntityWebhookSubscriptionRepository<TSubscription> :
EntityRepository<TSubscription>,
IWebhookSubscriptionRepository<TSubscription>
EntityRepository<TSubscription, string>,
IWebhookSubscriptionRepository<TSubscription,string>
where TSubscription : DbWebhookSubscription {

/// <summary>
Expand Down Expand Up @@ -68,7 +68,7 @@ private async Task<TSubscription> EnsureLoadedAsync(TSubscription subscription,
}

/// <inheritdoc/>
protected override async Task<TSubscription> OnEntityFoundByKeyAsync(object key, TSubscription entity, CancellationToken cancellationToken = default)
protected override async Task<TSubscription> OnEntityFoundByKeyAsync(string key, TSubscription entity, CancellationToken cancellationToken = default)
=> await EnsureLoadedAsync(entity, cancellationToken);

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace Deveel.Webhooks {
/// <summary>
/// Provides extensions to the <see cref="WebhookSubscriptionBuilder{TSubscription}"/>
/// Provides extensions to the <see cref="WebhookSubscriptionBuilder{TSubscription,TKey}"/>
/// to configure the storage system based on Entity Framework.
/// </summary>
public static class WebhookSubscriptionBuilderExtensions {
Expand All @@ -25,14 +25,14 @@ public static class WebhookSubscriptionBuilderExtensions {
/// The type of the <see cref="DbWebhookSubscription"/> entity to use
/// </typeparam>
/// <param name="builder">
/// The instance of the <see cref="WebhookSubscriptionBuilder{TSubscription}"/> to
/// The instance of the <see cref="WebhookSubscriptionBuilder{TSubscription,TKey}"/> to
/// extend with the Entity Framework storage system.
/// </param>
/// <returns>
/// Returns an instance of <see cref="EntityWebhookStorageBuilder{TSubscription}"/>
/// that can be used to configure the storage system.
/// </returns>
public static EntityWebhookStorageBuilder<TSubscription> UseEntityFramework<TSubscription>(this WebhookSubscriptionBuilder<TSubscription> builder)
public static EntityWebhookStorageBuilder<TSubscription> UseEntityFramework<TSubscription>(this WebhookSubscriptionBuilder<TSubscription,string> builder)
where TSubscription : DbWebhookSubscription
=> new EntityWebhookStorageBuilder<TSubscription>(builder);

Expand All @@ -43,18 +43,18 @@ public static EntityWebhookStorageBuilder<TSubscription> UseEntityFramework<TSub
/// The type of the <see cref="DbWebhookSubscription"/> entity to use
/// </typeparam>
/// <param name="builder">
/// The instance of the <see cref="WebhookSubscriptionBuilder{TSubscription}"/> to
/// The instance of the <see cref="WebhookSubscriptionBuilder{TSubscription,TKey}"/> to
/// extend with the Entity Framework storage system.
/// </param>
/// <param name="configure">
/// An action that receives an instance of <see cref="EntityWebhookStorageBuilder{TSubscription}"/>
/// as input to configure the storage system.
/// </param>
/// <returns>
/// Returns the same instance of <see cref="WebhookSubscriptionBuilder{TSubscription}"/>
/// Returns the same instance of <see cref="WebhookSubscriptionBuilder{TSubscription,TKey}"/>
/// as the input, to allow chaining of calls.
/// </returns>
public static WebhookSubscriptionBuilder<TSubscription> UseEntityFramework<TSubscription>(this WebhookSubscriptionBuilder<TSubscription> builder, Action<EntityWebhookStorageBuilder<TSubscription>> configure)
public static WebhookSubscriptionBuilder<TSubscription, string> UseEntityFramework<TSubscription>(this WebhookSubscriptionBuilder<TSubscription, string> builder, Action<EntityWebhookStorageBuilder<TSubscription>> configure)
where TSubscription : DbWebhookSubscription {
var storageBuilder = builder.UseEntityFramework();
configure(storageBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Deveel.Repository.MongoFramework" Version="1.2.7" />
<PackageReference Include="Deveel.Repository.MongoFramework" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,48 @@

using Deveel.Data;

using Finbuckle.MultiTenant;

using Microsoft.Extensions.Logging;

using SharpCompress.Compressors.PPMd;

namespace Deveel.Webhooks {
/// <summary>
/// Provides an implementation of the <see cref="IWebhookDeliveryResultRepositoryProvider{TResult}"/>
/// that is resolving instances of <see cref="MongoDbWebhookDeliveryResultRepository{TResult}"/> based
/// Provides an implementation of the <see cref="IWebhookDeliveryResultRepositoryProvider{TResult,TKey}"/>
/// that is resolving instances of <see cref="MongoDbWebhookDeliveryResultRepository{TResult,TKey}"/> based
/// on the tenant identifier.
/// </summary>
/// <typeparam name="TTenantInfo">
/// The type of tenant that owns the connection to the MongoDB database
/// </typeparam>
/// <typeparam name="TResult">
/// The type of the result that is stored in the database.
/// </typeparam>
public class MongoDbWebhookDeliveryResultRepositoryProvider<TTenantInfo, TResult> : MongoRepositoryProvider<MongoDbWebhookTenantContext, TResult, TTenantInfo>,
IWebhookDeliveryResultRepositoryProvider<TResult>
where TTenantInfo : class, ITenantInfo, new()
where TResult : MongoWebhookDeliveryResult {
/// <typeparam name="TKey">
/// The type of the key that is used to identify the result in the database.
/// </typeparam>
public class MongoDbWebhookDeliveryResultRepositoryProvider<TResult, TKey> : MongoRepositoryProvider<MongoDbWebhookTenantContext, TResult, TKey>,
IWebhookDeliveryResultRepositoryProvider<TResult, TKey>
where TResult : MongoWebhookDeliveryResult
where TKey : notnull {
/// <summary>
/// Constructs the provider with the given tenant store.
/// </summary>
/// <param name="tenantStore">
/// The store that is used to resolve the tenant information.
/// </param>
/// <param name="tenantResolver">
/// A service that is used to resolve the tenant identifier for the
/// current context.
/// </param>
/// <param name="loggerFactory">
/// An object that is used to create the logger for the repositories
/// created by this provider.
/// </param>
public MongoDbWebhookDeliveryResultRepositoryProvider(
IEnumerable<IMultiTenantStore<TTenantInfo>> tenantStore,
IRepositoryTenantResolver tenantResolver,
ILoggerFactory? loggerFactory = null)
: base(tenantStore, loggerFactory) {
: base(tenantResolver, loggerFactory) {
}

/// <inheritdoc/>
public new async Task<IWebhookDeliveryResultRepository<TResult>> GetRepositoryAsync(string tenantId, CancellationToken cancellationToken = default) {
return (IWebhookDeliveryResultRepository<TResult>) await base.GetRepositoryAsync(tenantId, cancellationToken);
public new async Task<IWebhookDeliveryResultRepository<TResult, TKey>> GetRepositoryAsync(string tenantId, CancellationToken cancellationToken = default) {
return (IWebhookDeliveryResultRepository<TResult, TKey>) await base.GetRepositoryAsync(tenantId, cancellationToken);
}

/// <inheritdoc/>
protected override MongoRepository<TResult> CreateRepository(MongoDbWebhookTenantContext context)
=> new MongoDbWebhookDeliveryResultRepository<TResult>(context, LoggerFactory?.CreateLogger<MongoDbWebhookDeliveryResultRepository<TResult>>());
protected override MongoRepository<TResult, TKey> CreateRepository(MongoDbWebhookTenantContext context)
=> new MongoDbWebhookDeliveryResultRepository<TResult, TKey>(context, LoggerFactory?.CreateLogger<MongoDbWebhookDeliveryResultRepository<TResult, TKey>>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;

using MongoDB.Bson;

namespace Deveel.Webhooks {
/// <summary>
/// An implementation of <see cref="IWebhookDeliveryResultLogger{TWebhook}"/> that
Expand Down Expand Up @@ -47,7 +49,7 @@ public class MongoDbWebhookDeliveryResultLogger<TWebhook, TResult> : IWebhookDel
/// An optional logger to use to log messages emitted by this service.
/// </param>
public MongoDbWebhookDeliveryResultLogger(
IWebhookDeliveryResultRepositoryProvider<TResult> storeProvider,
IWebhookDeliveryResultRepositoryProvider<TResult, ObjectId> storeProvider,
IMongoWebhookConverter<TWebhook>? webhookConverter = null,
ILogger<MongoDbWebhookDeliveryResultLogger<TWebhook, TResult>>? logger = null) {
RepositoryProvider = storeProvider;
Expand All @@ -59,7 +61,7 @@ public MongoDbWebhookDeliveryResultLogger(
/// Gets the provider used to resolve the MongoDB storage where to log
/// the delivery results.
/// </summary>
protected IWebhookDeliveryResultRepositoryProvider<TResult> RepositoryProvider { get; }
protected IWebhookDeliveryResultRepositoryProvider<TResult, ObjectId> RepositoryProvider { get; }

/// <summary>
/// Gets the logger used to log messages emitted by this service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using MongoDB.Bson;

namespace Deveel.Webhooks {
/// <summary>
/// A default implementation of the <see cref="IWebhookDeliveryResultRepository{T}"/>
/// A default implementation of the <see cref="IWebhookDeliveryResultRepository{TResult,TKey}"/>
/// that uses the <see cref="MongoWebhookDeliveryResult"/> as the entity
/// </summary>
public class MongoDbWebhookDeliveryResultRepository : MongoDbWebhookDeliveryResultRepository<MongoWebhookDeliveryResult> {
public class MongoDbWebhookDeliveryResultRepository : MongoDbWebhookDeliveryResultRepository<MongoWebhookDeliveryResult, ObjectId> {
/// <summary>
/// Constructs the store with the given context.
/// </summary>
Expand Down
Loading

0 comments on commit adc1160

Please sign in to comment.