Skip to content

Commit

Permalink
Fixed all (30) build warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
stijuh committed May 23, 2023
1 parent b282fb3 commit 76c881d
Show file tree
Hide file tree
Showing 27 changed files with 86 additions and 82 deletions.
22 changes: 11 additions & 11 deletions GainsTracker.ClientNative/GainsTracker.ClientNative.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,33 @@

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4"/>

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128"/>

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
<MauiImage Include="Resources\Images\*"/>
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208"/>

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />
<MauiFont Include="Resources\Fonts\*"/>

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
<!-- <None Remove="Resources\AppIcon\appiconfg.svg" />-->
<MauiIcon Include="Resources\AppIcon\appiconfg.svg" />
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)"/>
<!-- <None Remove="Resources\AppIcon\appiconfg.svg" />-->
<MauiIcon Include="Resources\AppIcon\appiconfg.svg"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GainsTracker.UI\GainsTracker.UI.csproj" />
<ProjectReference Include="..\GainsTracker.UI\GainsTracker.UI.csproj"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GainsTracker.Common\GainsTracker.Common.csproj" />
<ProjectReference Include="..\GainsTracker.Common\GainsTracker.Common.csproj"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Android.App;
using Android.Content.PM;
using Android.OS;

namespace GainsTracker.ClientNative;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ public MainApplication(IntPtr handle, JniHandleOwnership ownership)
{
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
protected override MauiApp CreateMauiApp()
{
return MauiProgram.CreateMauiApp();
}
}
2 changes: 2 additions & 0 deletions GainsTracker.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
public static class Constants
{
public const string BaseUrl = "https://localhost:7045";

public const string AnonymousUserName = "anonymous";
}
6 changes: 6 additions & 0 deletions GainsTracker.Common/DTO/WorkoutTypeDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

public class WorkoutTypeDto
{
public WorkoutTypeDto(string type, string category)
{
Type = type ?? throw new ArgumentNullException(nameof(type));
Category = category ?? throw new ArgumentNullException(nameof(category));
}

public string Type { get; set; }
public string Category { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Security.Claims;
using GainsTracker.Common;
using GainsTracker.CoreAPI.Components.Friends.Models;
using GainsTracker.CoreAPI.Components.Friends.Services;
using GainsTracker.CoreAPI.Components.Friends.Services.Dto;
Expand All @@ -19,7 +20,7 @@ public FriendController(IFriendService friendService)
_friendService = friendService;
}

private string CurrentUsername => User.FindFirstValue(ClaimTypes.Name);
private string CurrentUsername => User.FindFirstValue(ClaimTypes.Name) ?? Constants.AnonymousUserName;

[HttpGet]
public IActionResult GetFriends()
Expand Down
6 changes: 3 additions & 3 deletions GainsTracker.CoreAPI/Components/Friends/Models/Friend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public Friend(GainsAccount account, DateTime friendsSince)
}

