From 0309f16ec6b7421a97c735f88ad6ba36ea01fe73 Mon Sep 17 00:00:00 2001 From: Michal Halabica Date: Tue, 23 Jan 2024 07:55:08 +0100 Subject: [PATCH] Fixed filtering in the user measures. --- .../V1/UserMeasures/GetUserMeasuresList.cs | 20 +++++++++++++------ src/GrillBot.Data/Models/API/Users/User.cs | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/GrillBot.App/Actions/Api/V1/UserMeasures/GetUserMeasuresList.cs b/src/GrillBot.App/Actions/Api/V1/UserMeasures/GetUserMeasuresList.cs index 46eb41889..4a6914bc8 100644 --- a/src/GrillBot.App/Actions/Api/V1/UserMeasures/GetUserMeasuresList.cs +++ b/src/GrillBot.App/Actions/Api/V1/UserMeasures/GetUserMeasuresList.cs @@ -40,17 +40,20 @@ public override async Task ProcessAsync() var memberWarnings = await ReadMemberWarningsAsync(parameters); var unverifyLogs = await ReadUnverifyLogsAsync(repository, parameters); var allItems = await MergeAndMapAsync(repository, memberWarnings, unverifyLogs); - var result = PaginatedResponse.Create(allItems, parameters.Pagination); + var result = PaginatedResponse.Create(FilterItems(allItems, parameters), parameters.Pagination); return ApiResult.Ok(result); } private async Task> ReadMemberWarningsAsync(UserMeasuresParams parameters) { + var createdFrom = parameters.CreatedFrom is not null ? parameters.CreatedFrom.Value.WithKind(DateTimeKind.Local).ToUniversalTime() : (DateTime?)null; + var createdto = parameters.CreatedTo is not null ? parameters.CreatedTo.Value.WithKind(DateTimeKind.Local).ToUniversalTime() : (DateTime?)null; + var searchRequest = new AuditLogModels.Request.Search.SearchRequest { - CreatedFrom = parameters.CreatedFrom, - CreatedTo = parameters.CreatedTo, + CreatedFrom = createdFrom, + CreatedTo = createdto, GuildId = parameters.GuildId, Pagination = { @@ -123,8 +126,7 @@ private static async Task> ReadUnverifyLogsAsync(GrillBotRepos return result.Data; } - private async Task> MergeAndMapAsync(GrillBotRepository repository, List memberWarnings, - List unverifyLogs) + private async Task> MergeAndMapAsync(GrillBotRepository repository, List memberWarnings, List unverifyLogs) { var result = new List(); @@ -160,7 +162,6 @@ private async Task> MergeAndMapAsync(GrillBotReposito } return result.OrderByDescending(o => o.CreatedAt).ToList(); - } private async Task ReadGuildAsync(GrillBotRepository repository, string guildId) @@ -186,4 +187,11 @@ private async Task> MergeAndMapAsync(GrillBotReposito return user; } + + private static List FilterItems(List items, UserMeasuresParams parameters) + { + return parameters.Type is not null ? + items.FindAll(o => o.Type == parameters.Type.Value) : + items; + } } diff --git a/src/GrillBot.Data/Models/API/Users/User.cs b/src/GrillBot.Data/Models/API/Users/User.cs index a21c74eb5..0824b629c 100644 --- a/src/GrillBot.Data/Models/API/Users/User.cs +++ b/src/GrillBot.Data/Models/API/Users/User.cs @@ -11,7 +11,7 @@ public class User /// Username. /// public string Username { get; set; } = null!; - + public string? GlobalAlias { get; set; } ///