Skip to content

Commit a3801b2

Browse files
committed
Add user-workout relationship and seed database
1 parent baa7973 commit a3801b2

File tree

9 files changed

+725
-7
lines changed

9 files changed

+725
-7
lines changed

src/API/Extensions/ServiceExtensions.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public static class ServiceExtensions
1717
{
1818
public static void ConfigureSqlContext(this IServiceCollection services, IConfiguration configuration)
1919
{
20-
var connectionString = configuration["ConnectionStrings:Database"];
20+
//var connectionString = configuration["ConnectionStrings:Database"];
21+
var connectionString = "Server=127.0.0.1\\mssql,1433;Database=WorkoutTrackerDB;User=sa;Password=/Password12;TrustServerCertificate=Yes";
2122

2223
services.AddDbContext<ApplicationContext>(opt =>
2324
{
@@ -42,8 +43,9 @@ public static void ConfigureFilters(this IServiceCollection services)
4243
{
4344
services.AddScoped<ValidationFilterAttribute>();
4445
services.AddScoped<ExerciseExistsFilterAttribute>();
45-
services.AddScoped<WorkoutExistsFilterAttribute>();
46+
services.AddScoped<WorkoutForUserExistsFilterAttribute>();
4647
services.AddScoped<WorkoutExerciseExistsFilterAttribute>();
48+
services.AddScoped<UserExistsFilterAttribute>();
4749
}
4850

4951
public static void ConfigureSwagger(this IServiceCollection services)
@@ -85,9 +87,19 @@ public static void ConfigureAuthenticationAndAuthorization(this IServiceCollecti
8587
public static async Task SeedDatabase(this WebApplication app)
8688
{
8789
using var scope = app.Services.CreateScope();
88-
var dbSeeder = scope.ServiceProvider.GetRequiredService<AuthDbSeeder>();
90+
var authDbSeeder = scope.ServiceProvider.GetRequiredService<AuthDbSeeder>();
91+
var dbSeeder = scope.ServiceProvider.GetRequiredService<DbSeeder>();
8992

93+
await authDbSeeder.SeedAsync();
9094
await dbSeeder.SeedAsync();
9195
}
96+
97+
public static void RunMigrations(this WebApplication app)
98+
{
99+
using var scope = app.Services.CreateScope();
100+
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationContext>();
101+
102+
dbContext.Database.Migrate();
103+
}
92104
}
93105
}

0 commit comments

Comments
 (0)