-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add backoffice projections status
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/StreetNameRegistry.Projector/BackOffice/BackOfficeController.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,56 @@ | ||
namespace StreetNameRegistry.Projector.BackOffice | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Be.Vlaanderen.Basisregisters.Api; | ||
using Be.Vlaanderen.Basisregisters.ProjectionHandling.Runner.ProjectionStates; | ||
using Dapper; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Data.SqlClient; | ||
using Microsoft.Extensions.Configuration; | ||
using SqlStreamStore; | ||
|
||
[ApiVersion("1.0")] | ||
[ApiRoute("backoffice")] | ||
public class BackOfficeController : ApiController | ||
{ | ||
private const string? BackOfficeConnectionStringKey = "Events"; | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> Get( | ||
[FromServices] IConfiguration configuration, | ||
[FromServices] IStreamStore streamStore, | ||
CancellationToken cancellationToken) | ||
{ | ||
var streamPosition = await streamStore.ReadHeadPosition(cancellationToken); | ||
|
||
List<BackOfficeStatusResponse> response; | ||
await using (var sqlConnection = new SqlConnection(configuration.GetConnectionString(BackOfficeConnectionStringKey))) | ||
{ | ||
var result = | ||
await sqlConnection.QueryAsync<ProjectionStateItem>( | ||
"SELECT * FROM [StreetNameRegistryBackOfficeProjections].[ProjectionStates]", cancellationToken); | ||
|
||
response = result.Select(x => new BackOfficeStatusResponse(x, streamPosition)).ToList(); | ||
} | ||
|
||
return Ok(response); | ||
} | ||
} | ||
|
||
public class BackOfficeStatusResponse | ||
{ | ||
public long MaxPosition { get; set; } | ||
public string ProjectionName { get; set; } | ||
public long Position { get; set; } | ||
|
||
public BackOfficeStatusResponse(ProjectionStateItem projectionStateItem, long maxPosition) | ||
{ | ||
MaxPosition = maxPosition; | ||
ProjectionName = projectionStateItem.Name; | ||
Position = projectionStateItem.Position; | ||
} | ||
} | ||
} |