You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

42 lines
1.5 KiB

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);
[HttpGet("mobile/shopping")]
public IActionResult MobileShopping() => ReadConfigurationFile(Channel.Mobile, ChannelType.Shopping);
[HttpGet("web/marketing")]
public IActionResult WebMarketing() => ReadConfigurationFile(Channel.Web, ChannelType.Marketing);
[HttpGet("web/shopping")]
public IActionResult WebShopping() => ReadConfigurationFile(Channel.Web, ChannelType.Shopping);
private IActionResult ReadConfigurationFile(Channel channel, ChannelType channelType)
{
var path = $"{AppDomain.CurrentDomain.BaseDirectory}/Configurations/configuration.{channel}.Bff.{channelType}.json";
using (var streamReader = new StreamReader(path, Encoding.UTF8))
{
var jsonString = streamReader.ReadToEnd();
if (string.IsNullOrWhiteSpace(jsonString))
{
return BadRequest($"Configuration file 'configuration.{channel}.Bff.{channelType}.json' not found");
}
return Ok(jsonString);
}
}
}
}