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