Fix a bunch of warnings

This commit is contained in:
LumaLivy 2021-11-17 20:50:44 -05:00
commit d464329193
7 changed files with 29 additions and 23 deletions

2
.gitignore vendored
View file

@ -12,3 +12,5 @@ riderModule.iml
/ProjectLighthouse/logs/*
/ProjectLighthouse/ProjectLighthouse.csproj.user
.vs/
.vscode/
.editorconfig

View file

@ -35,7 +35,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
GameVersion gameVersion = token.GameVersion;
IQueryable<VisitedLevel> visited = this.database.VisitedLevels.Where(s => s.SlotId == slotId && s.UserId == user.UserId);
VisitedLevel v;
VisitedLevel? v;
if (!visited.Any())
{
switch (gameVersion)
@ -61,6 +61,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{
v = await visited.FirstOrDefaultAsync();
}
if (v == null) return this.StatusCode(403, "");
switch (gameVersion)
{
@ -95,7 +96,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (slot == null) return this.NotFound();
IQueryable<VisitedLevel> visited = this.database.VisitedLevels.Where(s => s.SlotId == id && s.UserId == user.UserId);
VisitedLevel v;
VisitedLevel? v;
if (!visited.Any())
{
slot.PlaysLBP1Unique++;
@ -109,6 +110,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{
v = await visited.FirstOrDefaultAsync();
}
if (v == null) return StatusCode(403, "");
slot.PlaysLBP1++;
v.PlaysLBP1++;

View file

@ -55,7 +55,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
User? user = await this.database.UserFromRequest(this.Request);
if (user == null) return this.StatusCode(403, "");
QueuedLevel queuedLevel = await this.database.QueuedLevels.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.SlotId == id);
QueuedLevel? queuedLevel = await this.database.QueuedLevels.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.SlotId == id);
if (queuedLevel != null) return this.Ok();
this.database.QueuedLevels.Add
@ -78,7 +78,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
User? user = await this.database.UserFromRequest(this.Request);
if (user == null) return this.StatusCode(403, "");
QueuedLevel queuedLevel = await this.database.QueuedLevels.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.SlotId == id);
QueuedLevel? queuedLevel = await this.database.QueuedLevels.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.SlotId == id);
if (queuedLevel != null) this.database.QueuedLevels.Remove(queuedLevel);
await this.database.SaveChangesAsync();
@ -119,7 +119,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
User? user = await this.database.UserFromRequest(this.Request);
if (user == null) return this.StatusCode(403, "");
HeartedLevel heartedLevel = await this.database.HeartedLevels.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.SlotId == id);
HeartedLevel? heartedLevel = await this.database.HeartedLevels.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.SlotId == id);
if (heartedLevel != null) return this.Ok();
this.database.HeartedLevels.Add
@ -142,7 +142,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
User? user = await this.database.UserFromRequest(this.Request);
if (user == null) return this.StatusCode(403, "");
HeartedLevel heartedLevel = await this.database.HeartedLevels.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.SlotId == id);
HeartedLevel? heartedLevel = await this.database.HeartedLevels.FirstOrDefaultAsync(q => q.UserId == user.UserId && q.SlotId == id);
if (heartedLevel != null) this.database.HeartedLevels.Remove(heartedLevel);
await this.database.SaveChangesAsync();
@ -185,7 +185,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
User? heartedUser = await this.database.Users.FirstOrDefaultAsync(u => u.Username == username);
if (heartedUser == null) return this.NotFound();
HeartedProfile heartedProfile = await this.database.HeartedProfiles.FirstOrDefaultAsync
HeartedProfile? heartedProfile = await this.database.HeartedProfiles.FirstOrDefaultAsync
(q => q.UserId == user.UserId && q.HeartedUserId == heartedUser.UserId);
if (heartedProfile != null) return this.Ok();
@ -212,7 +212,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
User? heartedUser = await this.database.Users.FirstOrDefaultAsync(u => u.Username == username);
if (heartedUser == null) return this.NotFound();
HeartedProfile heartedProfile = await this.database.HeartedProfiles.FirstOrDefaultAsync
HeartedProfile? heartedProfile = await this.database.HeartedProfiles.FirstOrDefaultAsync
(q => q.UserId == user.UserId && q.HeartedUserId == heartedUser.UserId);
if (heartedProfile != null) this.database.HeartedProfiles.Remove(heartedProfile);

View file

@ -82,7 +82,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{
User? userFromQuery = await this.database.Users.FirstOrDefaultAsync(u => u.Username == user);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (user == null) return this.NotFound();
if (user == null || userFromQuery == null) return this.NotFound();
List<Photo> photos = await this.database.Photos.Include
(p => p.Creator)
@ -100,7 +100,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{
User? userFromQuery = await this.database.Users.FirstOrDefaultAsync(u => u.Username == user);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (user == null) return this.NotFound();
if (user == null || userFromQuery == null) return this.NotFound();
List<Photo> photos = new();
foreach (Photo photo in this.database.Photos.Include(p => p.Creator))

View file

@ -80,7 +80,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
await this.database.SaveChangesAsync();
string myRanking = await GetScores(score.SlotId, score.Type, user);
string myRanking = GetScores(score.SlotId, score.Type, user);
return this.Ok(myRanking);
}
@ -99,10 +99,10 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (user == null) return this.StatusCode(403, "");
return this.Ok(await GetScores(slotId, type, user, pageStart, pageSize));
return this.Ok(GetScores(slotId, type, user, pageStart, pageSize));
}
public async Task<string> GetScores(int slotId, int type, User user, int pageStart = -1, int pageSize = 5)
public string GetScores(int slotId, int type, User user, int pageStart = -1, int pageSize = 5)
{
// This is hella ugly but it technically assigns the proper rank to a score
// var needed for Anonymous type returned from SELECT

View file

@ -31,7 +31,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
GameVersion gameVersion = token.GameVersion;
User user = await this.database.Users.FirstOrDefaultAsync(dbUser => dbUser.Username == u);
User? user = await this.database.Users.FirstOrDefaultAsync(dbUser => dbUser.Username == u);
if (user == null) return StatusCode(403, "");
string response = Enumerable.Aggregate
(

View file

@ -30,7 +30,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
{
User? user = await this.database.Users.Include(u => u.Location).FirstOrDefaultAsync(u => u.Username == username);
return user?.Serialize(gameVersion);
if (user == null) return "";
return user.Serialize(gameVersion);
}
[HttpGet("user/{username}")]
@ -40,7 +41,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (token == null) return this.StatusCode(403, "");
string? user = await this.GetSerializedUser(username, token.GameVersion);
if (user == null) return this.NotFound();
if (user == "") return this.NotFound();
return this.Ok(user);
}
@ -54,7 +55,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
List<string> serializedUsers = new();
foreach (string userId in u)
{
serializedUsers.Add(await this.GetSerializedUser(userId, token.GameVersion));
string? serializedUser = await this.GetSerializedUser(userId, token.GameVersion);
if (serializedUser != "") serializedUsers.Add(serializedUser);
}
string serialized = serializedUsers.Aggregate(string.Empty, (current, u) => u == null ? current : current + u);
@ -68,8 +70,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
[HttpPost("updateUser")]
public async Task<IActionResult> UpdateUser()
{
User user = await this.database.UserFromRequest(this.Request);
User? user = await this.database.UserFromRequest(this.Request);
if (user == null) return this.StatusCode(403, "");
XmlReaderSettings settings = new()
@ -144,8 +145,8 @@ namespace LBPUnion.ProjectLighthouse.Controllers
// the way location on a user card works is stupid and will not save with the way below as-is, so we do the following:
if (locationChanged) // only modify the database if we modify here
{
Location l = await this.database.Locations.Where(l => l.Id == user.LocationId).FirstOrDefaultAsync(); // find the location in the database again
Location? l = await this.database.Locations.Where(l => l.Id == user.LocationId).FirstOrDefaultAsync(); // find the location in the database again
if (l == null) return this.StatusCode(403, "");
// set the location in the database to the one we modified above
l.X = user.Location.X;
l.Y = user.Location.Y;
@ -160,11 +161,11 @@ namespace LBPUnion.ProjectLighthouse.Controllers
[HttpPost("update_my_pins")]
public async Task<IActionResult> UpdateMyPins()
{
User user = await this.database.UserFromRequest(this.Request);
User? user = await this.database.UserFromRequest(this.Request);
if (user == null) return this.StatusCode(403, "");
string pinsString = await new StreamReader(this.Request.Body).ReadToEndAsync();
Pins pinJson = JsonSerializer.Deserialize<Pins>(pinsString);
Pins? pinJson = JsonSerializer.Deserialize<Pins>(pinsString);
if (pinJson == null) return this.BadRequest();