diff --git a/src/MicroserviceComponents/BondiCompetition/CleanMicroserviceSystem.BondiCompetition.WebAPI/Controllers/AccountController.cs b/src/MicroserviceComponents/BondiCompetition/CleanMicroserviceSystem.BondiCompetition.WebAPI/Controllers/AccountController.cs index 9e3340f0..a47e75e7 100644 --- a/src/MicroserviceComponents/BondiCompetition/CleanMicroserviceSystem.BondiCompetition.WebAPI/Controllers/AccountController.cs +++ b/src/MicroserviceComponents/BondiCompetition/CleanMicroserviceSystem.BondiCompetition.WebAPI/Controllers/AccountController.cs @@ -17,13 +17,13 @@ public class AccountController : Controller { private readonly ILogger logger; private readonly IAccountRepository accountRepository; - private readonly IOptionsSnapshot tradingCompetitionOption; + private readonly IOptionsMonitor tradingCompetitionOption; private readonly ITradingCalendar tradingCalendar; public AccountController( ILogger logger, IAccountRepository accountRepository, - IOptionsSnapshot tradingCompetitionOption, + IOptionsMonitor tradingCompetitionOption, ITradingCalendar tradingCalendar) { this.logger = logger; @@ -36,6 +36,11 @@ public AccountController( public async Task> GetAccount() { var userName = this.HttpContext.User?.Identity?.Name; + if(string.IsNullOrEmpty(userName)) + { + return this.BadRequest("User name is empty."); + } + this.logger.LogInformation($"Get account for user: {userName}"); var account = await this.accountRepository.FindAccountByUserAsync(userName); if (account is null) @@ -43,15 +48,15 @@ public async Task> GetAccount() account = new Account() { Name = userName, - InitialCapital = this.tradingCompetitionOption.Value.InitialCapital, + InitialCapital = this.tradingCompetitionOption.CurrentValue.InitialCapital, }; await this.accountRepository.CreateAccountAsync(account); this.logger.LogInformation($"Account created for user: {userName}, {account.Id}"); } var date = this.tradingCalendar.GetCurrentTradingDate(); - var startTime = this.tradingCompetitionOption.Value.StartTime; - var endTime = this.tradingCompetitionOption.Value.EndTime; + var startTime = this.tradingCompetitionOption.CurrentValue.StartTime; + var endTime = this.tradingCompetitionOption.CurrentValue.EndTime; var currentTime = TimeOnly.FromDateTime(DateTime.Now); var isTradingDate = this.tradingCalendar.IsTradingDate(date); var isTradingTime = startTime <= currentTime && currentTime <= endTime;