Skip to content

Commit

Permalink
feat: add backoffice projections status
Browse files Browse the repository at this point in the history
  • Loading branch information
emalfroy authored and ArneD committed Feb 7, 2024
1 parent 9a22996 commit 4854a84
Showing 1 changed file with 56 additions and 0 deletions.
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;
}
}
}

0 comments on commit 4854a84

Please sign in to comment.