public string Id { get; set; } = Guid.NewGuid().ToString();
public string GainsAccountId { get; set; }
public string GainsAccountId { get; set; } = string.Empty;
public DateTime FriendsSince { get; set; }
public string FriendName { get; set; }
public string FriendHandle { get; set; }
public string FriendName { get; set; } = string.Empty;
public string FriendHandle { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public FriendRequest(GainsAccount requestedBy, GainsAccount requestedTo)

public string Id { get; set; } = Guid.NewGuid().ToString();

public string RequestedById { get; set; }
public string RequestedToId { get; set; }
public string RequestedById { get; set; } = string.Empty;
public string RequestedToId { get; set; } = string.Empty;

public GainsAccount RequestedBy { get; }
public GainsAccount RequestedTo { get; }
public GainsAccount RequestedBy { get; set; } = new();
public GainsAccount RequestedTo { get; set; } = new();

public DateTime RequestTime { get; private set; }
public FriendRequestStatus Status { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Security.Claims;
using GainsTracker.Common;
using GainsTracker.CoreAPI.Components.Gains.Models;
using GainsTracker.CoreAPI.Components.Gains.Services;
using GainsTracker.CoreAPI.Components.Gains.Services.Dto;
Expand All @@ -19,7 +20,7 @@ public GainsController(IGainsService service)
_gainsService = service;
}

private string CurrentUsername => User.FindFirstValue(ClaimTypes.Name);
private string CurrentUsername => User.FindFirstValue(ClaimTypes.Name) ?? Constants.AnonymousUserName;

[HttpGet]
public IActionResult GetUserGains()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ public class WorkoutCatalogController : ControllerBase
public IActionResult GetAvailableWorkoutTypes()
{
List<WorkoutTypeDto> workoutTypes = Enum.GetNames<WorkoutType>()
.Select(workoutType => new WorkoutTypeDto
{
Type = workoutType,
Category = WorkoutUtils.GetCategoryFromType(workoutType).GetDisplayName()
}).ToList();
.Select(workoutType => new WorkoutTypeDto(
workoutType,
WorkoutUtils.GetCategoryFromType(workoutType).GetDisplayName())
).ToList();

return Ok(workoutTypes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public Workout GetWorkoutWithMeasurementsById(string id)
//TODO: this query should soon move into its own big brain, specifically for the userprofile stuff.
public void UpdateDisplayNameByUserHandle(string userHandle, string newDisplayName)
{
GainsAccount? gains = Context.GainsAccounts.FirstOrDefault(g => g.UserHandle.ToLower() == userHandle.ToLower());
GainsAccount gains = Context.GainsAccounts.FirstOrDefault(g => g.UserHandle.ToLower() == userHandle.ToLower())
?? throw new NotFoundException("Can't find gains with that userhandle");

//TODO: filter out bad words n shizzle
gains.DisplayName = newDisplayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void CheckFriendRequests(string friendName)
#region Relations

public string Id { get; set; } = Guid.NewGuid().ToString();
public string UserId { get; set; }
public string UserId { get; set; } = string.Empty;

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ namespace GainsTracker.CoreAPI.Components.Gains.Models.Measurements;

public static class MeasurementFactory
{
public static Measurement DeserializeMeasurementFromJson(ExerciseCategory category, JsonDocument measurementData)
public static Measurement DeserializeMeasurementFromJson(ExerciseCategory category, JsonDocument? measurementData)
{
JsonSerializerOptions options = new()
{
PropertyNameCaseInsensitive = true
};

if (measurementData == null)
throw new ArgumentException("Can't deserialize measurement, invalid data provided.");

return (category switch
{
ExerciseCategory.Strength => measurementData.Deserialize<StrengthMeasurement>(options),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ namespace GainsTracker.CoreAPI.Components.Gains.Models.Workouts;
[Table("workout")]
public class Workout
{
// For Hibernate
protected Workout()
{
GainsAccountId = string.Empty;
}

public Workout(string gainsAccountId, WorkoutType type, List<Measurement> measurements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public class MeasurementDto
public string? WorkoutId { get; set; }
public ExerciseCategory Category { get; set; }
public DateTime? TimeOfRecord { get; set; }
public JsonDocument Data { get; set; }
public JsonDocument? Data { get; set; }
}
22 changes: 13 additions & 9 deletions GainsTracker.CoreAPI/Components/Gains/Services/Dto/WorkoutDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace GainsTracker.CoreAPI.Components.Gains.Services.Dto;

public class WorkoutDto
{
private WorkoutDto(string gainsAccountId)
{
GainsAccountId = gainsAccountId;
}

public string Id { get; set; } = "";
public string GainsAccountId { get; set; }
public WorkoutType WorkoutType { get; set; }
Expand All @@ -15,18 +20,17 @@ public static WorkoutDto FromWorkout(Workout workout)
MeasurementDto? bestMeasurement = null;

if (workout.PersonalBest != null)
{
bestMeasurement = new MeasurementDto();
bestMeasurement.WorkoutId = workout.PersonalBest.WorkoutId;
bestMeasurement.TimeOfRecord = workout.PersonalBest.TimeOfRecord;
bestMeasurement.Category = workout.PersonalBest.Category;
bestMeasurement.Data = MeasurementFactory.SerializeMeasurementToJson(workout.PersonalBest);
}
bestMeasurement = new MeasurementDto
{
WorkoutId = workout.PersonalBest.WorkoutId,
TimeOfRecord = workout.PersonalBest.TimeOfRecord,
Category = workout.PersonalBest.Category,
Data = MeasurementFactory.SerializeMeasurementToJson(workout.PersonalBest)
};

return new WorkoutDto
return new WorkoutDto(workout.GainsAccountId)
{
Id = workout.Id,
GainsAccountId = workout.GainsAccountId,
WorkoutType = workout.WorkoutType,
PersonalBest = bestMeasurement
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace GainsTracker.CoreAPI.Components.Security.Controllers.DTO;

public class LoginRequestDto
{
[Required] public string? UserHandle { get; set; }
[Required] public string? Password { get; set; }
[Required] public string UserHandle { get; set; } = string.Empty;
[Required] public string Password { get; set; } = string.Empty;
}
2 changes: 1 addition & 1 deletion GainsTracker.CoreAPI/Components/Security/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace GainsTracker.CoreAPI.Components.Security.Models;
public class User : IdentityUser
{
public override string Id { get; set; } = Guid.NewGuid().ToString();
public GainsAccount GainsAccount { get; set; }
public GainsAccount GainsAccount { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<string> Register(RegisterRequestDto request)
}
};

IdentityResult? result = await _userManager.CreateAsync(user, request.Password);
IdentityResult result = await _userManager.CreateAsync(user, request.Password);

if (!result.Succeeded) throw new ArgumentException($"Unable to register user {request.UserHandle} errors: {GetErrorsText(result.Errors)}");

Expand All @@ -49,14 +49,18 @@ public async Task<string> Register(RegisterRequestDto request)

public async Task<string> Login(LoginRequestDto request)
{
User? user = await _userManager.FindByNameAsync(request.UserHandle) ?? await _userManager.FindByEmailAsync(request.UserHandle);
ValidateLoginRequest(request);

if (user is null)
throw new NotFoundException("There is no user found with that username");
User user = await _userManager.FindByNameAsync(request.UserHandle)
?? await _userManager.FindByEmailAsync(request.UserHandle)
?? throw new NotFoundException("There is no user found with that username");

if (!await _userManager.CheckPasswordAsync(user, request.Password))
throw new UnauthorizedException($"Unable to authenticate user {request.UserHandle}");

if (string.IsNullOrEmpty(user.UserName) || string.IsNullOrEmpty(user.Email))
throw new BadRequestException("Invalid credentials.");

List<Claim> authClaims = new()
{
new Claim(ClaimTypes.Name, user.UserName),
Expand Down Expand Up @@ -87,4 +91,10 @@ private string GetErrorsText(IEnumerable<IdentityError> errors)
{
return string.Join(", ", errors.Select(error => error.Description).ToArray());
}

private void ValidateLoginRequest(LoginRequestDto login)
{
if (string.IsNullOrEmpty(login.UserHandle) || string.IsNullOrEmpty(login.Password))
throw new BadRequestException("Invalid credentials.");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Security.Claims;
using GainsTracker.Common;
using GainsTracker.CoreAPI.Components.Gains.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -17,7 +18,7 @@ public UserProfileController(IGainsService gainsService)
_gainsService = gainsService;
}

private string CurrentUsername => User.FindFirstValue(ClaimTypes.Name);
private string CurrentUsername => User.FindFirstValue(ClaimTypes.Name) ?? Constants.AnonymousUserName;

//TODO: make this into a bigger updating profile thing with a dto, not little parts like this.
[HttpGet("displayname")]
Expand Down
9 changes: 0 additions & 9 deletions GainsTracker.CoreAPI/Configurations/Database/BigBrain.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using GainsTracker.Common.Exceptions;
using GainsTracker.CoreAPI.Components.Gains.Models;
using GainsTracker.CoreAPI.Components.Security.Models;

namespace GainsTracker.CoreAPI.Configurations.Database;

Expand All @@ -24,14 +23,6 @@ public void SaveContext()
Context.SaveChanges();
}

public User GetUserByUsername(string userHandle)
{
User? user = Context.Users.FirstOrDefault(u =>
string.Equals(u.UserName.ToLower(), userHandle.ToLower()));

return user ?? throw new NotFoundException("User with that name not found");
}

public GainsAccount GetGainsAccountByUsername(string userHandle)
{
GainsAccount? gains = Context.GainsAccounts.FirstOrDefault(gains =>
Expand Down
8 changes: 3 additions & 5 deletions GainsTracker.CoreAPI/Configurations/Database/DbInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ public DbInitializer(ModelBuilder builder)
public void Seed()
{
const string ADMIN_ID = "a18be9c0-aa65-4af8-bd17-00bd9344e575";
const string GAINSACCOUNT_ID = "e58eddff-d5be-46c1-9c99-1283d54152d1";
const string GAINSACCOUNT_ID2 = "e58addff-d5be-46c1-9c99-1283d54152d1";
const string WORKOUT_ID1 = "a58eddff-d5be-46c1-9c99-1283d54152d1";
const string WORKOUT_ID2 = "B58eddff-d5be-46c1-9c99-1283d54152d1";

const string SIMPLE_USER_ID = "e18be9c0-aa65-4af8-bd17-00bd9344e575";
const string SIMPLE_USER_ID2 = "B18be9c0-aa65-4af8-bd17-00bd9344e575";

const string GAINSACCOUNT_ID = "e58eddff-d5be-46c1-9c99-1283d54152d1";
const string GAINSACCOUNT_ID2 = "e58addff-d5be-46c1-9c99-1283d54152d1";

const string ROLE_ID = ADMIN_ID;

_builder.Entity<IdentityRole>().HasData(new IdentityRole
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static void ConfigureAuthentication(this WebApplicationBuilder builder)
ValidateAudience = true,
ValidAudience = builder.Configuration["JWT:ValidAudience"],
ValidIssuer = builder.Configuration["JWT:ValidIssuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["JWT:Secret"]))
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["JWT:Secret"]!))
};
});
}
Expand Down
2 changes: 1 addition & 1 deletion GainsTracker.UI/Services/GainsAuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task<bool> PingApiHealth()
try
{
HttpResponseMessage response = await _httpClient.GetAsync(url);
JsonNode jsonString = JsonNode.Parse(await response.Content.ReadAsStringAsync());
JsonNode? jsonString = JsonNode.Parse(await response.Content.ReadAsStringAsync());

Debug.WriteLine(jsonString?["status"]?.ToString() == "UP"
? "Server successfully responded."
Expand Down
2 changes: 1 addition & 1 deletion GainsTracker.UI/Services/GainsTrackerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task<string> GetUserWorkouts()
{
Debug.WriteLine("uh oh:");
Debug.WriteLine(ex);
return null;
return string.Empty;
}
}
}
Loading

0 comments on commit 76c881d

Please sign in to comment.