Skip to content

Commit

Permalink
Fixed filtering in the user measures.
Browse files Browse the repository at this point in the history
  • Loading branch information
Misha12 committed Jan 23, 2024
1 parent 0f3c8e6 commit 0309f16
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,20 @@ public override async Task<ApiResult> ProcessAsync()
var memberWarnings = await ReadMemberWarningsAsync(parameters);
var unverifyLogs = await ReadUnverifyLogsAsync(repository, parameters);
var allItems = await MergeAndMapAsync(repository, memberWarnings, unverifyLogs);
var result = PaginatedResponse<UserMeasuresListItem>.Create(allItems, parameters.Pagination);
var result = PaginatedResponse<UserMeasuresListItem>.Create(FilterItems(allItems, parameters), parameters.Pagination);

return ApiResult.Ok(result);
}

private async Task<List<LogListItem>> 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 =
{
Expand Down Expand Up @@ -123,8 +126,7 @@ private static async Task<List<UnverifyLog>> ReadUnverifyLogsAsync(GrillBotRepos
return result.Data;
}

private async Task<List<UserMeasuresListItem>> MergeAndMapAsync(GrillBotRepository repository, List<AuditLogModels.Response.Search.LogListItem> memberWarnings,
List<UnverifyLog> unverifyLogs)
private async Task<List<UserMeasuresListItem>> MergeAndMapAsync(GrillBotRepository repository, List<LogListItem> memberWarnings, List<UnverifyLog> unverifyLogs)
{
var result = new List<UserMeasuresListItem>();

Expand Down Expand Up @@ -160,7 +162,6 @@ private async Task<List<UserMeasuresListItem>> MergeAndMapAsync(GrillBotReposito
}

return result.OrderByDescending(o => o.CreatedAt).ToList();

}

private async Task<ApiModels.Guilds.Guild> ReadGuildAsync(GrillBotRepository repository, string guildId)
Expand All @@ -186,4 +187,11 @@ private async Task<List<UserMeasuresListItem>> MergeAndMapAsync(GrillBotReposito

return user;
}

private static List<UserMeasuresListItem> FilterItems(List<UserMeasuresListItem> items, UserMeasuresParams parameters)
{
return parameters.Type is not null ?
items.FindAll(o => o.Type == parameters.Type.Value) :
items;
}
}
2 changes: 1 addition & 1 deletion src/GrillBot.Data/Models/API/Users/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class User
/// Username.
/// </summary>
public string Username { get; set; } = null!;

public string? GlobalAlias { get; set; }

/// <summary>
Expand Down

0 comments on commit 0309f16

Please sign in to comment.