Skip to content

Commit

Permalink
Merge pull request #142 from ezraroi/123-after-viewing-user-profile-w…
Browse files Browse the repository at this point in the history
…hen-general-bets-are-closed-in-detailed-table-you-can-see-general-bet-backend-issue-probably

fixed
  • Loading branch information
ezraroi authored Sep 21, 2024
2 parents a78cd62 + e06a2e3 commit 1e413d2
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 2,880 deletions.
2 changes: 1 addition & 1 deletion Mundialito/Client/src/Dashboard/Dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ <h4 class="media-heading"><a href="{{user.getUrl()}}">{{user.Place}}.
<tr ng-repeat="bet in generalBets">
<td>{{bet.OwnerName}}</td>
<td>{{usersDic[bet.OwnerId].Points}}</td>
<td>{{bet.WinningTeam.Name}}</td>
<td><team-flag team="bet.WinningTeam"></team-flag> {{bet.WinningTeam.Name}}</td>
<td>{{bet.GoldenBootPlayer.Name}}</td>
</tr>
</tbody>
Expand Down
10 changes: 6 additions & 4 deletions Mundialito/Controllers/GeneralBetsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public class GeneralBetsController : ControllerBase
private readonly UserManager<MundialitoUser> userManager;
private readonly ITeamsRepository teamsRepository;
private readonly IPlayersRepository playersRepository;
private readonly GeneralBetsService generalBetsService;
private readonly ILogger logger;

public GeneralBetsController(ILogger<GeneralBetsController> logger, IGeneralBetsRepository generalBetsRepository, IDateTimeProvider dateTimeProvider, IActionLogsRepository actionLogsRepository, IHttpContextAccessor httpContextAccessor, TournamentTimesUtils tournamentTimesUtils, UserManager<MundialitoUser> userManager, ITeamsRepository teamsRepository, IPlayersRepository playersRepository)
public GeneralBetsController(ILogger<GeneralBetsController> logger, IGeneralBetsRepository generalBetsRepository, IDateTimeProvider dateTimeProvider, IActionLogsRepository actionLogsRepository, IHttpContextAccessor httpContextAccessor, TournamentTimesUtils tournamentTimesUtils, UserManager<MundialitoUser> userManager, ITeamsRepository teamsRepository, IPlayersRepository playersRepository, GeneralBetsService generalBetsService)
{
this.generalBetsRepository = generalBetsRepository;
this.dateTimeProvider = dateTimeProvider;
Expand All @@ -37,17 +38,18 @@ public GeneralBetsController(ILogger<GeneralBetsController> logger, IGeneralBets
this.userManager = userManager;
this.teamsRepository = teamsRepository;
this.playersRepository = playersRepository;
this.generalBetsService = generalBetsService;
this.logger = logger;
}

[HttpGet]
public ActionResult<IEnumerable<GeneralBetViewModel>> 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));
}

Expand All @@ -68,7 +70,7 @@ public ActionResult<GeneralBetViewModel> 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()));
Expand Down
12 changes: 6 additions & 6 deletions Mundialito/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ public class UsersController : ControllerBase
private readonly UserManager<MundialitoUser> 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<UsersController> logger, IActionLogsRepository actionLogsRepository, IHttpContextAccessor httpContextAccessor, UserManager<MundialitoUser> userManager, IBetsRepository betsRepository, IDateTimeProvider dateTimeProvider, TournamentTimesUtils tournamentTimesUtils, IGeneralBetsRepository generalBetsRepository, TableBuilder tableBuilder, MundialitoDbContext mundialitoDbContext)
public UsersController(ILogger<UsersController> logger, IActionLogsRepository actionLogsRepository, IHttpContextAccessor httpContextAccessor, UserManager<MundialitoUser> userManager, IBetsRepository betsRepository, IDateTimeProvider dateTimeProvider, TournamentTimesUtils tournamentTimesUtils, GeneralBetsService generalBetsService, TableBuilder tableBuilder, MundialitoDbContext mundialitoDbContext)
{
this.actionLogsRepository = actionLogsRepository;
this.httpContextAccessor = httpContextAccessor;
this.userManager = userManager;
this.betsRepository = betsRepository;
this.dateTimeProvider = dateTimeProvider;
this.tournamentTimesUtils = tournamentTimesUtils;
this.generalBetsRepository = generalBetsRepository;
this.generalBetsService = generalBetsService;
this.logger = logger;
this.tableBuilder = tableBuilder;
this.mundialitoDbContext = mundialitoDbContext;
Expand Down Expand Up @@ -139,7 +139,7 @@ public async Task<ActionResult<UserModel>> 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;
Expand Down Expand Up @@ -285,7 +285,7 @@ private IEnumerable<UserCompareModel> CompareUsers(List<MundialitoUser> 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();
Expand Down Expand Up @@ -322,7 +322,7 @@ private void AddLog(ActionType actionType, string message)

private IEnumerable<UserWithPointsModel> GetTableDetails(IEnumerable<MundialitoUser> 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());
}
}

