Skip to content

Commit c3588ce

Browse files
Fix a bunch of varied warnings (#40)
* Fix a bunch of varied warnings * Remove Framework 4 package for AspNet stats gathering
1 parent 667b190 commit c3588ce

35 files changed

+301
-389
lines changed

ReplayBrowser/Controllers/AccountController.cs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public async Task<IActionResult> Logout()
5656
[Route("redirect")]
5757
public async Task<IActionResult> RedirectFromLogin()
5858
{
59-
if (!User.Identity.IsAuthenticated)
59+
if (User.Identity is null || !User.Identity.IsAuthenticated)
6060
{
6161
return Unauthorized();
6262
}
@@ -115,12 +115,12 @@ public async Task<IActionResult> DeleteAccount(
115115
[FromQuery] bool permanently = false
116116
)
117117
{
118-
if (!User.Identity.IsAuthenticated)
118+
if (User.Identity is null || !User.Identity.IsAuthenticated)
119119
{
120120
return Unauthorized();
121121
}
122122

123-
var guid = AccountHelper.GetAccountGuid(User);
123+
var guid = AccountHelper.GetAccountGuid(User)!;
124124

125125
var user = await _context.Accounts
126126
.Include(a => a.Settings)
@@ -139,15 +139,19 @@ public async Task<IActionResult> DeleteAccount(
139139
Guid = (Guid) guid
140140
});
141141

142-
await _context.Database.ExecuteSqlRawAsync($"""
143-
DELETE FROM "CharacterData"
144-
WHERE "CollectedPlayerDataPlayerGuid" = '{guid}';
145-
""");
142+
await _context.Database.ExecuteSqlAsync(
143+
$"""
144+
DELETE FROM "CharacterData"
145+
WHERE "CollectedPlayerDataPlayerGuid" = {guid};
146+
"""
147+
);
146148

147-
await _context.Database.ExecuteSqlRawAsync($"""
148-
DELETE FROM "JobCountData"
149-
WHERE "CollectedPlayerDataPlayerGuid" = '{guid}';
150-
""");
149+
await _context.Database.ExecuteSqlAsync(
150+
$"""
151+
DELETE FROM "JobCountData"
152+
WHERE "CollectedPlayerDataPlayerGuid" = {guid};
153+
"""
154+
);
151155

152156
_context.Replays
153157
.Include(r => r.RoundParticipants!)
@@ -192,7 +196,7 @@ [FromQuery] string guid
192196
return BadRequest("Guid is not a valid guid.");
193197
}
194198

195-
if (!User.Identity.IsAuthenticated)
199+
if (!User.Identity!.IsAuthenticated)
196200
{
197201
return Unauthorized();
198202
}
@@ -213,6 +217,7 @@ [FromQuery] string guid
213217
return Unauthorized("You are not an admin.");
214218

215219
var user = await _context.Accounts
220+
.AsNoTracking()
216221
.Include(a => a.Settings)
217222
.Include(a => a.History)
218223
.FirstOrDefaultAsync(a => a.Guid == parsedGuid);
@@ -228,7 +233,7 @@ [FromQuery] string guid
228233
await JsonSerializer.SerializeAsync(entryStream, user.History);
229234
}
230235

231-
user.History = null;
236+
user.History = [];
232237

233238
var baseEntry = archive.CreateEntry("user.json");
234239
using (var entryStream = baseEntry.Open())
@@ -284,7 +289,7 @@ [FromQuery] string guid
284289
return BadRequest("Guid is not a valid guid.");
285290
}
286291

287-
if (!User.Identity.IsAuthenticated)
292+
if (!User.Identity!.IsAuthenticated)
288293
{
289294
return Unauthorized();
290295
}
@@ -338,7 +343,7 @@ [FromQuery] string guid
338343
return BadRequest("Guid is not a valid guid.");
339344
}
340345

