-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
590 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
...ystem/src/TeachingRecordSystem.Api/Infrastructure/Json/JsonSerializerOptionsExtensions.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tructure/OpenApi/OpenApiDocumentHelper.cs → ...ecordSystem.Core/OpenApiDocumentHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/WebhookOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace TeachingRecordSystem.Core.Services.Webhooks; | ||
|
||
public class WebhookOptions | ||
{ | ||
[Required] | ||
public required string CanonicalDomain { get; set; } | ||
} |
45 changes: 45 additions & 0 deletions
45
TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/WebhookSender.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Diagnostics; | ||
using CloudNative.CloudEvents; | ||
using CloudNative.CloudEvents.Http; | ||
using CloudNative.CloudEvents.SystemTextJson; | ||
using Microsoft.Extensions.Options; | ||
using TeachingRecordSystem.Core.DataStore.Postgres.Models; | ||
|
||
namespace TeachingRecordSystem.Core.Services.Webhooks; | ||
|
||
public class WebhookSender(HttpClient httpClient, IOptions<WebhookOptions> optionsAccessor) | ||
{ | ||
private const string DataContentType = "application/json; charset=utf-8"; | ||
|
||
private readonly CloudEventFormatter _formatter = new JsonEventFormatter(); | ||
|
||
public async Task SendMessageAsync(WebhookMessage message, CancellationToken cancellationToken = default) | ||
{ | ||
Debug.Assert(message.WebhookEndpoint is not null); | ||
|
||
var openApiDocumentName = OpenApiDocumentHelper.GetDocumentName(3, message.ApiVersion); | ||
var swaggerEndpoint = OpenApiDocumentHelper.DocumentRouteTemplate.Replace("{documentName}", openApiDocumentName); | ||
var dataSchema = new Uri(optionsAccessor.Value.CanonicalDomain + swaggerEndpoint, UriKind.Absolute); | ||
|
||
var source = new Uri(optionsAccessor.Value.CanonicalDomain); | ||
|
||
var cloudEvent = new CloudEvent() | ||
{ | ||
Id = message.CloudEventId, | ||
Source = source, | ||
Type = message.CloudEventType, | ||
DataContentType = DataContentType, | ||
DataSchema = dataSchema, | ||
Time = message.Timestamp, | ||
Data = message.Data, | ||
}; | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Post, message.WebhookEndpoint.Address) | ||
{ | ||
Content = cloudEvent.ToHttpContent(ContentMode.Binary, _formatter) | ||
}; | ||
|
||
var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead, cancellationToken); | ||
response.EnsureSuccessStatusCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.