diff --git a/BuildingBlocks/src/BuildingBlocks.API/Mvc/ModelBinders/GenericArrayModelBinder.cs b/BuildingBlocks/src/BuildingBlocks.API/Mvc/ModelBinders/GenericArrayModelBinder.cs index c86ca565dc..4eee6518b5 100644 --- a/BuildingBlocks/src/BuildingBlocks.API/Mvc/ModelBinders/GenericArrayModelBinder.cs +++ b/BuildingBlocks/src/BuildingBlocks.API/Mvc/ModelBinders/GenericArrayModelBinder.cs @@ -18,7 +18,7 @@ public class GenericArrayModelBinder : IModelBinder public Task BindModelAsync(ModelBindingContext bindingContext) { var elementType = bindingContext.ModelType.GetElementType()!; - var templates = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType))!; + var items = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(elementType))!; var query = bindingContext.HttpContext.Request.Query; for (var i = 0; ; i++) @@ -29,7 +29,7 @@ public Task BindModelAsync(ModelBindingContext bindingContext) var queryValueFound = false; foreach (var property in properties) { - var key = $"templates.{i}.{property.Name.ToLower()}"; + var key = $"{bindingContext.ModelName}.{i}.{property.Name.ToLower()}"; if (!query.TryGetValue(key, out var queryValue)) continue; @@ -49,14 +49,14 @@ public Task BindModelAsync(ModelBindingContext bindingContext) if (!queryValueFound) break; - templates.Add(instance); + items.Add(instance); } - var resultArray = Array.CreateInstance(elementType, templates.Count); + var resultArray = Array.CreateInstance(elementType, items.Count); - for (var i = 0; i < templates.Count; i++) + for (var i = 0; i < items.Count; i++) { - resultArray.SetValue(templates[i], i); + resultArray.SetValue(items[i], i); } bindingContext.Result = ModelBindingResult.Success(resultArray); diff --git a/Modules/Tokens/src/Tokens.ConsumerApi/Controllers/TokensController.cs b/Modules/Tokens/src/Tokens.ConsumerApi/Controllers/TokensController.cs index 8e037fa8bc..c4c2b766ac 100644 --- a/Modules/Tokens/src/Tokens.ConsumerApi/Controllers/TokensController.cs +++ b/Modules/Tokens/src/Tokens.ConsumerApi/Controllers/TokensController.cs @@ -24,12 +24,10 @@ namespace Backbone.Modules.Tokens.ConsumerApi.Controllers; public class TokensController : ApiControllerBase { private readonly ApplicationOptions _options; - private readonly JsonSerializerOptions _jsonSerializerOptions; - public TokensController(IMediator mediator, IOptions options, IOptions jsonOptions) : base(mediator) + public TokensController(IMediator mediator, IOptions options) : base(mediator) { _options = options.Value; - _jsonSerializerOptions = jsonOptions.Value.JsonSerializerOptions; } [HttpPost] @@ -52,28 +50,14 @@ public async Task GetToken([FromRoute] string id, [FromQuery] byt [HttpGet] [ProducesResponseType(typeof(PagedHttpResponseEnvelope), StatusCodes.Status200OK)] - public async Task ListTokens([FromQuery] PaginationFilter paginationFilter, [FromQuery] string? tokens, + public async Task ListTokens([FromQuery] PaginationFilter paginationFilter, [FromQuery] ListTokensQueryItem[]? tokens, [FromQuery] IEnumerable ids, CancellationToken cancellationToken) { - List? tokenQueryItems; + // We keep this code for backwards compatibility reasons. In a few months the `templates` + // parameter will become required, and the fallback to `ids` will be removed. + tokens = tokens is { Length: > 0 } ? tokens : ids.Select(id => new ListTokensQueryItem { Id = id }).ToArray(); - if (tokens != null) - { - try - { - tokenQueryItems = JsonSerializer.Deserialize>(tokens, _jsonSerializerOptions); - } - catch (JsonException ex) - { - throw new ApplicationException(GenericApplicationErrors.Validation.InputCannotBeParsed(ex.Message)); - } - } - else - { - tokenQueryItems = ids.Select(id => new ListTokensQueryItem { Id = id }).ToList(); - } - - var request = new ListTokensQuery(paginationFilter, tokenQueryItems); + var request = new ListTokensQuery(paginationFilter, tokens); paginationFilter.PageSize ??= _options.Pagination.DefaultPageSize; diff --git a/Sdks/ConsumerApi.Sdk/src/Endpoints/Tokens/TokensEndpoint.cs b/Sdks/ConsumerApi.Sdk/src/Endpoints/Tokens/TokensEndpoint.cs index d36f871584..47729d3b34 100644 --- a/Sdks/ConsumerApi.Sdk/src/Endpoints/Tokens/TokensEndpoint.cs +++ b/Sdks/ConsumerApi.Sdk/src/Endpoints/Tokens/TokensEndpoint.cs @@ -25,12 +25,23 @@ public async Task> ListTokens(PaginationFilter? public async Task> ListTokens(IEnumerable queryItems, PaginationFilter? pagination = null) { - return await _client + var request = _client .Request(HttpMethod.Get, $"api/{API_VERSION}/Tokens") .Authenticate() - .WithPagination(pagination) - .AddQueryParameter("tokens", queryItems) - .Execute(); + .WithPagination(pagination); + + var i = 0; + foreach (var queryItem in queryItems) + { + request.AddQueryParameter($"tokens.{i}.id", queryItem.Id); + + if (queryItem.Password != null) + request.AddQueryParameter($"tokens.{i}.password", queryItem.Password); + + i++; + } + + return await request.Execute(); } public async Task> GetTokenUnauthenticated(string id)