-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ABL-174-admin-api-send-announcements-to-spec…
…ify-identities
- Loading branch information
Showing
99 changed files
with
527 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
meta { | ||
name: /Tokens | ||
type: http | ||
seq: 1 | ||
} | ||
|
||
get { | ||
url: {{baseUrl}}/Tokens?createdBy=did:e:localhost:dids:c179861648989f28d189c9&PageNumber=1&PageSize=1 | ||
body: none | ||
auth: inherit | ||
} | ||
|
||
params:query { | ||
createdBy: did:e:localhost:dids:c179861648989f28d189c9 | ||
PageNumber: 1 | ||
PageSize: 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
Applications/AdminApi/src/AdminApi/Configuration/TokensConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Backbone.Modules.Tokens.Application; | ||
|
||
namespace Backbone.AdminApi.Configuration; | ||
|
||
public class TokensConfiguration | ||
{ | ||
[Required] | ||
public ApplicationOptions Application { get; set; } = new(); | ||
|
||
[Required] | ||
public InfrastructureConfiguration Infrastructure { get; set; } = new(); | ||
|
||
public class InfrastructureConfiguration | ||
{ | ||
[Required] | ||
public SqlDatabaseConfiguration SqlDatabase { get; set; } = new(); | ||
|
||
public class SqlDatabaseConfiguration | ||
{ | ||
[Required] | ||
[MinLength(1)] | ||
[RegularExpression("SqlServer|Postgres")] | ||
public string Provider { get; set; } = string.Empty; | ||
|
||
[Required] | ||
[MinLength(1)] | ||
public string ConnectionString { get; set; } = string.Empty; | ||
|
||
[Required] | ||
public bool EnableHealthCheck { get; set; } = true; | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Applications/AdminApi/src/AdminApi/Controllers/TokensController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Backbone.BuildingBlocks.API.Mvc; | ||
using Backbone.BuildingBlocks.Application.Abstractions.Exceptions; | ||
using Backbone.BuildingBlocks.Application.Pagination; | ||
using Backbone.Modules.Tokens.Application; | ||
using Backbone.Modules.Tokens.Application.Tokens.DTOs; | ||
using Backbone.Modules.Tokens.Application.Tokens.Queries.ListTokensByIdentity; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Options; | ||
using ApplicationException = Backbone.BuildingBlocks.Application.Abstractions.Exceptions.ApplicationException; | ||
|
||
namespace Backbone.AdminApi.Controllers; | ||
|
||
[Route("api/v1/[controller]")] | ||
[Authorize("ApiKey")] | ||
public class TokensController(IMediator mediator, IOptions<ApplicationOptions> options) : ApiControllerBase(mediator) | ||
{ | ||
[HttpGet] | ||
[ProducesResponseType(typeof(List<TokenDTO>), StatusCodes.Status200OK)] | ||
public async Task<IActionResult> ListTokensByIdentity([FromQuery] PaginationFilter paginationFilter, [FromQuery] string createdBy, CancellationToken cancellationToken) | ||
{ | ||
if (paginationFilter.PageSize != null) | ||
{ | ||
var maxPageSize = options.Value.Pagination.MaxPageSize; | ||
|
||
if (paginationFilter.PageSize > maxPageSize) | ||
{ | ||
throw new ApplicationException(GenericApplicationErrors.Validation.InvalidPageSize(maxPageSize)); | ||
} | ||
} | ||
|
||
var request = new ListTokensByIdentityQuery(createdBy, paginationFilter); | ||
var pagedResult = await _mediator.Send(request, cancellationToken); | ||
|
||
return Paged(pagedResult); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Applications/AdminApi/src/AdminApi/Extensions/TokensServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Backbone.AdminApi.Configuration; | ||
using Backbone.Modules.Tokens.Application.Extensions; | ||
using Backbone.Modules.Tokens.Infrastructure.Persistence; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Backbone.AdminApi.Extensions; | ||
|
||
public static class TokensServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddTokens(this IServiceCollection services, IConfiguration configuration) | ||
{ | ||
services.AddApplication(configuration.GetSection("Application")); | ||
|
||
services.ConfigureAndValidate<TokensConfiguration.InfrastructureConfiguration>(configuration.GetSection("Infrastructure").Bind); | ||
|
||
var infrastructureConfiguration = services.BuildServiceProvider().GetRequiredService<IOptions<TokensConfiguration.InfrastructureConfiguration>>().Value; | ||
|
||
services.AddPersistence(options => | ||
{ | ||
options.DbOptions.Provider = infrastructureConfiguration.SqlDatabase.Provider; | ||
options.DbOptions.DbConnectionString = infrastructureConfiguration.SqlDatabase.ConnectionString; | ||
}); | ||
|
||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
Applications/AdminApi/test/AdminApi.Tests.Integration/Features/Tokens/GET.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@Integration | ||
Feature: GET /Tokens?createdBy={identity-address} | ||
|
||
Listing all tokens of an identity that doesn't have any tokens | ||
|
||
Scenario: Get all Tokens for an identity with no tokens | ||
Given an identity with no tokens | ||
When a GET request is sent to the /Tokens endpoint with the identity's address | ||
Then the response status code is 200 (OK) | ||
And the response content is an empty array |
48 changes: 48 additions & 0 deletions
48
...cations/AdminApi/test/AdminApi.Tests.Integration/StepDefinitions/TokensStepDefinitions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Backbone.AdminApi.Sdk.Endpoints.Tokens.Response; | ||
using Backbone.AdminApi.Sdk.Services; | ||
using Backbone.AdminApi.Tests.Integration.Configuration; | ||
using Backbone.AdminApi.Tests.Integration.Extensions; | ||
using Backbone.BuildingBlocks.SDK.Endpoints.Common.Types; | ||
using Microsoft.Extensions.Options; | ||
using PaginationFilter = Backbone.BuildingBlocks.SDK.Endpoints.Common.Types.PaginationFilter; | ||
|
||
|
||
namespace Backbone.AdminApi.Tests.Integration.StepDefinitions; | ||
|
||
[Binding] | ||
[Scope(Feature = "GET /Tokens?createdBy={identity-address}")] | ||
internal class TokensStepDefinitions(HttpClientFactory factory, IOptions<HttpClientOptions> options) : BaseStepDefinitions(factory, options) | ||
{ | ||
private ApiResponse<ListTokensTestResponse> _listTokensResponse = null!; | ||
private string _newIdentityAddress = string.Empty; | ||
|
||
[Given(@"an identity with no tokens")] | ||
public async Task GivenAnIdentityWithNoTokens() | ||
{ | ||
var createIdentityResponse = await IdentityCreationHelper.CreateIdentity(_client); | ||
|
||
createIdentityResponse.Should().BeASuccess(); | ||
|
||
_newIdentityAddress = createIdentityResponse.Result!.Address; | ||
} | ||
|
||
|
||
[When(@"a GET request is sent to the /Tokens endpoint with the identity's address")] | ||
public async Task WhenAGETRequestIsSentToTheTokensEndpointWithTheIdentitysAddress() | ||
{ | ||
_listTokensResponse = await _client.Tokens.ListTokensByIdentity(new PaginationFilter { PageNumber = 1, PageSize = 5 }, _newIdentityAddress, CancellationToken.None); | ||
} | ||
|
||
[Then(@"the response status code is (\d+) \(.+\)")] | ||
public void ThenTheResponseStatusCodeIs(int expectedStatusCode) | ||
{ | ||
((int)_listTokensResponse!.Status).Should().Be(expectedStatusCode); | ||
} | ||
|
||
|
||
[Then(@"the response content is an empty array")] | ||
public void ThenTheResponseContentIsAnEmptyArray() | ||
{ | ||
_listTokensResponse.Result!.Count.Should().Be(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.