Compare commits

...

5 Commits
main ... Login

Author SHA1 Message Date
Louis LABORIE c392815ae5
continuous-integration/drone/push Build is passing Details
4 months ago
Louis LABORIE 6a8ef3d1e9
continuous-integration/drone/push Build is passing Details
4 months ago
Louis LABORIE 3dd55ed594 Try to deploy with db
4 months ago
Louis LABORIE 4b924f815e Supprimer 'Server/FirstTest.db'
continuous-integration/drone/push Build is passing Details
4 months ago
Louis LABORIE 0e808cd004 Implement login method 🌱🌱
continuous-integration/drone/push Build is passing Details
4 months ago

@ -61,6 +61,7 @@ steps:
- main
- rebase
- pipeline
- Login
- name: deploy-container
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest

@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure;
public class ApplicationDbContext : IdentityDbContext<IdentityUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) :
base(options)
{ }
}

@ -27,7 +27,7 @@ public class User : EntityBase
public ESport? ESport { get; set; }
public ESleepLevel? ESleepLevel { get; set; }
public ESportLevel? ESportLevel { get; set; }
public string HashPassword { get; set; }
public string? HashPassword { get; set; }
public string? OAuthProvider { get; set; }

@ -8,6 +8,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>

@ -0,0 +1,197 @@
// <auto-generated />
using Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Infrastructure.Migrations
{
[DbContext(typeof(OptifitDbContext))]
[Migration("20250212145647_Initialize")]
partial class Initialize
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
modelBuilder.Entity("Infrastructure.Entities.Exercice", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Duration")
.HasColumnType("REAL");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbRepetitions")
.HasColumnType("INTEGER");
b.Property<int>("NbSeries")
.HasColumnType("INTEGER");
b.Property<string>("SessionId")
.HasColumnType("TEXT");
b.Property<string>("Video")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("SessionId");
b.ToTable("Exercices");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Duration")
.HasColumnType("REAL");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("TrainingProgramId")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("TrainingProgramId");
b.ToTable("Sessions");
});
modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Difficulty")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("WeekDuration")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Programs");
});
modelBuilder.Entity("Infrastructure.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("EGoal")
.HasColumnType("TEXT");
b.Property<int>("EHealthProblem")
.HasColumnType("INTEGER");
b.Property<int?>("ESleepLevel")
.HasColumnType("INTEGER");
b.Property<int?>("ESport")
.HasColumnType("INTEGER");
b.Property<int?>("ESportLevel")
.HasColumnType("INTEGER");
b.Property<string>("HashPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Height")
.HasColumnType("REAL");
b.Property<string>("Logo")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbSessionPerWeek")
.HasColumnType("INTEGER");
b.Property<string>("OAuthId")
.HasColumnType("TEXT");
b.Property<string>("OAuthProvider")
.HasColumnType("TEXT");
b.Property<bool>("Sexe")
.HasColumnType("INTEGER");
b.Property<float>("Weight")
.HasColumnType("REAL");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("Infrastructure.Entities.Exercice", b =>
{
b.HasOne("Infrastructure.Entities.Session", null)
.WithMany("Exercices")
.HasForeignKey("SessionId");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.HasOne("Infrastructure.Entities.TrainingProgram", null)
.WithMany("Sessions")
.HasForeignKey("TrainingProgramId");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.Navigation("Exercices");
});
modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b =>
{
b.Navigation("Sessions");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,125 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations
{
/// <inheritdoc />
public partial class Initialize : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Programs",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
WeekDuration = table.Column<int>(type: "INTEGER", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
Difficulty = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Programs", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
Age = table.Column<int>(type: "INTEGER", nullable: false),
Height = table.Column<float>(type: "REAL", nullable: false),
Weight = table.Column<float>(type: "REAL", nullable: false),
Sexe = table.Column<bool>(type: "INTEGER", nullable: false),
Logo = table.Column<string>(type: "TEXT", nullable: false),
NbSessionPerWeek = table.Column<int>(type: "INTEGER", nullable: false),
EGoal = table.Column<string>(type: "TEXT", nullable: true),
EHealthProblem = table.Column<int>(type: "INTEGER", nullable: false),
ESport = table.Column<int>(type: "INTEGER", nullable: true),
ESleepLevel = table.Column<int>(type: "INTEGER", nullable: true),
ESportLevel = table.Column<int>(type: "INTEGER", nullable: true),
HashPassword = table.Column<string>(type: "TEXT", nullable: false),
OAuthProvider = table.Column<string>(type: "TEXT", nullable: true),
OAuthId = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Sessions",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
Duration = table.Column<float>(type: "REAL", nullable: false),
TrainingProgramId = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Sessions", x => x.Id);
table.ForeignKey(
name: "FK_Sessions_Programs_TrainingProgramId",
column: x => x.TrainingProgramId,
principalTable: "Programs",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Exercices",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
Duration = table.Column<float>(type: "REAL", nullable: false),
Image = table.Column<string>(type: "TEXT", nullable: false),
Video = table.Column<string>(type: "TEXT", nullable: false),
NbSeries = table.Column<int>(type: "INTEGER", nullable: false),
NbRepetitions = table.Column<int>(type: "INTEGER", nullable: false),
SessionId = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Exercices", x => x.Id);
table.ForeignKey(
name: "FK_Exercices_Sessions_SessionId",
column: x => x.SessionId,
principalTable: "Sessions",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_Exercices_SessionId",
table: "Exercices",
column: "SessionId");
migrationBuilder.CreateIndex(
name: "IX_Sessions_TrainingProgramId",
table: "Sessions",
column: "TrainingProgramId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Exercices");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Sessions");
migrationBuilder.DropTable(
name: "Programs");
}
}
}

@ -0,0 +1,196 @@
// <auto-generated />
using Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Infrastructure.Migrations
{
[DbContext(typeof(OptifitDbContext))]
[Migration("20250212152834_Second")]
partial class Second
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
modelBuilder.Entity("Infrastructure.Entities.Exercice", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Duration")
.HasColumnType("REAL");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbRepetitions")
.HasColumnType("INTEGER");
b.Property<int>("NbSeries")
.HasColumnType("INTEGER");
b.Property<string>("SessionId")
.HasColumnType("TEXT");
b.Property<string>("Video")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("SessionId");
b.ToTable("Exercices");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Duration")
.HasColumnType("REAL");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("TrainingProgramId")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("TrainingProgramId");
b.ToTable("Sessions");
});
modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Difficulty")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("WeekDuration")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Programs");
});
modelBuilder.Entity("Infrastructure.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("EGoal")
.HasColumnType("TEXT");
b.Property<int>("EHealthProblem")
.HasColumnType("INTEGER");
b.Property<int?>("ESleepLevel")
.HasColumnType("INTEGER");
b.Property<int?>("ESport")
.HasColumnType("INTEGER");
b.Property<int?>("ESportLevel")
.HasColumnType("INTEGER");
b.Property<string>("HashPassword")
.HasColumnType("TEXT");
b.Property<float>("Height")
.HasColumnType("REAL");
b.Property<string>("Logo")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbSessionPerWeek")
.HasColumnType("INTEGER");
b.Property<string>("OAuthId")
.HasColumnType("TEXT");
b.Property<string>("OAuthProvider")
.HasColumnType("TEXT");
b.Property<bool>("Sexe")
.HasColumnType("INTEGER");
b.Property<float>("Weight")
.HasColumnType("REAL");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("Infrastructure.Entities.Exercice", b =>
{
b.HasOne("Infrastructure.Entities.Session", null)
.WithMany("Exercices")
.HasForeignKey("SessionId");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.HasOne("Infrastructure.Entities.TrainingProgram", null)
.WithMany("Sessions")
.HasForeignKey("TrainingProgramId");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.Navigation("Exercices");
});
modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b =>
{
b.Navigation("Sessions");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations
{
/// <inheritdoc />
public partial class Second : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "HashPassword",
table: "Users",
type: "TEXT",
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "HashPassword",
table: "Users",
type: "TEXT",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "TEXT",
oldNullable: true);
}
}
}

