Skip to content

Commit

Permalink
switch to mongo fw
Browse files Browse the repository at this point in the history
  • Loading branch information
azhe403 committed Jun 6, 2024
1 parent ae59a8b commit 78e414d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using MongoFramework.Linq;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using ZiziBot.DataSource.MongoDb.Entities;
using ZiziBot.DataSource.MongoEf;
using ZiziBot.DataSource.MongoEf.Entities;

namespace ZiziBot.Application.Handlers.RestApis.Webhook;

Expand Down Expand Up @@ -39,7 +38,6 @@ public class PostWebhookPayloadHandler(
IMediator mediator,
MediatorService mediatorService,
MongoDbContextBase mongoDbContextBase,
MongoEfContext mongoEfContext,
WebhookService webhookService,
AppSettingRepository appSettingRepository,
ChatSettingRepository chatSettingRepository,
Expand Down Expand Up @@ -128,7 +126,7 @@ CancellationToken cancellationToken
}
}

mongoEfContext.WebhookHistory.Add(new WebhookHistoryEntity {
mongoDbContextBase.WebhookHistory.Add(new WebhookHistoryEntity {
RouteId = webhookChat.RouteId,
TransactionId = $"{request.TransactionId}",
ChatId = webhookChat.ChatId,
Expand All @@ -137,10 +135,10 @@ CancellationToken cancellationToken
Elapsed = stopwatch.Elapsed,
Payload = request.IsDebug ? content : string.Empty,
Header = request.IsDebug ? webhookHeader : default,
Status = EventStatus.Complete
Status = (int)EventStatus.Complete
});

await mongoEfContext.SaveChangesAsync(cancellationToken);
await mongoDbContextBase.SaveChangesAsync(cancellationToken);

mongoDbContextBase.ChatActivity.Add(new ChatActivityEntity {
ActivityType = ChatActivityType.BotSentWebHook,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ZiziBot.Types.Types;

namespace ZiziBot.DataSource.MongoDb.Entities;

[Table("WebhookHistory")]
public class WebhookHistoryEntity : EntityBase
{
public string RouteId { get; set; }
public long ChatId { get; set; }
public int MessageId { get; set; }
public int MessageThreadId { get; set; }
public WebhookSource WebhookSource { get; set; }
public TimeSpan Elapsed { get; set; }
public WebhookHeader? Header { get; set; }
public string? Payload { get; set; }
}
2 changes: 2 additions & 0 deletions backend/ZiziBot.DataSource/MongoDb/MongoDbContextBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public class MongoDbContextBase : MongoDbContext
public MongoDbSet<NoteEntity> Note { get; set; }
public MongoDbSet<RssSettingEntity> RssSetting { get; set; }
public MongoDbSet<RssHistoryEntity> RssHistory { get; set; }

public MongoDbSet<WebhookChatEntity> WebhookChat { get; set; }
public MongoDbSet<WebhookHistoryEntity> WebhookHistory { get; set; }

public MongoDbSet<WordFilterEntity> WordFilter { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using MongoDB.EntityFrameworkCore;
using ZiziBot.Types.Types;

namespace ZiziBot.DataSource.MongoEf.Entities;

[Collection("WebhookHistory")]
public class WebhookHistoryEntity : EntityBase
{
public required string RouteId { get; set; }
public required long ChatId { get; set; }
public required int MessageId { get; set; }
public string RouteId { get; set; }
public long ChatId { get; set; }
public int MessageId { get; set; }
public int MessageThreadId { get; set; }
public required WebhookSource WebhookSource { get; set; }
public WebhookSource WebhookSource { get; set; }
public TimeSpan Elapsed { get; set; }
public required string Payload { get; set; }
public WebhookHeader? Header { get; set; }
public string? Payload { get; set; }
}

0 comments on commit 78e414d

Please sign in to comment.