Skip to content

Commit

Permalink
Merge pull request #79 from ezraroi/78-when-viewing-a-user-profile-it…
Browse files Browse the repository at this point in the history
…-is-displayed-as-first-place-in-the-table

fixed bug
  • Loading branch information
ezraroi authored Jul 11, 2024
2 parents 4102556 + fbaa437 commit c9acb9c
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)));

Check failure on line 142 in Mundialito/Controllers/UsersController.cs

View workflow job for this annotation

GitHub Actions / build

'UserModel' does not contain a definition for 'AddBet' and no accessible extension method 'AddBet' accepting a first argument of type 'UserModel' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in Mundialito/Controllers/UsersController.cs

View workflow job for this annotation

GitHub Actions / build

'UserModel' does not contain a definition for 'AddBet' and no accessible extension method 'AddBet' accepting a first argument of type 'UserModel' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in Mundialito/Controllers/UsersController.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

'UserModel' does not contain a definition for 'AddBet' and no accessible extension method 'AddBet' accepting a first argument of type 'UserModel' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in Mundialito/Controllers/UsersController.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

'UserModel' does not contain a definition for 'AddBet' and no accessible extension method 'AddBet' accepting a first argument of type 'UserModel' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in Mundialito/Controllers/UsersController.cs

View workflow job for this annotation

GitHub Actions / build

'UserModel' does not contain a definition for 'AddBet' and no accessible extension method 'AddBet' accepting a first argument of type 'UserModel' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in Mundialito/Controllers/UsersController.cs

View workflow job for this annotation

GitHub Actions / build

'UserModel' does not contain a definition for 'AddBet' and no accessible extension method 'AddBet' accepting a first argument of type 'UserModel' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in Mundialito/Controllers/UsersController.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

'UserModel' does not contain a definition for 'AddBet' and no accessible extension method 'AddBet' accepting a first argument of type 'UserModel' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in Mundialito/Controllers/UsersController.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

'UserModel' does not contain a definition for 'AddBet' and no accessible extension method 'AddBet' accepting a first argument of type 'UserModel' could be found (are you missing a using directive or an assembly reference?)
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;

Check warning on line 13 in Mundialito/Models/UserModel.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.

Check warning on line 13 in Mundialito/Models/UserModel.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

Possible null reference assignment.

Check warning on line 13 in Mundialito/Models/UserModel.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.

Check warning on line 13 in Mundialito/Models/UserModel.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

Possible null reference assignment.
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 c9acb9c

Please sign in to comment.