@ -0,0 +1,193 @@
// <auto-generated />
using Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Infrastructure.Migrations
{
[DbContext(typeof(OptifitDbContext))]
partial class OptifitDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.1");
modelBuilder.Entity("Infrastructure.Entities.Exercice", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Duration")
.HasColumnType("REAL");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbRepetitions")
.HasColumnType("INTEGER");
b.Property<int>("NbSeries")
.HasColumnType("INTEGER");
b.Property<string>("SessionId")
.HasColumnType("TEXT");
b.Property<string>("Video")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("SessionId");
b.ToTable("Exercices");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Duration")
.HasColumnType("REAL");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("TrainingProgramId")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("TrainingProgramId");
b.ToTable("Sessions");
});
modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Difficulty")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("WeekDuration")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Programs");
});
modelBuilder.Entity("Infrastructure.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("EGoal")
.HasColumnType("TEXT");
b.Property<int>("EHealthProblem")
.HasColumnType("INTEGER");
b.Property<int?>("ESleepLevel")
.HasColumnType("INTEGER");
b.Property<int?>("ESport")
.HasColumnType("INTEGER");
b.Property<int?>("ESportLevel")
.HasColumnType("INTEGER");
b.Property<string>("HashPassword")
.HasColumnType("TEXT");
b.Property<float>("Height")
.HasColumnType("REAL");
b.Property<string>("Logo")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbSessionPerWeek")
.HasColumnType("INTEGER");
b.Property<string>("OAuthId")
.HasColumnType("TEXT");
b.Property<string>("OAuthProvider")
.HasColumnType("TEXT");
b.Property<bool>("Sexe")
.HasColumnType("INTEGER");
b.Property<float>("Weight")
.HasColumnType("REAL");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("Infrastructure.Entities.Exercice", b =>
{
b.HasOne("Infrastructure.Entities.Session", null)
.WithMany("Exercices")
.HasForeignKey("SessionId");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.HasOne("Infrastructure.Entities.TrainingProgram", null)
.WithMany("Sessions")
.HasForeignKey("TrainingProgramId");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.Navigation("Exercices");
});
modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b =>
{
b.Navigation("Sessions");
});
#pragma warning restore 612, 618
}
}
}

