diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/InstructLogFilter.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/InstructLogFilter.cs index c1040f94..aeec7b18 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/InstructLogFilter.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/InstructLogFilter.cs @@ -8,6 +8,8 @@ public class InstructLogFilter : Pagination public List? TemplateNames { get; set; } public List? UserIds { get; set; } public List? States { get; set; } + public DateTime? StartTime { get; set; } + public DateTime? EndTime { get; set; } public static InstructLogFilter Empty() { diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs index 81da4047..a42bc988 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs @@ -452,6 +452,10 @@ public partial class FileRepository { matched = matched && record.CreatedTime >= filter.StartTime.Value; } + if (filter?.EndTime != null) + { + matched = matched && record.CreatedTime <= filter.EndTime.Value; + } if (filter?.Tags != null && filter.Tags.Any()) { matched = matched && !record.Tags.IsNullOrEmpty() && record.Tags.Exists(t => filter.Tags.Contains(t)); diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Log.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Log.cs index 3913a404..5b8d095f 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Log.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Log.cs @@ -202,6 +202,14 @@ namespace BotSharp.Core.Repository { matched = matched && filter.UserIds.Contains(log.UserId); } + if (filter.StartTime.HasValue) + { + matched = matched && log.CreatedTime >= filter.StartTime.Value; + } + if (filter.EndTime.HasValue) + { + matched = matched && log.CreatedTime <= filter.EndTime.Value; + } // Check states if (matched && filter != null && !filter.States.IsNullOrEmpty()) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs index 8cd6e158..196c6dfc 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Log.cs @@ -196,6 +196,14 @@ public partial class MongoRepository { logFilters.Add(logBuilder.In(x => x.TemplateName, filter.TemplateNames)); } + if (filter.StartTime.HasValue) + { + logFilters.Add(logBuilder.Gte(x => x.CreatedTime, filter.StartTime.Value)); + } + if (filter.EndTime.HasValue) + { + logFilters.Add(logBuilder.Lte(x => x.CreatedTime, filter.EndTime.Value)); + } // Filter states if (filter != null && !filter.States.IsNullOrEmpty())