Skip to content

Commit

Permalink
fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ezraroi committed Jul 11, 2024
1 parent 4102556 commit fbaa437
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions Mundialito/Client/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
teams: ['TeamsManager', (TeamsManager) => TeamsManager.loadAllTeams()],
generalBetsAreOpen: ['GeneralBetsManager', (GeneralBetsManager) => GeneralBetsManager.canSubmtiGeneralBet()],
players: ['PlayersManager', (PlayersManager) => PlayersManager.loadAllPlayers()],
allUsers: ['UsersManager', (UsersManager) => UsersManager.loadAllUsers()]
}
}).
when('/manage_users', {
Expand Down
13 changes: 8 additions & 5 deletions Mundialito/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,21 @@ public async Task<IList<UserModel>> GetFollowersAsync()
}

[HttpGet("{username}")]
public async Task<ActionResult<UserWithPointsModel>> GetUserByUsername(string username)
public async Task<ActionResult<UserModel>> GetUserByUsername(string username)
{
var user = await userManager.FindByNameAsync(username);
if (user == null)
return NotFound(new ErrorMessage { Message = string.Format("No such user '{0}'", username) });
var res = GetTableDetails(new List<MundialitoUser>{user}).ToList();
res.ForEach(user => IsAdmin(user));
return Ok(res.First());
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);
if (generalBet != null)
userModel.SetGeneralBet(new GeneralBetViewModel(generalBet, tournamentTimesUtils.GetGeneralBetsCloseTime()));
return await IsAdmin(userModel);
}

[HttpGet("me")]
public async Task<ActionResult<UserWithPointsModel>> GetMe()
public async Task<ActionResult<UserModel>> GetMe()
{
return await GetUserByUsername(httpContextAccessor.HttpContext?.User.Identity.Name);
}
Expand Down
16 changes: 16 additions & 0 deletions Mundialito/Models/UserModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public UserModel(MundialitoUser user)
Name = string.Format("{0} {1}", user.FirstName, user.LastName);
Id = user.Id;
Email = user.Email;
Points = 0;
}

[JsonPropertyName("Id")]
Expand All @@ -27,6 +28,21 @@ public UserModel(MundialitoUser user)

[JsonPropertyName("Name")]
public string Name { get; set; }

[JsonPropertyName("GeneralBet")]
public GeneralBetViewModel? GeneralBet { get; set; }

[JsonPropertyName("Points")]
public int Points { get; set; }

public void SetGeneralBet(GeneralBetViewModel generalBet)
{
GeneralBet = generalBet;
if (generalBet.IsResolved)
{
Points += generalBet.Points;
}
}

}

Expand Down
2 changes: 1 addition & 1 deletion Mundialito/wwwroot/js/app-min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Mundialito/wwwroot/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ angular.module('mundialitoApp', ['key-value-editor', 'security', 'ngSanitize', '
teams: ['TeamsManager', (TeamsManager) => TeamsManager.loadAllTeams()],
generalBetsAreOpen: ['GeneralBetsManager', (GeneralBetsManager) => GeneralBetsManager.canSubmtiGeneralBet()],
players: ['PlayersManager', (PlayersManager) => PlayersManager.loadAllPlayers()],
allUsers: ['UsersManager', (UsersManager) => UsersManager.loadAllUsers()]
}
}).
when('/manage_users', {
Expand Down

0 comments on commit fbaa437

Please sign in to comment.