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

This file was deleted.

181 changes: 14 additions & 167 deletions MobileConfiguration/Controllers/MobileConfigurationController.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using MobileConfiguration.Repository;
using Shared.Results.Web;

namespace MobileConfiguration.Controllers
{
using MobileConfiguration.DataTransferObjects;
using DataTransferObjects;
using Models;
using Newtonsoft.Json;
using Shared.Logger;
using ApplicationCentreConfiguration = Database.Entities.ApplicationCentreConfiguration;
using DTOHostAddress = DataTransferObjects.HostAddress;
using ModelHostAddress = Models.HostAddress;
using DTOLoggingLevel = DataTransferObjects.LoggingLevel;
using ModelLoggingLevel = Models.LoggingLevel;
using DTOServiceType = DataTransferObjects.ServiceType;
using ModelServiceType = Models.ServiceType;

[Route("api/[controller]")]
[ApiController]
Expand All @@ -25,181 +16,37 @@ public class TransactionMobileConfigurationController : ControllerBase
public TransactionMobileConfigurationController(IConfigurationRepository repository) {
this.Repository = repository;
}

[HttpPost]
public async Task<IActionResult> PostConfiguration([FromBody] Configuration configuration,
CancellationToken cancellationToken) {

// TODO: Add a factory
Models.MobileConfiguration configurationModel = new Models.MobileConfiguration {
ClientId = configuration.ClientId,
ClientSecret = configuration.ClientSecret,
ConfigurationType = ConfigurationType.TransactionMobile,
DeviceIdentifier = configuration.DeviceIdentifier,
EnableAutoUpdates = configuration.EnableAutoUpdates,
Id = configuration.Id,
HostAddresses = new List<Models.HostAddress>()
};

foreach (DTOHostAddress configurationHostAddress in configuration.HostAddresses) {
Models.HostAddress hostAddressModel = new Models.HostAddress {
Uri = configurationHostAddress.Uri,
};
hostAddressModel.ServiceType = configurationHostAddress.ServiceType switch
{
DTOServiceType.EstateManagement => ModelServiceType.EstateManagement,
DTOServiceType.TransactionProcessorAcl => ModelServiceType.TransactionProcessorAcl,
DTOServiceType.VoucherManagementAcl => ModelServiceType.VoucherManagementAcl,
_ => ModelServiceType.Security
};

configurationModel.HostAddresses.Add(hostAddressModel);
}
MobileConfiguration configurationModel = Factories.Factory.ToMobileConfiguration(configuration);

configurationModel.LogLevel = configuration.LogLevel switch {
DTOLoggingLevel.Debug => ModelLoggingLevel.Debug,
DTOLoggingLevel.Error => ModelLoggingLevel.Error,
DTOLoggingLevel.Fatal => ModelLoggingLevel.Fatal,
DTOLoggingLevel.Information => ModelLoggingLevel.Information,
DTOLoggingLevel.Trace => ModelLoggingLevel.Trace,
DTOLoggingLevel.Warning => ModelLoggingLevel.Warning,
_ => ModelLoggingLevel.Information
};
var result = await this.Repository.CreateConfiguration(configurationModel, cancellationToken);

await this.Repository.CreateConfiguration(configurationModel, cancellationToken);

// TODO: return "correct" response...
return this.Ok();
return result.ToActionResultX();
}

[HttpGet]
[Route("{id}")]
public async Task<IActionResult> GetConfiguration([FromRoute] String id, CancellationToken cancellationToken) {
Models.MobileConfiguration configurationModel = await this.Repository.GetConfiguration(ConfigurationType.TransactionMobile, id, cancellationToken);
// TODO: base this on the enum value???
ApplicationCentreConfiguration appCenterConfiguration = await this.Repository.GetAppCentreConfiguration("transactionMobilePOS", cancellationToken);

ConfigurationResponse response = new ConfigurationResponse {
HostAddresses = new List<DTOHostAddress>(),
Id = configurationModel.Id,
ClientSecret = configurationModel.ClientSecret,
DeviceIdentifier = configurationModel.DeviceIdentifier,
EnableAutoUpdates = configurationModel.EnableAutoUpdates,
ClientId = configurationModel.ClientId,
};

foreach (ModelHostAddress configurationHostAddress in configurationModel.HostAddresses)
{
DTOHostAddress hostAddress = new DTOHostAddress
{
Uri = configurationHostAddress.Uri,
};
hostAddress.ServiceType = configurationHostAddress.ServiceType switch
{
ModelServiceType.EstateManagement => DTOServiceType.EstateManagement,
ModelServiceType.TransactionProcessorAcl => DTOServiceType.TransactionProcessorAcl,
ModelServiceType.VoucherManagementAcl => DTOServiceType.VoucherManagementAcl,
_ => DTOServiceType.Security
};

response.HostAddresses.Add(hostAddress);
}

response.LogLevel = configurationModel.LogLevel switch
{
ModelLoggingLevel.Debug => DTOLoggingLevel.Debug,
ModelLoggingLevel.Error => DTOLoggingLevel.Error,
ModelLoggingLevel.Fatal => DTOLoggingLevel.Fatal,
ModelLoggingLevel.Information => DTOLoggingLevel.Information,
ModelLoggingLevel.Trace => DTOLoggingLevel.Trace,
ModelLoggingLevel.Warning => DTOLoggingLevel.Warning,
_ => DTOLoggingLevel.Information
};
MobileConfiguration configurationModel = await this.Repository.GetConfiguration(ConfigurationType.TransactionMobile, id, cancellationToken);

response.ApplicationCentreConfiguration = new DataTransferObjects.ApplicationCentreConfiguration() {
AndroidKey = appCenterConfiguration.AndroidKey,
ApplicationId = appCenterConfiguration.ApplicationId,
IosKey = appCenterConfiguration.IosKey,
MacosKey = appCenterConfiguration.MacosKey,
WindowsKey = appCenterConfiguration.WindowsKey,
};

// TODO: Convert to a DTO...
ConfigurationResponse response = Factories.Factory.ToConfigurationResponse(configurationModel);

return this.Ok(response);
}

[HttpPut]
public async Task<IActionResult> PutConfiguration(String id, Configuration configuration, CancellationToken cancellationToken)
{
Models.MobileConfiguration configurationModel = new Models.MobileConfiguration
{
ClientId = configuration.ClientId,
ClientSecret = configuration.ClientSecret,
ConfigurationType = ConfigurationType.TransactionMobile,
DeviceIdentifier = configuration.DeviceIdentifier,
EnableAutoUpdates = configuration.EnableAutoUpdates,
Id = configuration.Id,
HostAddresses = new List<Models.HostAddress>()
};

foreach (DTOHostAddress configurationHostAddress in configuration.HostAddresses)
{
Models.HostAddress hostAddressModel = new Models.HostAddress
{
Uri = configurationHostAddress.Uri,
};
hostAddressModel.ServiceType = configurationHostAddress.ServiceType switch
{
DTOServiceType.EstateManagement => ModelServiceType.EstateManagement,
DTOServiceType.TransactionProcessorAcl => ModelServiceType.TransactionProcessorAcl,
DTOServiceType.VoucherManagementAcl => ModelServiceType.VoucherManagementAcl,
_ => ModelServiceType.Security
};

configurationModel.HostAddresses.Add(hostAddressModel);
}

configurationModel.LogLevel = configuration.LogLevel switch
{
DTOLoggingLevel.Debug => ModelLoggingLevel.Debug,
DTOLoggingLevel.Error => ModelLoggingLevel.Error,
DTOLoggingLevel.Fatal => ModelLoggingLevel.Fatal,
DTOLoggingLevel.Information => ModelLoggingLevel.Information,
DTOLoggingLevel.Trace => ModelLoggingLevel.Trace,
DTOLoggingLevel.Warning => ModelLoggingLevel.Warning,
_ => ModelLoggingLevel.Information
};

await this.Repository.UpdateConfiguration(ConfigurationType.TransactionMobile, id, configurationModel, cancellationToken);

return this.Ok();
}
}