30 changes: 30 additions & 0 deletions Mundialito/Logic/GeneralBetsService.cs
Original file line number Diff line number Diff line change
@@ -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<GeneralBet> GetGeneralBets()
{
if (_dateTimeProvider.UTCNow >= _tournamentTimesUtils.GetGeneralBetsCloseTime())
return _generalBetsRepository.GetGeneralBets();
return new List<GeneralBet>();
}

public GeneralBet? GetUserGeneralBet(string username)
{
if (_dateTimeProvider.UTCNow >= _tournamentTimesUtils.GetGeneralBetsCloseTime())
return _generalBetsRepository.GetUserGeneralBet(username);
return null;
}
}
3 changes: 0 additions & 3 deletions Mundialito/Logic/TableBuilder.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 1 addition & 0 deletions Mundialito/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
builder.Services.AddScoped<TableBuilder, TableBuilder>();
builder.Services.AddScoped<TournamentTimesUtils, TournamentTimesUtils>();
builder.Services.AddScoped<IDateTimeProvider, DateTimeProvider>();
builder.Services.AddScoped<GeneralBetsService, GeneralBetsService>();
builder.Services.AddTransient<IEmailSender, EmailSender>();
builder.Services.AddCors(options =>
{
Expand Down
4 changes: 2 additions & 2 deletions Mundialito/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@
@if (env.IsProduction())
{
<script src="lib/lib-min-2d5e40df8764ea1d842fca768d139b58.js"></script>
<script src="js/app-min-dbea857653a57fb18c602c8a4373eee2.js"></script>
<script src="js/app-min-7650b9735dadd2976bd3e012a2ea28c6.js"></script>
}
else {
<script src="lib/lib-77990d6df268e8d3d432fb52597000f9.js"></script>
<script src="js/app-d59627e3e8cd8f2d05420f29a89370ce.js"></script>
<script src="js/app-96f22219e28d4994f79433c0d1d5ec4c.js"></script>
}
<script>
Expand Down
2 changes: 1 addition & 1 deletion Mundialito/wwwroot/App/Dashboard/Dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ <h4 class="media-heading"><a href="{{user.getUrl()}}">{{user.Place}}.
<tr ng-repeat="bet in generalBets">
<td>{{bet.OwnerName}}</td>
<td>{{usersDic[bet.OwnerId].Points}}</td>
<td>{{bet.WinningTeam.Name}}</td>
<td><team-flag team="bet.WinningTeam"></team-flag> {{bet.WinningTeam.Name}}</td>
<td>{{bet.GoldenBootPlayer.Name}}</td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('mundialitoApp', ['key-value-editor', 'security', 'ngSanitize', 'ngRoute', 'ngAnimate', 'ui.bootstrap', 'autofields.bootstrap', 'cgBusy', 'ajoslin.promise-tracker', 'ui.select',
'ui.bootstrap.datetimepicker', 'ui.grid', 'ui.grid.autoResize', 'googlechart', 'toaster', 'ui.grid.saveState', 'ui.grid.resizeColumns','ui.toggle'])
'ui.bootstrap.datetimepicker', 'ui.grid', 'ui.grid.autoResize', 'googlechart', 'toaster', 'ui.grid.saveState', 'ui.grid.resizeColumns','ui.toggle', 'ngSentry'])
.value('cgBusyTemplateName', 'App/Partials/angular-busy.html')
.config(['$routeProvider', '$httpProvider', '$locationProvider', '$parseProvider', 'securityProvider', 'Constants', function ($routeProvider, $httpProvider, $locationProvider, $parseProvider, securityProvider, Constants) {
$locationProvider.html5Mode(true);
Expand Down Expand Up @@ -1445,12 +1445,10 @@ angular.module('mundialitoApp').factory('ErrorHandler', ['$rootScope', '$log', '
}])
.factory('myHttpInterceptor', ['ErrorHandler', '$q', function (ErrorHandler, $q) {
return {
response: function (response) {
return response;
},
responseError: function (response) {
response: (response) => response,
responseError: (response) => {
ErrorHandler.handle(response.data, response.status, response.headers, response.config);

Sentry.captureException(response.data);
// do something on error
return $q.reject(response);
}
Expand Down
Loading

0 comments on commit 1e413d2

Please sign in to comment.