Skip to content

Commit

Permalink
Merge pull request #27 from masastack/feature/stack-config
Browse files Browse the repository at this point in the history
♻ refactor(wasm): OpenApiService add getStackConfigAsync and getI18NC…
  • Loading branch information
wzh425 authored Dec 16, 2024
2 parents 9a9affe + 9aee590 commit a04b743
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

public interface IOpenApiService
{
Task<T> GetPublicConfigAsync<T>(string configObject, string environment = "", string cluster = "") where T : class, new();
Task<Dictionary<string, string>> GetStackConfigAsync(string environment = "", string cluster = "");

Task<Dictionary<string, string>> GetI18NConfigAsync(string culture, string environment = "", string cluster = "");
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public virtual async Task InitializeAsync()
{
if (_dccClient != null)
{
Section = await _dccClient.OpenApiService.GetPublicConfigAsync<Dictionary<string, string>>(Configs.DEFAULT_CONFIG_NAME);
Section = await _dccClient.OpenApiService.GetStackConfigAsync(Configs.DEFAULT_CONFIG_NAME);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static class MasaStackConfigUtils
{
public static async Task<Dictionary<string, string>> GetDefaultPublicConfigAsync(IDccClient client, string environment)
{
var publicConfig = await client.OpenApiService.GetPublicConfigAsync<Dictionary<string, string>>(Configs.DEFAULT_CONFIG_NAME, environment);
var publicConfig = await client.OpenApiService.GetStackConfigAsync(Configs.DEFAULT_CONFIG_NAME, environment);
return publicConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,49 @@ public OpenApiService(ICaller caller, IMultiEnvironmentUserContext environmentUs
_masaStackConfig = masaStackConfig;
}

public async Task<T> GetPublicConfigAsync<T>(string configObject, string environment, string cluster) where T : class, new()
public async Task<Dictionary<string, string>> GetStackConfigAsync(string environment, string cluster)
{
if (environment.IsNullOrEmpty())
{
environment = _environmentUserContext.Environment ?? string.Empty;
}

if (environment.IsNullOrEmpty())
{
environment = _masaStackConfig.Environment;
}

if (cluster.IsNullOrEmpty())
{
cluster = Configs.DEFAULT_CLUSTER;
}

var requestUri = $"open-api/releasing/{environment}/{cluster}/stack-config";
var result = await _caller.GetAsync<Dictionary<string, string>>(requestUri);

return result ?? new();
}

public async Task<Dictionary<string, string>> GetI18NConfigAsync(string culture, string environment, string cluster)
{
if (environment.IsNullOrEmpty())
{
environment = _environmentUserContext.Environment ?? string.Empty;
}

if (environment.IsNullOrEmpty())
{
environment = _masaStackConfig.Environment;
}

if (cluster.IsNullOrEmpty())
{
cluster = Configs.DEFAULT_CLUSTER;
}
var requestUri = $"open-api/releasing/{environment}/{cluster}/publicConfig/{configObject}";
var result = await _caller.GetAsync<T>(requestUri);

return result ?? new T();
var requestUri = $"open-api/releasing/{environment}/{cluster}/i18n/{culture}";
var result = await _caller.GetAsync<Dictionary<string, string>>(requestUri);

return result ?? new();
}
}

0 comments on commit a04b743

Please sign in to comment.