1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

finish initial rework of profile page with meta pagination

This commit is contained in:
RaidMax
2019-03-29 21:56:56 -05:00
parent 25472b06c3
commit 807d9fa069
16 changed files with 227 additions and 140 deletions

View File

@ -18,10 +18,6 @@ namespace SharedLibraryCore.Dtos
public List<string> IPs { get; set; }
public bool HasActivePenalty { get; set; }
public string ActivePenaltyType { get; set; }
//public int ConnectionCount { get; set; }
//public string LastSeen { get; set; }
//public string FirstSeen { get; set; }
//public string TimePlayed { get; set; }
public bool Authenticated { get; set; }
public List<ProfileMeta> Meta { get; set; }
public bool Online { get; set; }

View File

@ -13,7 +13,9 @@ namespace SharedLibraryCore.Dtos
Other,
Information,
AliasUpdate,
ChatMessage
ChatMessage,
Penalized,
ReceivedPenalty,
}
public DateTime When { get; set; }

View File

@ -11,7 +11,7 @@ namespace SharedLibraryCore.Services
{
public class MetaService
{
private static List<Func<int, int, int, Task<List<ProfileMeta>>>> _metaActions = new List<Func<int, int, int, Task<List<ProfileMeta>>>>();
private static List<Func<int, int, int, DateTime?, Task<List<ProfileMeta>>>> _metaActions = new List<Func<int, int, int, DateTime?, Task<List<ProfileMeta>>>>();
/// <summary>
/// adds or updates meta key and value to the database
@ -71,7 +71,7 @@ namespace SharedLibraryCore.Services
/// aads a meta task to the runtime meta list
/// </summary>
/// <param name="metaAction"></param>
public static void AddRuntimeMeta(Func<int, int, int, Task<List<ProfileMeta>>> metaAction)
public static void AddRuntimeMeta(Func<int, int, int, DateTime?, Task<List<ProfileMeta>>> metaAction)
{
_metaActions.Add(metaAction);
}
@ -83,16 +83,24 @@ namespace SharedLibraryCore.Services
/// <param name="count">number of meta items to retrieve</param>
/// <param name="offset">offset from the first item</param>
/// <returns></returns>
public static async Task<List<ProfileMeta>> GetRuntimeMeta(int clientId, int offset = 0, int count = int.MaxValue)
public static async Task<List<ProfileMeta>> GetRuntimeMeta(int clientId, int offset = 0, int count = int.MaxValue, DateTime? startAt = null)
{
var meta = new List<ProfileMeta>();
foreach (var action in _metaActions)
{
meta.AddRange(await action(clientId, offset, count));
var metaItems = await action(clientId, offset, count, startAt);
meta.AddRange(metaItems);
}
return meta;
if (count == 1)
{
return meta;
}
return meta.OrderByDescending(_meta => _meta.When)
.Take(count)
.ToList();
}
}
}

View File

@ -159,6 +159,24 @@ namespace SharedLibraryCore.Services
}
}
public async Task<IList<EFPenalty>> GetAllClientPenaltiesAsync(int clientId, int count, int offset, DateTime? startAt)
{
using (var ctx = new DatabaseContext(true))
{
var iqPenalties = ctx.Penalties.AsNoTracking()
.Include(_penalty => _penalty.Offender.CurrentAlias)
.Include(_penalty => _penalty.Punisher.CurrentAlias)
.Where(_penalty => _penalty.Active)
.Where(_penalty => _penalty.OffenderId == clientId || _penalty.PunisherId == clientId)
.Where(_penalty => _penalty.When < startAt)
.OrderByDescending(_penalty => _penalty.When)
.Skip(offset)
.Take(count);
return await iqPenalties.ToListAsync();
}
}
/// <summary>
/// Get a read-only copy of client penalties
/// </summary>