dev
This commit is contained in:
parent
b0c537fef8
commit
7bbace5cb2
|
|
@ -14,8 +14,8 @@ namespace GameData.UnitTests
|
||||||
[Test]
|
[Test]
|
||||||
public void Test1()
|
public void Test1()
|
||||||
{
|
{
|
||||||
var client = new ExpenseRepository(null);
|
//var client = new ExpenseRepository(null, null, null);
|
||||||
var test = client.GetAll();
|
//var test = client.GetAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using GameData.Repository;
|
using GameData.Repository;
|
||||||
|
using GameModel.Settings;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
@ -19,10 +20,14 @@ namespace GameData
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly HttpClient client;
|
private readonly HttpClient client;
|
||||||
private readonly string _apiKey = "9wIqngBjwR_l2f89D0EEAN1ldrcXUl6c";
|
|
||||||
private readonly string Api = "https://directus.straso.com/";
|
private readonly AppSettings _appSettings;
|
||||||
public ApiClient()
|
private readonly string Api;
|
||||||
|
|
||||||
|
public ApiClient(AppSettings appSettings)
|
||||||
{
|
{
|
||||||
|
_appSettings = appSettings;
|
||||||
|
|
||||||
client = new HttpClient
|
client = new HttpClient
|
||||||
{
|
{
|
||||||
Timeout = TimeSpan.FromMinutes(1)
|
Timeout = TimeSpan.FromMinutes(1)
|
||||||
|
|
@ -33,10 +38,11 @@ namespace GameData
|
||||||
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
|
||||||
client.DefaultRequestHeaders
|
client.DefaultRequestHeaders
|
||||||
.Authorization = new AuthenticationHeaderValue("Bearer", _apiKey);
|
.Authorization = new AuthenticationHeaderValue("Bearer", _appSettings.ApiToken);
|
||||||
|
|
||||||
//client.DefaultRequestHeaders.Add("Api-AppInfo", "KrahApp;" + Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
//client.DefaultRequestHeaders.Add("Api-AppInfo", "KrahApp;" + Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||||
|
|
||||||
|
Api = _appSettings.ApiBaseUrl;
|
||||||
if (!Api.EndsWith("/"))
|
if (!Api.EndsWith("/"))
|
||||||
{
|
{
|
||||||
Api += "/";
|
Api += "/";
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,13 @@ namespace GameData.Repository
|
||||||
{
|
{
|
||||||
readonly ILogger<ExpenseRepository> _log;
|
readonly ILogger<ExpenseRepository> _log;
|
||||||
private ApiClient _client;
|
private ApiClient _client;
|
||||||
private AppSettings _appSettings;
|
|
||||||
string Url => "items/expense";
|
string Url => "items/expense";
|
||||||
|
|
||||||
public ExpenseRepository(ILogger<ExpenseRepository> log, AppSettings appSettings)
|
public ExpenseRepository(ILogger<ExpenseRepository> log, ApiClient apiClient)
|
||||||
{
|
{
|
||||||
_appSettings = appSettings;
|
|
||||||
_log = log;
|
_log = log;
|
||||||
_client = new ApiClient();
|
_client = apiClient;
|
||||||
|
|
||||||
_log?.LogWarning("TESTWARN");
|
_log?.LogWarning("TESTWARN");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace GameHandler
|
||||||
{
|
{
|
||||||
public class GameService
|
public class GameService
|
||||||
{
|
{
|
||||||
private IContainer _container { get; set; }
|
private IContainer _rootContainer { get; set; }
|
||||||
private bool _isStarted = false;
|
private bool _isStarted = false;
|
||||||
private ILifetimeScope _scope;
|
private ILifetimeScope _scope;
|
||||||
private IGameHandler _gh;
|
private IGameHandler _gh;
|
||||||
|
|
@ -32,9 +32,9 @@ namespace GameHandler
|
||||||
|
|
||||||
private IExpenseRepository _expenseRepository { get => _scope.Resolve<IExpenseRepository>(); }
|
private IExpenseRepository _expenseRepository { get => _scope.Resolve<IExpenseRepository>(); }
|
||||||
|
|
||||||
public GameService(IContainer container =null)
|
public GameService(IContainer rootContainer = null)
|
||||||
{
|
{
|
||||||
_container = container;
|
_rootContainer = rootContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ThrowModeName
|
public string ThrowModeName
|
||||||
|
|
@ -64,7 +64,7 @@ namespace GameHandler
|
||||||
}
|
}
|
||||||
_isStarted = true;
|
_isStarted = true;
|
||||||
|
|
||||||
_scope = _container?.BeginLifetimeScope();
|
_scope = _rootContainer?.BeginLifetimeScope();
|
||||||
_gh = this.GetGameHandler(gameName);
|
_gh = this.GetGameHandler(gameName);
|
||||||
var gm = _gh.InitGameModel(playerIds, gameSettings);
|
var gm = _gh.InitGameModel(playerIds, gameSettings);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,7 @@ namespace GameModel.Settings
|
||||||
public class AppSettings
|
public class AppSettings
|
||||||
{
|
{
|
||||||
public string ApiToken { get; set; }
|
public string ApiToken { get; set; }
|
||||||
|
|
||||||
|
public string ApiBaseUrl { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,11 +48,11 @@ Autofac.IContainer Register()
|
||||||
{
|
{
|
||||||
var builder = new ContainerBuilder();
|
var builder = new ContainerBuilder();
|
||||||
|
|
||||||
//builder.Populate(serviceCollection);
|
|
||||||
RegisterAppsettings(builder);
|
RegisterAppsettings(builder);
|
||||||
|
|
||||||
RegisterLogging(builder);
|
RegisterLogging(builder);
|
||||||
|
|
||||||
|
builder.RegisterType<ApiClient>();
|
||||||
builder.RegisterType<ExpenseRepository>().As<IExpenseRepository>();
|
builder.RegisterType<ExpenseRepository>().As<IExpenseRepository>();
|
||||||
return builder.Build();
|
return builder.Build();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"AppSettings": {
|
"AppSettings": {
|
||||||
"ApiToken": "LT9iPa1EuaaRB0h2VL45fVPLLK7Rt0wb"
|
"ApiToken": "LT9iPa1EuaaRB0h2VL45fVPLLK7Rt0wb",
|
||||||
|
"ApiBaseUrl": "https://directus.straso.com/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue