From e06a2e380d2c1fbec9cc5b29237ba288442ebfc6 Mon Sep 17 00:00:00 2001 From: "roi.ezra" Date: Sat, 21 Sep 2024 21:53:44 +0300 Subject: [PATCH] fixed --- .../Client/src/Dashboard/Dashboard.html | 2 +- .../Controllers/GeneralBetsController.cs | 10 +- Mundialito/Controllers/UsersController.cs | 12 +- Mundialito/Logic/GeneralBetsService.cs | 30 + Mundialito/Logic/TableBuilder.cs | 3 - Mundialito/Program.cs | 1 + Mundialito/Views/Home/Index.cshtml | 4 +- .../wwwroot/App/Dashboard/Dashboard.html | 2 +- ...> app-96f22219e28d4994f79433c0d1d5ec4c.js} | 10 +- .../app-d59627e3e8cd8f2d05420f29a89370ce.js | 2855 ----------------- ...pp-min-7650b9735dadd2976bd3e012a2ea28c6.js | 1 + ...pp-min-b9de64167c2b03c8f2f816e6e633631e.js | 1 - ...pp-min-dbea857653a57fb18c602c8a4373eee2.js | 1 - 13 files changed, 52 insertions(+), 2880 deletions(-) create mode 100644 Mundialito/Logic/GeneralBetsService.cs rename Mundialito/wwwroot/js/{app-06c454b6fe15193adf661d79a88ef6c0.js => app-96f22219e28d4994f79433c0d1d5ec4c.js} (99%) delete mode 100644 Mundialito/wwwroot/js/app-d59627e3e8cd8f2d05420f29a89370ce.js create mode 100644 Mundialito/wwwroot/js/app-min-7650b9735dadd2976bd3e012a2ea28c6.js delete mode 100644 Mundialito/wwwroot/js/app-min-b9de64167c2b03c8f2f816e6e633631e.js delete mode 100644 Mundialito/wwwroot/js/app-min-dbea857653a57fb18c602c8a4373eee2.js diff --git a/Mundialito/Client/src/Dashboard/Dashboard.html b/Mundialito/Client/src/Dashboard/Dashboard.html index 262603a..cd20639 100644 --- a/Mundialito/Client/src/Dashboard/Dashboard.html +++ b/Mundialito/Client/src/Dashboard/Dashboard.html @@ -268,7 +268,7 @@

{{user.Place}}. {{bet.OwnerName}} {{usersDic[bet.OwnerId].Points}} - {{bet.WinningTeam.Name}} + {{bet.WinningTeam.Name}} {{bet.GoldenBootPlayer.Name}} diff --git a/Mundialito/Controllers/GeneralBetsController.cs b/Mundialito/Controllers/GeneralBetsController.cs index b852081..a4b4588 100644 --- a/Mundialito/Controllers/GeneralBetsController.cs +++ b/Mundialito/Controllers/GeneralBetsController.cs @@ -25,9 +25,10 @@ public class GeneralBetsController : ControllerBase private readonly UserManager userManager; private readonly ITeamsRepository teamsRepository; private readonly IPlayersRepository playersRepository; + private readonly GeneralBetsService generalBetsService; private readonly ILogger logger; - public GeneralBetsController(ILogger logger, IGeneralBetsRepository generalBetsRepository, IDateTimeProvider dateTimeProvider, IActionLogsRepository actionLogsRepository, IHttpContextAccessor httpContextAccessor, TournamentTimesUtils tournamentTimesUtils, UserManager userManager, ITeamsRepository teamsRepository, IPlayersRepository playersRepository) + public GeneralBetsController(ILogger logger, IGeneralBetsRepository generalBetsRepository, IDateTimeProvider dateTimeProvider, IActionLogsRepository actionLogsRepository, IHttpContextAccessor httpContextAccessor, TournamentTimesUtils tournamentTimesUtils, UserManager userManager, ITeamsRepository teamsRepository, IPlayersRepository playersRepository, GeneralBetsService generalBetsService) { this.generalBetsRepository = generalBetsRepository; this.dateTimeProvider = dateTimeProvider; @@ -37,17 +38,18 @@ public GeneralBetsController(ILogger logger, IGeneralBets this.userManager = userManager; this.teamsRepository = teamsRepository; this.playersRepository = playersRepository; + this.generalBetsService = generalBetsService; this.logger = logger; } [HttpGet] public ActionResult> GetAllGeneralBets() { - if (!User.IsInRole("Admin") && dateTimeProvider.UTCNow < tournamentTimesUtils.GetGeneralBetsCloseTime()) + if (dateTimeProvider.UTCNow < tournamentTimesUtils.GetGeneralBetsCloseTime()) { return BadRequest(new ErrorMessage { Message = "General bets are still open for betting, you can't see other users bets yet" }); } - return Ok(generalBetsRepository.GetGeneralBets().Select(bet => + return Ok(generalBetsService.GetGeneralBets().Select(bet => new GeneralBetViewModel(bet, tournamentTimesUtils.GetGeneralBetsCloseTime())).OrderBy(bet => bet.OwnerName)); } @@ -68,7 +70,7 @@ public ActionResult GetUserGeneralBet(string username) { if (httpContextAccessor.HttpContext?.User.Identity.Name != username && dateTimeProvider.UTCNow < tournamentTimesUtils.GetGeneralBetsCloseTime()) return BadRequest(new ErrorMessage { Message = "General bets are still open for betting, you can't see other users bets yet" }); - var item = generalBetsRepository.GetUserGeneralBet(username); + var item = generalBetsService.GetUserGeneralBet(username); if (item == null) return NotFound(string.Format("User '{0}' dosen't have a general bet yet", username)); return Ok(new GeneralBetViewModel(item, tournamentTimesUtils.GetGeneralBetsCloseTime())); diff --git a/Mundialito/Controllers/UsersController.cs b/Mundialito/Controllers/UsersController.cs index 2f2d124..8f0229a 100644 --- a/Mundialito/Controllers/UsersController.cs +++ b/Mundialito/Controllers/UsersController.cs @@ -24,12 +24,12 @@ public class UsersController : ControllerBase private readonly UserManager userManager; private readonly IDateTimeProvider dateTimeProvider; private readonly TournamentTimesUtils tournamentTimesUtils; - private readonly IGeneralBetsRepository generalBetsRepository; + private readonly GeneralBetsService generalBetsService; private readonly TableBuilder tableBuilder; private readonly MundialitoDbContext mundialitoDbContext; private readonly ILogger logger; - public UsersController(ILogger logger, IActionLogsRepository actionLogsRepository, IHttpContextAccessor httpContextAccessor, UserManager userManager, IBetsRepository betsRepository, IDateTimeProvider dateTimeProvider, TournamentTimesUtils tournamentTimesUtils, IGeneralBetsRepository generalBetsRepository, TableBuilder tableBuilder, MundialitoDbContext mundialitoDbContext) + public UsersController(ILogger logger, IActionLogsRepository actionLogsRepository, IHttpContextAccessor httpContextAccessor, UserManager userManager, IBetsRepository betsRepository, IDateTimeProvider dateTimeProvider, TournamentTimesUtils tournamentTimesUtils, GeneralBetsService generalBetsService, TableBuilder tableBuilder, MundialitoDbContext mundialitoDbContext) { this.actionLogsRepository = actionLogsRepository; this.httpContextAccessor = httpContextAccessor; @@ -37,7 +37,7 @@ public UsersController(ILogger logger, IActionLogsRepository ac this.betsRepository = betsRepository; this.dateTimeProvider = dateTimeProvider; this.tournamentTimesUtils = tournamentTimesUtils; - this.generalBetsRepository = generalBetsRepository; + this.generalBetsService = generalBetsService; this.logger = logger; this.tableBuilder = tableBuilder; this.mundialitoDbContext = mundialitoDbContext; @@ -139,7 +139,7 @@ public async Task> GetUserByUsername(string username) return NotFound(new ErrorMessage { Message = string.Format("No such user '{0}'", username) }); var userModel = new UserModel(user); betsRepository.GetUserBets(user.UserName).Where(bet => httpContextAccessor.HttpContext?.User.Identity.Name == username || !bet.IsOpenForBetting(dateTimeProvider.UTCNow)).ToList().ForEach(bet => userModel.AddBet(new BetViewModel(bet, dateTimeProvider.UTCNow))); - var generalBet = generalBetsRepository.GetUserGeneralBet(username); + var generalBet = generalBetsService.GetUserGeneralBet(username); if (generalBet != null) userModel.SetGeneralBet(new GeneralBetViewModel(generalBet, tournamentTimesUtils.GetGeneralBetsCloseTime())); return userModel; @@ -285,7 +285,7 @@ private IEnumerable CompareUsers(List users) } if (betsByDate.Count() > 0) { - var generalBets = generalBetsRepository.GetGeneralBets(); + var generalBets = generalBetsService.GetGeneralBets(); allUsers = tableBuilder.GetTable(allUsers, [], generalBets.Where(bet => users.Select(user => user.Id).Contains(bet.User.Id)).ToList()).ToList(); var finalTable = tableBuilder.GetTable(allUsers, [], generalBets); var finalUserEntries = users.Select(user => finalTable.FirstOrDefault(tableUser => tableUser.Id == user.Id)).Where(entry => entry != null).ToList(); @@ -322,7 +322,7 @@ private void AddLog(ActionType actionType, string message) private IEnumerable GetTableDetails(IEnumerable users) { - return tableBuilder.GetTable(users.Select((user) => new UserWithPointsModel(user)), betsRepository.GetBets().ToList(), generalBetsRepository.GetGeneralBets().Where(bet => users.Select(user => user.Id).Contains(bet.User.Id)).ToList()); + return tableBuilder.GetTable(users.Select((user) => new UserWithPointsModel(user)), betsRepository.GetBets().ToList(), generalBetsService.GetGeneralBets().Where(bet => users.Select(user => user.Id).Contains(bet.User.Id)).ToList()); } } diff --git a/Mundialito/Logic/GeneralBetsService.cs b/Mundialito/Logic/GeneralBetsService.cs new file mode 100644 index 0000000..56b2312 --- /dev/null +++ b/Mundialito/Logic/GeneralBetsService.cs @@ -0,0 +1,30 @@ +using Mundialito.DAL.GeneralBets; + +namespace Mundialito.Logic; + +public class GeneralBetsService { + + private readonly IDateTimeProvider _dateTimeProvider; + private readonly IGeneralBetsRepository _generalBetsRepository; + private readonly TournamentTimesUtils _tournamentTimesUtils; + + public GeneralBetsService(IDateTimeProvider dateTimeProvider, IGeneralBetsRepository generalBetsRepository, TournamentTimesUtils tournamentTimesUtils) { + _dateTimeProvider = dateTimeProvider; + _generalBetsRepository = generalBetsRepository; + _tournamentTimesUtils = tournamentTimesUtils; + } + + public IEnumerable GetGeneralBets() + { + if (_dateTimeProvider.UTCNow >= _tournamentTimesUtils.GetGeneralBetsCloseTime()) + return _generalBetsRepository.GetGeneralBets(); + return new List(); + } + + public GeneralBet? GetUserGeneralBet(string username) + { + if (_dateTimeProvider.UTCNow >= _tournamentTimesUtils.GetGeneralBetsCloseTime()) + return _generalBetsRepository.GetUserGeneralBet(username); + return null; + } +} \ No newline at end of file diff --git a/Mundialito/Logic/TableBuilder.cs b/Mundialito/Logic/TableBuilder.cs index 51bb693..c045bfe 100644 --- a/Mundialito/Logic/TableBuilder.cs +++ b/Mundialito/Logic/TableBuilder.cs @@ -1,9 +1,6 @@ using Mundialito.Models; using Mundialito.DAL.Bets; using Mundialito.DAL.GeneralBets; -using Mundialito.DAL.Accounts; -using Mundialito.DAL.Teams; -using Mundialito.DAL.Players; namespace Mundialito.Logic; diff --git a/Mundialito/Program.cs b/Mundialito/Program.cs index 9b8ea91..074a64d 100644 --- a/Mundialito/Program.cs +++ b/Mundialito/Program.cs @@ -139,6 +139,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddTransient(); builder.Services.AddCors(options => { diff --git a/Mundialito/Views/Home/Index.cshtml b/Mundialito/Views/Home/Index.cshtml index 2613711..0db91af 100644 --- a/Mundialito/Views/Home/Index.cshtml +++ b/Mundialito/Views/Home/Index.cshtml @@ -149,11 +149,11 @@ @if (env.IsProduction()) { - + } else { - + }