Skip to content

Commit

Permalink
Moved most dto's to common folder
Browse files Browse the repository at this point in the history
  • Loading branch information
stijuh committed Jun 8, 2023
1 parent 2b44e88 commit 10f2930
Show file tree
Hide file tree
Showing 23 changed files with 110 additions and 100 deletions.
4 changes: 4 additions & 0 deletions GainsTracker.Common/GainsTracker.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Folder Include="Models\Measurements\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace GainsTracker.CoreAPI.Components.Workouts.Models.Measurements.Units;
namespace GainsTracker.Common.Models.Measurements.Units;

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum DistanceUnits
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace GainsTracker.CoreAPI.Components.Workouts.Models.Measurements.Units;
namespace GainsTracker.Common.Models.Measurements.Units;

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum TimeUnits
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace GainsTracker.CoreAPI.Components.Workouts.Models.Measurements.Units;
namespace GainsTracker.Common.Models.Measurements.Units;

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum WeightUnits
Expand Down
7 changes: 7 additions & 0 deletions GainsTracker.Common/Models/Workouts/Dto/CreateWorkoutDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace GainsTracker.Common.Models.Workouts.Dto;

public class CreateWorkoutDto
{
public string GainsAccountId { get; set; } = string.Empty;
public WorkoutType WorkoutType { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Text.Json;
using GainsTracker.CoreAPI.Components.Workouts.Models.Measurements.Units;
using GainsTracker.Common.Models.Measurements.Units;
using GainsTracker.CoreAPI.Components.Workouts.Models.Workouts;

namespace GainsTracker.CoreAPI.Components.Workouts.Services.Dto;
namespace GainsTracker.Common.Models.Workouts.Dto;

public class MeasurementDto
{
Expand Down
14 changes: 14 additions & 0 deletions GainsTracker.Common/Models/Workouts/Dto/WorkoutDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace GainsTracker.Common.Models.Workouts.Dto;

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

public string Id { get; set; } = "";
public string GainsAccountId { get; set; }
public WorkoutType WorkoutType { get; set; }
public MeasurementDto? PersonalBest { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GainsTracker.Common.Models.Workouts.Dto;

public class WorkoutMeasurementsDto
{
public string Id { get; set; } = "";
public List<MeasurementDto> Measurements { get; set; } = new();


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace GainsTracker.CoreAPI.Components.Workouts.Models.Workouts;
namespace GainsTracker.Common.Models.Workouts;

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum WorkoutType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json;
using GainsTracker.Common.Models.Generic;
using GainsTracker.CoreAPI.Components.Workouts.Services.Dto;
using GainsTracker.Common.Models.Workouts.Dto;
using Microsoft.AspNetCore.Mvc;

namespace GainsTracker.CoreAPI.Components.Workouts.Controllers.Examples;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GainsTracker.Common.Models.Workouts.Dto;
using GainsTracker.CoreAPI.Components.Workouts.Models;
using GainsTracker.CoreAPI.Components.Workouts.Services;
using GainsTracker.CoreAPI.Components.Workouts.Services.Dto;
using GainsTracker.CoreAPI.Shared;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GainsTracker.Common.DTO;
using GainsTracker.Common.Models.Workouts;
using GainsTracker.CoreAPI.Components.Workouts.Models.Workouts;
using Microsoft.AspNetCore.Mvc;
using Microsoft.OpenApi.Extensions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using GainsTracker.Common.Models.Generic;
using GainsTracker.CoreAPI.Components.Workouts.Models.Measurements.Units;
using GainsTracker.Common.Models.Measurements.Units;
using GainsTracker.CoreAPI.Components.Workouts.Models.Workouts;

namespace GainsTracker.CoreAPI.Components.Workouts.Models.Measurements;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using GainsTracker.Common.Models.Workouts;
using GainsTracker.CoreAPI.Components.Workouts.Models.Measurements;

namespace GainsTracker.CoreAPI.Components.Workouts.Models.Workouts;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace GainsTracker.CoreAPI.Components.Workouts.Models.Workouts;
using GainsTracker.Common.Models.Workouts;

namespace GainsTracker.CoreAPI.Components.Workouts.Models.Workouts;

public static class WorkoutUtils
{
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using GainsTracker.CoreAPI.Components.Workouts.Data;
using GainsTracker.Common.Models.Workouts.Dto;
using GainsTracker.CoreAPI.Components.Workouts.Data;
using GainsTracker.CoreAPI.Components.Workouts.Models;
using GainsTracker.CoreAPI.Components.Workouts.Models.Measurements;
using GainsTracker.CoreAPI.Components.Workouts.Models.Workouts;
using GainsTracker.CoreAPI.Components.Workouts.Services.Dto;

namespace GainsTracker.CoreAPI.Components.Workouts.Services;

Expand All @@ -26,7 +26,7 @@ public async Task<List<WorkoutDto>> GetWorkoutsByUsername(string username)
{
string id = _bigBrain.GetGainsIdByUsername(username);
return (await _bigBrain.GetWorkoutsByGainsId(id))
.Select(WorkoutDto.FromWorkout)
.Select(w => w.ToDto())
.ToList();
}

Expand All @@ -42,7 +42,7 @@ public void AddWorkoutToGainsAccount(string username, CreateWorkoutDto workoutDt
public WorkoutMeasurementsDto GetWorkoutMeasurementsById(string workoutId)
{
Workout workout = _bigBrain.GetWorkoutWithMeasurementsById(workoutId);
return WorkoutMeasurementsDto.FromWorkout(workout);
return workout.ToMeasurementsListDto();
}

public void AddMeasurementToWorkout(string workoutId, MeasurementDto dto)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using GainsTracker.CoreAPI.Components.Workouts.Models;
using GainsTracker.CoreAPI.Components.Workouts.Services.Dto;
using GainsTracker.Common.Models.Workouts.Dto;
using GainsTracker.CoreAPI.Components.Workouts.Models;

namespace GainsTracker.CoreAPI.Components.Workouts.Services;

Expand Down
45 changes: 45 additions & 0 deletions GainsTracker.CoreAPI/Components/Workouts/WorkoutExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using GainsTracker.Common.Models.Workouts.Dto;
using GainsTracker.CoreAPI.Components.Workouts.Models.Measurements;
using GainsTracker.CoreAPI.Components.Workouts.Models.Workouts;

namespace GainsTracker.CoreAPI.Components.Workouts;

public static class WorkoutExtensions
{
public static WorkoutDto ToDto(this Workout workout)
{
MeasurementDto? bestMeasurement = null;

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

return new WorkoutDto(workout.GainsAccountId)
{
Id = workout.Id,
WorkoutType = workout.WorkoutType,
PersonalBest = bestMeasurement
};
}

public static WorkoutMeasurementsDto ToMeasurementsListDto(this Workout workout)
{
return new WorkoutMeasurementsDto
{
Id = workout.Id,
Measurements = workout.Measurements
.Select(m => new MeasurementDto
{
WorkoutId = m.WorkoutId,
Category = m.Category,
TimeOfRecord = m.TimeOfRecord,
Data = MeasurementFactory.SerializeMeasurementToJson(m)
}).ToList()
};
}
}
22 changes: 11 additions & 11 deletions GainsTracker.CoreAPI/GainsTracker.CoreAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.1"/>
<PackageReference Include="EFCore.NamingConventions" Version="7.0.2"/>
<PackageReference Include="EntityFramework" Version="6.4.4"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.15"/>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.15"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4"/>
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="EFCore.NamingConventions" Version="7.0.2" />
<PackageReference Include="EntityFramework" Version="6.4.4" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.15" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.15" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.12"/>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3"/>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.12" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

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

0 comments on commit 10f2930

Please sign in to comment.