Skip to content

Commit

Permalink
Add GetMapRecordsAsync with single mapId option
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBang1112 committed Jul 6, 2024
1 parent c1ed3ab commit 917b1dc
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Src/ManiaAPI.NadeoAPI/NadeoServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public interface INadeoServices : INadeoAPI
Task<ImmutableArray<Account>> GetAccountDisplayNamesAsync(IEnumerable<Guid> accountIds, CancellationToken cancellationToken = default);
Task<ImmutableArray<Account>> GetAccountDisplayNamesAsync(params Guid[] accountIds);
Task<ImmutableArray<MapRecord>> GetMapRecordsAsync(IEnumerable<Guid> accountIds, IEnumerable<Guid> mapIds, CancellationToken cancellationToken = default);
Task<MapRecord> GetMapRecordByIdAsync(Guid mapRecordId, CancellationToken cancellationToken = default);
Task<ImmutableArray<MapRecord>> GetMapRecordsAsync(IEnumerable<Guid> accountIds, Guid mapId, CancellationToken cancellationToken = default);
Task<MapRecord> GetMapRecordByIdAsync(Guid mapRecordId, CancellationToken cancellationToken = default);
Task<ImmutableArray<PlayerZone>> GetPlayerZonesAsync(IEnumerable<Guid> accountIds, CancellationToken cancellationToken = default);
Task<ImmutableArray<PlayerZone>> GetPlayerZonesAsync(params Guid[] accountIds);
Task<Dictionary<string, ApiRoute>> GetApiRoutesAsync(ApiUsage usage, CancellationToken cancellationToken = default);
Expand All @@ -32,12 +33,24 @@ public NadeoServices(HttpClient client, bool automaticallyAuthorize = true) : ba

public NadeoServices(bool automaticallyAuthorize = true) : this(new HttpClient(), automaticallyAuthorize)
{
}
}

public virtual async Task<ImmutableArray<MapRecord>> GetMapRecordsAsync(IEnumerable<Guid> accountIds, Guid mapId, CancellationToken cancellationToken = default)
{
return await GetJsonAsync($"v2/mapRecords/?accountIdList={string.Join(',', accountIds)}&mapId={mapId}",
NadeoAPIJsonContext.Default.ImmutableArrayMapRecord, cancellationToken);
}

public virtual async Task<ImmutableArray<MapRecord>> GetMapRecordsAsync(IEnumerable<Guid> accountIds, IEnumerable<Guid> mapIds, CancellationToken cancellationToken = default)
public virtual async Task<ImmutableArray<MapRecord>> GetMapRecordsAsync(IEnumerable<Guid> accountIds, IEnumerable<Guid> mapIds, CancellationToken cancellationToken = default)
{
return await GetJsonAsync($"mapRecords/?accountIdList={string.Join(',', accountIds)}&mapIdList={string.Join(',', mapIds)}",
NadeoAPIJsonContext.Default.ImmutableArrayMapRecord, cancellationToken);
var records = ImmutableArray.CreateBuilder<MapRecord>();

foreach (var mapId in mapIds)
{
records.AddRange(await GetMapRecordsAsync(accountIds, mapId, cancellationToken));
}

return records.ToImmutable();
}

public virtual async Task<MapRecord> GetMapRecordByIdAsync(Guid mapRecordId, CancellationToken cancellationToken = default)
Expand Down

0 comments on commit 917b1dc

Please sign in to comment.