341-
if (!User.Identity.IsAuthenticated)
346+
if (!User.Identity!.IsAuthenticated)
342347
{
343348
return Unauthorized();
344349
}
@@ -395,14 +400,15 @@ [FromQuery] string guid
395400
[HttpGet("download")]
396401
public async Task<IActionResult> DownloadAccount()
397402
{
398-
if (!User.Identity.IsAuthenticated)
403+
if (User.Identity is null || !User.Identity.IsAuthenticated)
399404
{
400405
return Unauthorized();
401406
}
402407

403408
var guid = AccountHelper.GetAccountGuid(User);
404409

405410
var user = await _context.Accounts
411+
.AsNoTracking()
406412
.Include(a => a.Settings)
407413
.Include(a => a.History)
408414
.FirstOrDefaultAsync(a => a.Guid == guid);
@@ -421,7 +427,7 @@ public async Task<IActionResult> DownloadAccount()
421427
await JsonSerializer.SerializeAsync(entryStream, user.History);
422428
}
423429

424-
user.History = null;
430+
user.History = [];
425431

426432
var baseEntry = archive.CreateEntry("user.json");
427433
using (var entryStream = baseEntry.Open())
@@ -440,10 +446,16 @@ public async Task<IActionResult> DownloadAccount()
440446
}
441447

