Introduice TrainingSVC + DataEntities relations

features/training-svc
Leo TUAILLON 3 weeks ago
parent 143ba29d60
commit 2c791baa06

@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CatalogService", "src\Catal
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "src\Shared\Shared.csproj", "{BF49B348-4188-4AC7-9ED4-5837F4B3BCD2}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "src\Shared\Shared.csproj", "{BF49B348-4188-4AC7-9ED4-5837F4B3BCD2}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrainingSvc", "src\TrainingSvc\TrainingSvc.csproj", "{F16873D3-6511-48AA-B74E-8B13D5F20F20}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -26,9 +28,14 @@ Global
{BF49B348-4188-4AC7-9ED4-5837F4B3BCD2}.Debug|Any CPU.Build.0 = Debug|Any CPU {BF49B348-4188-4AC7-9ED4-5837F4B3BCD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BF49B348-4188-4AC7-9ED4-5837F4B3BCD2}.Release|Any CPU.ActiveCfg = Release|Any CPU {BF49B348-4188-4AC7-9ED4-5837F4B3BCD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BF49B348-4188-4AC7-9ED4-5837F4B3BCD2}.Release|Any CPU.Build.0 = Release|Any CPU {BF49B348-4188-4AC7-9ED4-5837F4B3BCD2}.Release|Any CPU.Build.0 = Release|Any CPU
{F16873D3-6511-48AA-B74E-8B13D5F20F20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F16873D3-6511-48AA-B74E-8B13D5F20F20}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F16873D3-6511-48AA-B74E-8B13D5F20F20}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F16873D3-6511-48AA-B74E-8B13D5F20F20}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution GlobalSection(NestedProjects) = preSolution
{54BE8DE8-08BD-429F-BCCA-3363A879D922} = {2A7200CA-F40B-4715-8726-4ED30C785FA4} {54BE8DE8-08BD-429F-BCCA-3363A879D922} = {2A7200CA-F40B-4715-8726-4ED30C785FA4}
{BF49B348-4188-4AC7-9ED4-5837F4B3BCD2} = {2A7200CA-F40B-4715-8726-4ED30C785FA4} {BF49B348-4188-4AC7-9ED4-5837F4B3BCD2} = {2A7200CA-F40B-4715-8726-4ED30C785FA4}
{F16873D3-6511-48AA-B74E-8B13D5F20F20} = {2A7200CA-F40B-4715-8726-4ED30C785FA4}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

@ -0,0 +1,10 @@
namespace Shared.Enum;
public enum EDifficulty
{
None,
Beginner,
Intermediate,
Advanced,
Expert
}

@ -0,0 +1,10 @@
namespace Shared.Enum;
public enum EGoal
{
None,
MuscleGain,
WeightLoss,
Endurance,
Strength,
}

@ -0,0 +1,11 @@
using Microsoft.EntityFrameworkCore;
namespace TrainingSvc.Data;
public class TrainingDbContext : DbContext
{
public TrainingDbContext(DbContextOptions options) : base(options)
{
}
}

@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
using Shared.Entities;
namespace TrainingSvc.Entities;
public class ExerciceInstance : EntityBase
{
public required string Name { get; set; }
public string? ExerciceId { get; set; }
public float Duration { get; set; }
public int NbSets { get; set; }
public int NbReps { get; set; }
public float RestingTime { get; set; }
public float? Weight { get; set; }
public bool IsDone { get; set; }
[Required]
public string SessionId { get; set; }
public Session Session { get; set; }
}

@ -0,0 +1,24 @@
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using Shared.Entities;
using Shared.Enum;
namespace TrainingSvc.Entities;
public class Session : EntityBase
{
public required string Name { get; set; }
public string? Description { get; set; }
[Range(1, 7)]
public int Day { get; set; }
public ETarget? Target { get; set; }
[Required]
public string TrainingProgramId { get; set; }
public TrainingProgram TrainingProgram { get; set; }
public virtual ICollection<ExerciceInstance> Exercices { get; set; } = new Collection<ExerciceInstance>();
}

@ -0,0 +1,26 @@
using System.Collections.ObjectModel;
using Shared.Entities;
using Shared.Enum;
namespace TrainingSvc.Entities;
public class TrainingProgram : EntityBase
{
public string Lang { get; set; } = "en";
public required string Name { get; set; }
public string? Description { get; set; }
public int WeekDuration { get; set; } = 4;
public int NbDays { get; set; } = 3;
public string OwnerId { get; set; } = "";
public EGoal Goal { get; set; } = EGoal.MuscleGain;
public EDifficulty Difficulty { get; set; } = EDifficulty.Beginner;
public virtual ICollection<Session> Sessions { get; set; } = new Collection<Session>();
}

@ -0,0 +1,33 @@
using TrainingSvc.Data;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddDbContext<TrainingDbContext>(opt =>
{
opt.UseNpgsql(builder.Configuration.GetConnectionString("TrainingDb"));
});
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
var app = builder.Build();
app.UseAuthorization();
app.MapControllers();
try
{
//NOT IMPLEMENTED
app.MapGet("/", () => "Hello World!");
//DbInitializer.InitDb(app);
}
catch (Exception e)
{
Console.WriteLine(e);
}
app.Run();

@ -0,0 +1,15 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:7002",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.15" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.11" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,6 @@
@TrainingSvc_HostAddress = http://localhost:5269
GET {{TrainingSvc_HostAddress}}/weatherforecast/
Accept: application/json
###
Loading…
Cancel
Save