@ -1,9 +1,25 @@
using System.ComponentModel.DataAnnotations;
using Shared;
namespace Server.Dto.Request;
public class RequestUserDto
{
[Required(ErrorMessage = "FirstName is required")]
public string Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public float Height { get; set; }
public float Weight { get; set; }
public bool Sexe { get; set; }
public string? Logo { get; set; }
public int NbSessionPerWeek { get; set; }
public string? EGoal { get; set; }
public ESleepLevel ESleepLevel { get; set; }
public EHealthProblem EHealthProblem { get; set; }
public ESport ESport { get; set; }
public ESportLevel ESportLevel { get; set; }
}

Binary file not shown.

@ -25,15 +25,19 @@ public class UserProfile : Profile
.ForMember(dest => dest.ESport, opt => opt.MapFrom(src => src.ESport));
_ = CreateMap<RequestUserDto, User>()
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name));
//.ForMember(dest => dest.Age, opt => opt.MapFrom(src => src.Age))
//.ForMember(dest => dest.Height, opt => opt.MapFrom(src => src.Height))
//.ForMember(dest => dest.Weight, opt => opt.MapFrom(src => src.Weight))
//.ForMember(dest => dest.Sexe, opt => opt.MapFrom(src => src.Sexe))
//.ForMember(dest => dest.Logo, opt => opt.MapFrom(src => src.Logo))
//.ForMember(dest => dest.NbSessionPerWeek, opt => opt.MapFrom(src => src.NbSessionPerWeek))
//.ForMember(dest => dest.EGoal, opt => opt.MapFrom(src => src.EGoal))
//.ForMember(dest => dest.ESleepLevel, opt => opt.MapFrom(src => src.ESleepLevel));
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
.ForMember(dest => dest.Age, opt => opt.MapFrom(src => src.Age))
.ForMember(dest => dest.Height, opt => opt.MapFrom(src => src.Height))
.ForMember(dest => dest.Weight, opt => opt.MapFrom(src => src.Weight))
.ForMember(dest => dest.Sexe, opt => opt.MapFrom(src => src.Sexe))
.ForMember(dest => dest.Logo, opt => opt.MapFrom(src => src.Logo))
.ForMember(dest => dest.NbSessionPerWeek, opt => opt.MapFrom(src => src.NbSessionPerWeek))
.ForMember(dest => dest.EGoal, opt => opt.MapFrom(src => src.EGoal))
.ForMember(dest => dest.ESleepLevel, opt => opt.MapFrom(src => src.ESleepLevel))
.ForMember(dest => dest.EHealthProblem, opt => opt.MapFrom(src => src.EHealthProblem))
.ForMember(dest => dest.ESportLevel, opt => opt.MapFrom(src => src.ESportLevel))
.ForMember(dest => dest.ESport, opt => opt.MapFrom(src => src.ESport));
}
}

