From e690a649e8d42348437f45920a6a11cfbb1ade48 Mon Sep 17 00:00:00 2001 From: troogs Date: Sat, 31 Jan 2026 01:13:23 +0100 Subject: [PATCH] feat: add sample data population for new users and improve exercise list layout --- src/ASTRAIN.Api/Services/UserProvisioning.cs | 54 ++++++++++++++++++++ src/ASTRAIN.Client/Pages/Exercises.razor | 12 +++-- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/ASTRAIN.Api/Services/UserProvisioning.cs b/src/ASTRAIN.Api/Services/UserProvisioning.cs index 0211395..228ab8a 100644 --- a/src/ASTRAIN.Api/Services/UserProvisioning.cs +++ b/src/ASTRAIN.Api/Services/UserProvisioning.cs @@ -29,6 +29,7 @@ internal static class UserProvisioning var created = new User { Id = userId }; db.Users.Add(created); await db.SaveChangesAsync(); + await PopulateSampleDataAsync(db, created); return created; } @@ -44,10 +45,63 @@ internal static class UserProvisioning var user = new User { Id = newId }; db.Users.Add(user); await db.SaveChangesAsync(); + await PopulateSampleDataAsync(db, user); return user; } } + /// + /// Populates a new user with sample exercises and routines for debugging. + /// + /// The application database context. + /// The newly created user. + private static async Task PopulateSampleDataAsync(AppDbContext db, User user) + { + // Sample exercises + var exercises = new[] + { + new Exercise { Name = "Push-ups", UserId = user.Id }, + new Exercise { Name = "Squats", UserId = user.Id }, + new Exercise { Name = "Pull-ups", UserId = user.Id }, + new Exercise { Name = "Bench Press", UserId = user.Id }, + new Exercise { Name = "Deadlift", UserId = user.Id } + }; + + db.Exercises.AddRange(exercises); + await db.SaveChangesAsync(); + + // Sample routines + var routine1 = new Routine { Name = "Upper Body", UserId = user.Id }; + var routine2 = new Routine { Name = "Lower Body", UserId = user.Id }; + + db.Routines.AddRange(routine1, routine2); + await db.SaveChangesAsync(); + + // Associate exercises with routines + var pushUps = exercises.First(e => e.Name == "Push-ups"); + var pullUps = exercises.First(e => e.Name == "Pull-ups"); + var benchPress = exercises.First(e => e.Name == "Bench Press"); + var squats = exercises.First(e => e.Name == "Squats"); + var deadlift = exercises.First(e => e.Name == "Deadlift"); + + var routineExercises1 = new[] + { + new RoutineExercise { RoutineId = routine1.Id, ExerciseId = pushUps.Id, Order = 0 }, + new RoutineExercise { RoutineId = routine1.Id, ExerciseId = pullUps.Id, Order = 1 }, + new RoutineExercise { RoutineId = routine1.Id, ExerciseId = benchPress.Id, Order = 2 } + }; + + var routineExercises2 = new[] + { + new RoutineExercise { RoutineId = routine2.Id, ExerciseId = squats.Id, Order = 0 }, + new RoutineExercise { RoutineId = routine2.Id, ExerciseId = deadlift.Id, Order = 1 } + }; + + db.RoutineExercises.AddRange(routineExercises1); + db.RoutineExercises.AddRange(routineExercises2); + await db.SaveChangesAsync(); + } + /// /// Determines whether a user id matches the expected format. /// diff --git a/src/ASTRAIN.Client/Pages/Exercises.razor b/src/ASTRAIN.Client/Pages/Exercises.razor index 2e66478..a503992 100644 --- a/src/ASTRAIN.Client/Pages/Exercises.razor +++ b/src/ASTRAIN.Client/Pages/Exercises.razor @@ -41,17 +41,19 @@
@foreach (var exercise in ExerciseList) { -
+
@if (EditingId == exercise.Id) { - - +
+ + +
} else { -
@exercise.Name
-
+
@exercise.Name
+