Skip to content

Commit 4c07958

Browse files
authored
Merge pull request #145 from LeadOn/develop
Fixed issues with LoL routes + updated way to store pictures for players and tournaments
2 parents 88083d3 + 790f6c0 commit 4c07958

41 files changed

Lines changed: 1075 additions & 68 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

GameOn.Application/Common/Changelogs/Commands/CreateChangelog/CreateChangelogCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace GameOn.Application.Common.Changelogs.Commands.CreateChangelog
77
using GameOn.Common.DTOs;
88
using GameOn.Domain;
99
using MediatR;
10-
10+
1111
/// <summary>
1212
/// CreateChangelogCommand class.
1313
/// </summary>

GameOn.Application/Common/Changelogs/Commands/DeleteChangelog/DeleteChangelogCommandHandler.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
// Copyright (c) LeadOn's Corp'. All rights reserved.
33
// </copyright>
44

5-
using AutoMapper;
6-
using Microsoft.EntityFrameworkCore;
7-
85
namespace GameOn.Application.Common.Changelogs.Commands.DeleteChangelog
96
{
107
using GameOn.Common.Interfaces;
11-
using GameOn.Domain;
128
using MediatR;
9+
using Microsoft.EntityFrameworkCore;
1310

1411
/// <summary>
1512
/// DeleteChangelogCommandHandler class.

GameOn.Application/Common/Changelogs/Commands/UpdateChangelog/UpdateChangelogCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace GameOn.Application.Common.Changelogs.Commands.UpdateChangelog
77
using GameOn.Common.DTOs;
88
using GameOn.Domain;
99
using MediatR;
10-
10+
1111
/// <summary>
1212
/// UpdateChangelogCommand class.
1313
/// </summary>

GameOn.Application/Common/Changelogs/Commands/UpdateChangelog/UpdateChangelogCommandHandler.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
// Copyright (c) LeadOn's Corp'. All rights reserved.
33
// </copyright>
44

5-
using AutoMapper;
6-
using Microsoft.EntityFrameworkCore;
7-
85
namespace GameOn.Application.Common.Changelogs.Commands.UpdateChangelog
96
{
7+
using AutoMapper;
108
using GameOn.Common.Interfaces;
119
using GameOn.Domain;
1210
using MediatR;
11+
using Microsoft.EntityFrameworkCore;
1312

1413
/// <summary>
1514
/// UpdateChangelogCommandHandler class.

GameOn.Application/Common/Changelogs/Queries/GetLatestChangelog/GetLatestChangelogQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="GetLatestChangelog.cs" company="LeadOn's Corp'">
1+
// <copyright file="GetLatestChangelogQuery.cs" company="LeadOn's Corp'">
22
// Copyright (c) LeadOn's Corp'. All rights reserved.
33
// </copyright>
44

GameOn.Application/Common/Home/Queries/GetHomeData/GetHomeDataQueryHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
// Copyright (c) LeadOn's Corp'. All rights reserved.
33
// </copyright>
44

5-
using GameOn.Application.Common.Changelogs.Queries.GetLatestChangelog;
6-
75
namespace GameOn.Application.Common.Home.Queries.GetHomeData
86
{
7+
using GameOn.Application.Common.Changelogs.Queries.GetLatestChangelog;
98
using GameOn.Application.FIFA.Seasons.Queries.GetCurrentSeason;
109
using GameOn.Application.FIFA.Tournaments.Queries.GetFeaturedTournaments;
1110
using GameOn.Common.DTOs.Common;

GameOn.Application/Common/Players/Commands/UpdateConnectedPlayer/UpdateConnectedPlayerCommandHandler.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,12 @@ public async Task<Player> Handle(UpdateConnectedPlayerCommand request, Cancellat
4545
playerInDb.FullName = request.Player.FullName;
4646
playerInDb.Nickname = request.Player.Nickname;
4747

48-
if (request.Player.ProfilePictureUrl is not null && request.Player.ProfilePictureUrl != string.Empty)
49-
{
50-
playerInDb.ProfilePictureUrl = request.Player.ProfilePictureUrl;
51-
}
52-
else
53-
{
54-
playerInDb.ProfilePictureUrl = "https://gameon.valentinvirot.fr/assets/img/gameon-logo.webp";
55-
}
56-
5748
if (request.Player.RiotGamesNickname is not null && request.Player.RiotGamesTagLine is not null)
5849
{
5950
// First, checking if player isn't already present in DB
6051
var playersWithRiotCombo = await this.context.Players.FirstOrDefaultAsync(x => x.RiotGamesNickname == request.Player.RiotGamesNickname && x.RiotGamesTagLine == request.Player.RiotGamesTagLine, cancellationToken);
6152

62-
if (playersWithRiotCombo is not null)
53+
if (playersWithRiotCombo is not null && playersWithRiotCombo.Id != playerInDb.Id)
6354
{
6455
return playerInDb;
6556
}
@@ -79,7 +70,9 @@ public async Task<Player> Handle(UpdateConnectedPlayerCommand request, Cancellat
7970

8071
if (summonerIdFromRiot is not null)
8172
{
82-
playerInDb.LolSummonerId = summonerIdFromRiot.SummonerId;
73+
playerInDb.LolSummonerLevel = summonerIdFromRiot.SummonerLevel;
74+
playerInDb.LolIconId = summonerIdFromRiot.ProfileIconId;
75+
playerInDb.LolRefreshedOn = DateTime.Now;
8376
}
8477
}
8578
}

GameOn.Application/Common/Players/Commands/UpdatePlayer/UpdatePlayerCommandHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public UpdatePlayerCommandHandler(IApplicationDbContext context)
2828
/// <inheritdoc />
2929
public async Task<Player> Handle(UpdatePlayerCommand request, CancellationToken cancellationToken)
3030
{
31-
var playerInDb = await this.context.Players.FirstOrDefaultAsync(x => x.Id == request.Player.Id);
31+
var playerInDb = await this.context.Players.FirstOrDefaultAsync(x => x.Id == request.Player.Id, cancellationToken);
3232

3333
if (playerInDb == null)
3434
{
@@ -37,7 +37,6 @@ public async Task<Player> Handle(UpdatePlayerCommand request, CancellationToken
3737

3838
playerInDb.FullName = request.Player.FullName;
3939
playerInDb.Nickname = request.Player.Nickname;
40-
playerInDb.ProfilePictureUrl = request.Player.ProfilePictureUrl ?? "https://gameon.valentinvirot.fr/assets/img/gameon-logo.webp";
4140
playerInDb.KeycloakId = request.Player.KeycloakId;
4241
playerInDb.Archived = request.Player.Archived;
4342

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// <copyright file="UpdatePlayerProfilePictureCommand.cs" company="LeadOn's Corp'">
2+
// Copyright (c) LeadOn's Corp'. All rights reserved.
3+
// </copyright>
4+
5+
namespace GameOn.Application.Common.Players.Commands.UpdatePlayerProfilePicture
6+
{
7+
using GameOn.Common.DTOs;
8+
using GameOn.Domain;
9+
using MediatR;
10+
using Microsoft.AspNetCore.Http;
11+
12+
/// <summary>
13+
/// UpdatePlayerProfilePictureCommand class.
14+
/// </summary>
15+
public class UpdatePlayerProfilePictureCommand : IRequest<bool>
16+
{
17+
/// <summary>
18+
/// Gets or sets Player ID.
19+
/// </summary>
20+
public int PlayerId { get; set; }
21+
22+
/// <summary>
23+
/// Gets or sets File.
24+
/// </summary>
25+
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
26+
public IFormFile File { get; set; }
27+
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
28+
}
29+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// <copyright file="UpdatePlayerProfilePictureCommandHandler.cs" company="LeadOn's Corp'">
2+
// Copyright (c) LeadOn's Corp'. All rights reserved.
3+
// </copyright>
4+
5+
namespace GameOn.Application.Common.Players.Commands.UpdatePlayerProfilePicture
6+
{
7+
using GameOn.Application.Common.Players.Queries.GetPlayerById;
8+
using GameOn.Common.Exceptions;
9+
using GameOn.Common.Interfaces;
10+
using GameOn.Domain;
11+
using GameOn.External.NetworkStorage.Interfaces;
12+
using MediatR;
13+
using Microsoft.EntityFrameworkCore;
14+
15+
/// <summary>
16+
/// UpdatePlayerProfilePictureCommandHandler class.
17+
/// </summary>
18+
public class UpdatePlayerProfilePictureCommandHandler : IRequestHandler<UpdatePlayerProfilePictureCommand, bool>
19+
{
20+
private readonly IMediator mediator;
21+
private readonly IApplicationDbContext context;
22+
private readonly INetworkStorageService nsService;
23+
private readonly string bucketName = Environment.GetEnvironmentVariable("S3_BUCKET_NAME") ?? throw new MissingEnvironmentVariableException("S3_BUCKET_NAME");
24+
private readonly string ppBasePath = Environment.GetEnvironmentVariable("S3_PP_BASE_PATH") ?? throw new MissingEnvironmentVariableException("S3_PP_BASE_PATH");
25+
26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="UpdatePlayerProfilePictureCommandHandler"/> class.
28+
/// </summary>
29+
/// <param name="context">DbContext, injected.</param>
30+
/// <param name="nsService">NetworkStorageService, injected.</param>
31+
/// <param name="mediator">Mediator, injected.</param>
32+
public UpdatePlayerProfilePictureCommandHandler(IApplicationDbContext context, INetworkStorageService nsService, IMediator mediator)
33+
{
34+
this.context = context;
35+
this.nsService = nsService;
36+
this.mediator = mediator;
37+
}
38+
39+
/// <inheritdoc />
40+
public async Task<bool> Handle(UpdatePlayerProfilePictureCommand request, CancellationToken cancellationToken)
41+
{
42+
try
43+
{
44+
await this.nsService.UploadFile(this.bucketName, this.ppBasePath + "/" + request.PlayerId + Path.GetExtension(request.File.FileName), request.File);
45+
46+
// now that file is uploaded, updating user
47+
var playerInDb = await this.mediator.Send(new GetPlayerByIdQuery { PlayerId = request.PlayerId }, cancellationToken);
48+
49+
if (playerInDb is not null)
50+
{
51+
playerInDb.ProfilePictureUrl = request.PlayerId + Path.GetExtension(request.File.FileName);
52+
this.context.Players.Update(playerInDb);
53+
await this.context.SaveChangesAsync(cancellationToken);
54+
}
55+
56+
return true;
57+
}
58+
catch
59+
{
60+
return false;
61+
}
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)