442448
[HttpPost("add-protected-account")]
449+
[Authorize]
443450
public async Task<IActionResult> AddProtectedAccount(
444451
[FromQuery] string username
445452
)
446453
{
454+
if (User.Identity is null || !User.Identity.IsAuthenticated)
455+
{
456+
return Unauthorized();
457+
}
458+
447459
if (string.IsNullOrWhiteSpace(username))
448460
{
449461
return BadRequest("Username is null or empty.");
@@ -461,11 +473,6 @@ [FromQuery] string username
461473
return NotFound("Player guid is null or empty. This should not happen.");
462474
}
463475

464-
if (!User.Identity.IsAuthenticated)
465-
{
466-
return Unauthorized();
467-
}
468-
469476
var guidRequestor = AccountHelper.GetAccountGuid(User);
470477

471478
var requestor = await _context.Accounts

ReplayBrowser/Controllers/ReplayController.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task<IActionResult> GetReplay(int replayId)
4646
[HttpDelete("profile/delete/{serverId}")]
4747
public async Task<IActionResult> DeleteProfile(string serverId)
4848
{
49-
if (!User.Identity.IsAuthenticated)
49+
if (User.Identity is null || !User.Identity.IsAuthenticated)
5050
{
5151
return Unauthorized();
5252
}
@@ -70,22 +70,26 @@ public async Task<IActionResult> DeleteProfile(string serverId)
7070
.Where(r => r.ServerId == serverId)
7171
.Include(r => r.RoundParticipants)
7272
.Where(r => r.RoundParticipants != null)
73-
.SelectMany(r => r.RoundParticipants)
73+
.SelectMany(r => r.RoundParticipants!)
7474
.Select(p => p.PlayerGuid)
7575
.Distinct()
7676
.ToListAsync();
7777

7878
foreach (var player in players)
7979
{
80-
await _dbContext.Database.ExecuteSqlRawAsync($"""
81-
DELETE FROM "CharacterData"
82-
WHERE "CollectedPlayerDataPlayerGuid" = '{player}';
83-
""");
84-
85-
await _dbContext.Database.ExecuteSqlRawAsync($"""
86-
DELETE FROM "JobCountData"
87-
WHERE "CollectedPlayerDataPlayerGuid" = '{player}';
88-
""");
80+
await _dbContext.Database.ExecuteSqlAsync(
81+
$"""
82+
DELETE FROM "CharacterData"
83+
WHERE "CollectedPlayerDataPlayerGuid" = {player};
84+
"""
85+
);
86+
87+
await _dbContext.Database.ExecuteSqlAsync(
88+
$"""
89+
DELETE FROM "JobCountData"
90+
WHERE "CollectedPlayerDataPlayerGuid" = {player};
91+
"""
92+
);
8993
}
9094

9195
await _dbContext.PlayerProfiles

ReplayBrowser/Data/Models/Account/Account.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Account : IEntityTypeConfiguration<Account>
99
public int Id { get; set; }
1010

1111
public Guid Guid { get; set; }
12-
public string Username { get; set; }
12+
public required string Username { get; set; }
1313
public bool IsAdmin { get; set; } = false;
1414
public AccountSettings Settings { get; set; } = new();
1515

ReplayBrowser/Data/Models/Account/History.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
public class HistoryEntry
44
{
55
public int Id { get; set; }
6-
7-
public string Action { get; set; }
6+
7+
public required string Action { get; set; }
88
public DateTime Time { get; set; }
99
public string? Details { get; set; }
10+
11+
public Account Account { get; set; } = null!;
12+
public int AccountId { get; set; }
1013
}
1114

1215
public enum Action
1316
{
1417
// Account actions
1518
AccountSettingsChanged,
1619
Login,
17-
20+
1821
// Site actions
1922
SearchPerformed,
2023
LeaderboardViewed,

ReplayBrowser/Data/Models/CollectedPlayerData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public override int GetHashCode()
7373
public class CharacterData
7474
{
7575
public int Id { get; set; }
76-
public string CharacterName { get; set; }
76+
public required string CharacterName { get; set; }
7777
public DateTime LastPlayed { get; set; } = DateTime.MinValue;
7878
public int RoundsPlayed { get; set; }
7979
}
@@ -82,7 +82,7 @@ public class JobCountData
8282
{
8383
public int Id { get; set; }
8484

85-
public string JobPrototype { get; set; }
85+
public required string JobPrototype { get; set; }
8686
public int RoundsPlayed { get; set; }
8787
public DateTime LastPlayed { get; set; } = DateTime.MinValue;
8888
}

ReplayBrowser/Data/Models/ParsedReplay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ namespace ReplayBrowser.Data.Models;
55
public class ParsedReplay
66
{
77
[Key]
8-
public string Name { get; set; }
8+
public required string Name { get; set; }
99
}

ReplayBrowser/Data/Models/PlayerData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class PlayerData
1313

1414
public Guid? PlayerGuid { get; set; }
1515

16-
public string Username { get; set; }
16+
public string Username { get; set; } = null!;
1717

1818

1919
public override bool Equals(object? obj)

ReplayBrowser/Data/Models/Replay.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Replay : IEntityTypeConfiguration<Replay>
1313
{
1414
public int Id { get; set; }
1515

16-
public string Link { get; set; }
16+
public required string Link { get; set; }
1717

1818
public int? RoundId { get; set; }
1919

@@ -23,19 +23,19 @@ public class Replay : IEntityTypeConfiguration<Replay>
2323
public string? Map { get; set; }
2424

2525
public List<string>? Maps { get; set; }
26-
public string Gamemode { get; set; }
26+
public required string Gamemode { get; set; }
2727
public List<ReplayParticipant>? RoundParticipants { get; set; }
2828
public string? RoundEndText { get; set; }
29-
public string ServerId { get; set; }
29+
public required string ServerId { get; set; }
3030
public int EndTick { get; set; }
31-
public string Duration { get; set; }
31+
public required string Duration { get; set; }
3232
public int FileCount { get; set; }
3333
public int Size { get; set; }
3434
public int UncompressedSize { get; set; }
35-
public string EndTime { get; set; }
35+
public required string EndTime { get; set; }
3636

3737
[JsonIgnore]
38-
public NpgsqlTsVector RoundEndTextSearchVector { get; set; }
38+
public NpgsqlTsVector RoundEndTextSearchVector { get; set; } = null!;
3939

4040
/// <summary>
4141
/// Determines if a replay is marked as a favorite.

0 commit comments

Comments
 (0)