[Route("api/[controller]")]
[ApiController]
public class TransactionMobileLoggingController : ControllerBase
{
private readonly IConfigurationRepository Repository;

public TransactionMobileLoggingController() {
public async Task<IActionResult> PutConfiguration(String id, Configuration configuration, CancellationToken cancellationToken) {
MobileConfiguration configurationModel = Factories.Factory.ToMobileConfiguration(configuration);

}

[HttpPost]
public async Task<IActionResult> PostConfiguration([FromBody] List<LogMessage> logMessages,
CancellationToken cancellationToken) {

Logger.LogInformation(JsonConvert.SerializeObject(logMessages));
await this.Repository.UpdateConfiguration(ConfigurationType.TransactionMobile, id, configurationModel, cancellationToken);

// TODO: return "correct" response...
return this.Ok();
}
}

public class LogMessage
{
public DateTime EntryDateTime { get; set; }
public String LogLevel { get; set; }
public String Message { get; set; }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Mvc;
using MobileConfiguration.DataTransferObjects;
using MobileConfiguration.Repository;
using Newtonsoft.Json;
using Shared.Logger;

namespace MobileConfiguration.Controllers;

[Route("api/[controller]")]
[ApiController]
public class TransactionMobileLoggingController : ControllerBase
{
[HttpPost]
public async Task<IActionResult> PostConfiguration([FromBody] List<LogMessage> logMessages,

Check warning on line 14 in MobileConfiguration/Controllers/TransactionMobileLoggingController.cs

View workflow job for this annotation

GitHub Actions / Build and Test Pull Requests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
CancellationToken cancellationToken) {

Logger.LogInformation(JsonConvert.SerializeObject(logMessages));

// TODO: return "correct" response...
return this.Ok();
}
}
Loading
Loading