@ -6,6 +6,8 @@ using Server.Services;
using Microsoft.OpenApi.Models;
using Infrastructure.Repositories;
using AutoMapper;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Server.Mappers;
var builder = WebApplication.CreateBuilder(args);
@ -24,7 +26,7 @@ builder.Services.AddScoped<ITrainingProgramRepository, TrainingProgramRepository
builder.Services.AddControllers();
builder.Services.AddDbContext<OptifitDbContext>(options =>
options.UseSqlite("Data Source=../Server/FirstTest.db", b => b.MigrationsAssembly("Infrastructure")));
options.UseSqlite("Data Source=FirstTest.db", b => b.MigrationsAssembly("Infrastructure")));
// Register AutoMapper
builder.Services.AddAutoMapper(typeof(UserProfile));
@ -34,6 +36,8 @@ builder.Services.AddAutoMapper(typeof(PaginatedResultProfile));
builder.Services.AddAutoMapper(typeof(TrainingProgramProfile));
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
@ -50,9 +54,40 @@ builder.Services.AddApiVersioning(options =>
options.SubstituteApiVersionInUrl = true;
});
builder.Services.AddSwaggerGen(c =>
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Optifit API", Version = "v1" })
);
builder.Services.AddSwaggerGen(option =>
{
option.SwaggerDoc("v1", new OpenApiInfo { Title = "Optifit API", Version = "v1" });
option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Description = "Please enter a valid token",
Name = "Authorization",
Type = SecuritySchemeType.Http,
BearerFormat = "JWT",
Scheme = "Bearer"
});
option.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type=ReferenceType.SecurityScheme,
Id="Bearer"
}
},
new string[]{}
}
});
});
builder.Services.AddDbContext<ApplicationDbContext>(
options => options.UseInMemoryDatabase("AppDb"));
builder.Services.AddIdentityApiEndpoints<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddRouting(options => options.LowercaseUrls = true);
@ -70,6 +105,27 @@ if (app.Environment.IsDevelopment())
app.UseHttpsRedirection();
}
app.MapIdentityApi<IdentityUser>();
app.UseAuthorization();
app.MapControllers();
using var scoped = app.Services.CreateScope();
var dataContext = scoped.ServiceProvider.GetService<OptifitDbContext>();
//libraryContext.Database.EnsureCreated();
dataContext.Database.Migrate();
app.MapPost("/logout", async (SignInManager<IdentityUser> signInManager,
[FromBody]object empty) =>
{
if (empty != null)
{
await signInManager.SignOutAsync();
return Results.Ok();
}
return Results.Unauthorized();
})
.WithOpenApi()
.RequireAuthorization();
app.Run();

@ -13,6 +13,7 @@
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>

@ -11,4 +11,8 @@
<Folder Include="Enums\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
</ItemGroup>
</Project>

Loading…
Cancel
Save