42 lines
1.5 KiB
C#
Raw Normal View History

2018-12-17 14:31:19 +01:00
using ApiGw_Base.Enums;
using Microsoft.AspNetCore.Mvc;
using System;
using System.IO;
using System.Text;
namespace ApiGw_Base.Controllers
{
[Route("[controller]")]
[ApiController]
public class ConfigurationController : ControllerBase
{
[HttpGet("mobile/marketing")]
public IActionResult MobileMarketing() => ReadConfigurationFile(Channel.Mobile, ChannelType.Marketing);
2018-12-17 14:31:19 +01:00
[HttpGet("mobile/shopping")]
public IActionResult MobileShopping() => ReadConfigurationFile(Channel.Mobile, ChannelType.Shopping);
2018-12-17 14:31:19 +01:00
[HttpGet("web/marketing")]
public IActionResult WebMarketing() => ReadConfigurationFile(Channel.Web, ChannelType.Marketing);
2018-12-17 14:31:19 +01:00
[HttpGet("web/shopping")]
public IActionResult WebShopping() => ReadConfigurationFile(Channel.Web, ChannelType.Shopping);
2018-12-17 14:31:19 +01:00
private IActionResult ReadConfigurationFile(Channel channel, ChannelType channelType)
2018-12-17 14:31:19 +01:00
{
var path = $"{AppDomain.CurrentDomain.BaseDirectory}/Configurations/configuration.{channel}.Bff.{channelType}.json";
2018-12-17 14:47:19 +01:00
using (var streamReader = new StreamReader(path, Encoding.UTF8))
2018-12-17 14:31:19 +01:00
{
2018-12-17 14:47:19 +01:00
var jsonString = streamReader.ReadToEnd();
2018-12-17 14:31:19 +01:00
2018-12-17 14:47:19 +01:00
if (string.IsNullOrWhiteSpace(jsonString))
2018-12-17 14:31:19 +01:00
{
return BadRequest($"Configuration file 'configuration.{channel}.Bff.{channelType}.json' not found");
2018-12-17 14:31:19 +01:00
}
2018-12-17 14:47:19 +01:00
return Ok(jsonString);
2018-12-17 14:31:19 +01:00
}
}
}
}