Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions EstateReportingAPI.BusinessLogic/IReportingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IReportingManager{
Task<List<Merchant>> GetMerchants(Guid estateId, CancellationToken cancellationToken);
Task<MerchantKpi> GetMerchantsTransactionKpis(Guid estateId, CancellationToken cancellationToken);
Task<List<Operator>> GetOperators(Guid estateId, CancellationToken cancellationToken);
Task<List<ResponseCode>> GetResponseCodes(Guid estateId, CancellationToken cancellationToken);
Task<TodaysSales> GetTodaysFailedSales(Guid estateId, DateTime comparisonDate, String responseCode, CancellationToken cancellationToken);
Task<TodaysSales> GetTodaysSales(Guid estateId, DateTime comparisonDate, CancellationToken cancellationToken);
Task<List<TodaysSalesCountByHour>> GetTodaysSalesCountByHour(Guid estateId, DateTime comparisonDate, CancellationToken cancellationToken);
Expand Down
14 changes: 14 additions & 0 deletions EstateReportingAPI.BusinessLogic/ReportingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@ public async Task<MerchantKpi> GetMerchantsTransactionKpis(Guid estateId, Cancel
return response;
}

public async Task<List<ResponseCode>> GetResponseCodes(Guid estateId, CancellationToken cancellationToken){
EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken);
List<ResponseCode> response = new List<ResponseCode>();

List<ResponseCodes> responseCodes = await context.ResponseCodes.ToListAsync(cancellationToken);

responseCodes.ForEach(r => response.Add(new ResponseCode{
Code = r.ResponseCode,
Description = r.Description
}));

return response;
}

public async Task<TodaysSales> GetTodaysFailedSales(Guid estateId, DateTime comparisonDate, String responseCode, CancellationToken cancellationToken){
EstateManagementGenericContext? context = await this.ContextFactory.GetContext(estateId, ReportingManager.ConnectionStringIdentifier, cancellationToken);

Expand Down
8 changes: 8 additions & 0 deletions EstateReportingAPI.DataTrasferObjects/ResponseCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace EstateReportingAPI.DataTrasferObjects{
using System;

public class ResponseCode{
public Int32 Code { get; set; }
public String Description { get; set; }
}
}
23 changes: 23 additions & 0 deletions EstateReportingAPI.IntegrationTests/DatabaseHelper.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace EstateReportingAPI.IntegrationTests;

using System.Text;
using EstateManagement.Database.Contexts;
using EstateManagement.Database.Entities;
using EstateManagement.Database.Migrations.MySql;
using k8s.KubeConfigModels;
using Microsoft.EntityFrameworkCore;

public class DatabaseHelper{
Expand All @@ -12,6 +14,27 @@ public DatabaseHelper(EstateManagementGenericContext context){
this.Context = context;
}

public async Task AddResponseCode(Int32 code, String description){
await this.Context.Database.OpenConnectionAsync(CancellationToken.None);
try{
StringBuilder builder = new StringBuilder();
builder.AppendLine("SET IDENTITY_INSERT dbo.ResponseCodes ON");
//await this.Context.Database.ExecuteSqlRawAsync("SET IDENTITY_INSERT dbo.ResponseCodes ON", CancellationToken.None);
String sql = $"insert into dbo.ResponseCodes(ResponseCode, Description) SELECT {code}, '{description}'";
builder.AppendLine(sql);
builder.AppendLine("SET IDENTITY_INSERT dbo.ResponseCodes OFF");
//await this.Context.Database.ExecuteSqlRawAsync(sql, CancellationToken.None);
//await this.Context.Database.ExecuteSqlRawAsync("SET IDENTITY_INSERT dbo.ResponseCodes OFF", CancellationToken.None);
await this.Context.Database.ExecuteSqlRawAsync(builder.ToString(), CancellationToken.None);
}
finally
{
await this.Context.Database.CloseConnectionAsync();
}

var x = await this.Context.ResponseCodes.ToListAsync(CancellationToken.None);
}

public async Task AddCalendarYear(Int32 year){
List<DateTime> datesInYear = this.GetDatesForYear(year);
await this.AddCalendarDates(datesInYear);
Expand Down
45 changes: 45 additions & 0 deletions EstateReportingAPI.IntegrationTests/DimensionControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
using Common;
using DataTrasferObjects;
using EstateManagement.Database.Contexts;
using EstateReportingAPI.Models;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Newtonsoft.Json;
using Shouldly;
using Xunit;
using Merchant = DataTrasferObjects.Merchant;
using Operator = DataTrasferObjects.Operator;
using ResponseCode = DataTrasferObjects.ResponseCode;

public class DimensionsControllerTests :ControllerTestsBase, IDisposable{

Expand Down Expand Up @@ -232,6 +236,47 @@ public async Task DimensionsController_GetOperators_OperatorsReturned()
operators.Any(o => o.Name == "Operator3").ShouldBeTrue();
}


[Fact]
public async Task DimensionsController_GetResponseCodes_ResponseCodesReturned()
{
EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{this.TestId.ToString()}"));

DatabaseHelper helper = new DatabaseHelper(context);
await helper.AddResponseCode(0, "Success");
await helper.AddResponseCode(1000, "Unknown Device");
await helper.AddResponseCode(1001, "Unknown Estate");
await helper.AddResponseCode(1002, "Unknown Merchant");
await helper.AddResponseCode(1003, "No Devices Configured");



HttpResponseMessage response = await this.CreateAndSendHttpRequestMessage("api/dimensions/responsecodes");

String content = await response.Content.ReadAsStringAsync(CancellationToken.None);
List<ResponseCode>? responseCodes = JsonConvert.DeserializeObject<List<ResponseCode>>(content);
responseCodes.Count.ShouldBe(5);
responseCodes.Any(o => o.Code == 0).ShouldBeTrue();
responseCodes.Any(o => o.Code == 1000).ShouldBeTrue();
responseCodes.Any(o => o.Code == 1001).ShouldBeTrue();
responseCodes.Any(o => o.Code == 1002).ShouldBeTrue();
responseCodes.Any(o => o.Code == 1003).ShouldBeTrue();
}

[Fact]
public async Task DimensionsController_GetResponseCodes_NoData_NoResponseCodesReturned()
{
EstateManagementGenericContext context = new EstateManagementSqlServerContext(GetLocalConnectionString($"EstateReportingReadModel{this.TestId.ToString()}"));

DatabaseHelper helper = new DatabaseHelper(context);

HttpResponseMessage response = await this.CreateAndSendHttpRequestMessage("api/dimensions/responsecodes");

String content = await response.Content.ReadAsStringAsync(CancellationToken.None);
List<ResponseCode>? responseCodes = JsonConvert.DeserializeObject<List<ResponseCode>>(content);
responseCodes.ShouldBeEmpty();
}

#endregion

//public void Dispose(){
Expand Down
7 changes: 7 additions & 0 deletions EstateReportingAPI.Models/ResponseCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EstateReportingAPI.Models;

public class ResponseCode
{
public Int32 Code { get; set; }
public String Description { get; set; }
}
16 changes: 16 additions & 0 deletions EstateReportingAPI/Controllers/DimensionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ public async Task<IActionResult> GetOperators([FromHeader] Guid estateId, Cancel

return this.Ok(response.OrderBy(m => m.Name));
}

[HttpGet]
[Route("responsecodes")]
public async Task<IActionResult> GetResponseCodes([FromHeader] Guid estateId, CancellationToken cancellationToken)
{
List<Models.ResponseCode> responseCodes = await this.ReportingManager.GetResponseCodes(estateId, cancellationToken);

List<ResponseCode> response = new List<ResponseCode>();

responseCodes.ForEach(o => response.Add(new ResponseCode{
Code = o.Code,
Description = o.Description
}));

return this.Ok(response.OrderBy(m => m.Code));
}
}


Expand Down