Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamMorrow committed Jul 28, 2024
1 parent b12adf4 commit 99eb7ae
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 138 deletions.
20 changes: 11 additions & 9 deletions LiftLog.Api/Controllers/EventsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ [FromServices] IValidator<GetEventsRequest> validator
return BadRequest(validationResult.Errors);
}

var validFollowSecrets = await db.UserFollowSecrets.Where(x =>
request.Users.Select(x => x.FollowSecret).Contains(x.Value)
)
var validFollowSecrets = await db
.UserFollowSecrets.Where(x =>
request.Users.Select(x => x.FollowSecret).Contains(x.Value)
)
.ToArrayAsync();
var invalidFollowSecrets = request
.Users.Select(x => x.FollowSecret)
Expand All @@ -39,12 +40,13 @@ [FromServices] IValidator<GetEventsRequest> validator
})
.ToArray();

var events = await db.UserEvents.Join(
db.UserEventFilterStubDbSet.CreateResultSetFromData(userIdsAndSince),
x => x.UserId,
x => x.UserId,
(Event, Request) => new { Event, Request }
)
var events = await db
.UserEvents.Join(
db.UserEventFilterStubDbSet.CreateResultSetFromData(userIdsAndSince),
x => x.UserId,
x => x.UserId,
(Event, Request) => new { Event, Request }
)
.Where(x => x.Event.Expiry > DateTimeOffset.UtcNow)
.Where(x => x.Event.Timestamp > x.Request.Since)
.Select(x => x.Event)
Expand Down
7 changes: 4 additions & 3 deletions LiftLog.Api/Controllers/FollowSecretController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ [FromServices] IValidator<DeleteUserFollowSecretRequest> validator
return Unauthorized();
}

var userFollowSecret = await db.UserFollowSecrets.Where(x =>
x.UserId == request.UserId && x.Value == request.FollowSecret
)
var userFollowSecret = await db
.UserFollowSecrets.Where(x =>
x.UserId == request.UserId && x.Value == request.FollowSecret
)
.ToListAsync();
db.UserFollowSecrets.RemoveRange(userFollowSecret);
await db.SaveChangesAsync();
Expand Down
3 changes: 2 additions & 1 deletion LiftLog.Api/Controllers/InboxController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ [FromServices] IValidator<GetInboxMessagesRequest> validator
return Unauthorized();
}

var inboxItems = await db.UserInboxItems.Where(x => x.UserId == request.UserId)
var inboxItems = await db
.UserInboxItems.Where(x => x.UserId == request.UserId)
.ToArrayAsync();
db.UserInboxItems.RemoveRange(inboxItems);
await db.SaveChangesAsync();
Expand Down
15 changes: 8 additions & 7 deletions LiftLog.Api/Controllers/SharedItemController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ [FromServices] IValidator<CreateSharedItemRequest> validator
[HttpGet]
public async Task<IActionResult> GetSharedItem(string id)
{
var sharedItem = await db.SharedItems.Select(x => new
{
x.Id,
x.User.RsaPublicKey,
x.EncryptedPayload,
x.EncryptionIV
})
var sharedItem = await db
.SharedItems.Select(x => new
{
x.Id,
x.User.RsaPublicKey,
x.EncryptedPayload,
x.EncryptionIV
})
.FirstOrDefaultAsync(x => x.Id == id);
if (sharedItem == null)
{
Expand Down
3 changes: 2 additions & 1 deletion LiftLog.Api/Service/CleanupExpiredDataHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
using var scope = services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<UserDataContext>();
var now = DateTimeOffset.UtcNow;
var expiredEvents = await db.UserEvents.Where(e => e.Expiry < now)
var expiredEvents = await db
.UserEvents.Where(e => e.Expiry < now)
.ToListAsync(cancellationToken: stoppingToken);
db.UserEvents.RemoveRange(expiredEvents);
await db.SaveChangesAsync(stoppingToken);
Expand Down
24 changes: 12 additions & 12 deletions LiftLog.Api/Service/GptAiWorkoutPlanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ Please make me a workout plan.
.Sessions.Select(s => new SessionBlueprint(
s.Name,
s.Exercises.Select(e => new ExerciseBlueprint(
e.Name,
e.Sets,
e.RepsPerSet,
e.WeightIncreaseOnSuccess,
new Rest(
TimeSpan.FromSeconds(e.RestBetweenSets.MinRestSeconds),
TimeSpan.FromSeconds(e.RestBetweenSets.MaxRestSeconds),
TimeSpan.FromSeconds(e.RestBetweenSets.FailureRestSeconds)
),
false,
Notes: ""
))
e.Name,
e.Sets,
e.RepsPerSet,
e.WeightIncreaseOnSuccess,
new Rest(
TimeSpan.FromSeconds(e.RestBetweenSets.MinRestSeconds),
TimeSpan.FromSeconds(e.RestBetweenSets.MaxRestSeconds),
TimeSpan.FromSeconds(e.RestBetweenSets.FailureRestSeconds)
),
false,
Notes: ""
))
.ToImmutableList(),
Notes: s.Description
))
Expand Down
4 changes: 1 addition & 3 deletions LiftLog.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,7 @@ private static void HandleLink(string? link)
MainThread.BeginInvokeOnMainThread(() =>
{
Application
.Current?.Handler
.MauiContext?.Services
.GetRequiredService<Fluxor.IDispatcher>()
.Current?.Handler.MauiContext?.Services.GetRequiredService<Fluxor.IDispatcher>()
.Dispatch(new NavigateAction(path + query));
});
}
Expand Down
5 changes: 2 additions & 3 deletions LiftLog.Maui/Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ protected override void OnCreate(Bundle? savedInstanceState)
base.OnCreate(savedInstanceState);
WindowCompat.SetDecorFitsSystemWindows(Window!, false);
WebViewSoftInputPatch.Initialize();
var insetsManager = IPlatformApplication
.Current?.Services
.GetRequiredService<InsetsManager>();
var insetsManager =
IPlatformApplication.Current?.Services.GetRequiredService<InsetsManager>();
if (insetsManager is not null)
{
insetsManager.SystemSafeInsetBottom =
Expand Down
5 changes: 3 additions & 2 deletions LiftLog.Ui/Models/FeedStateDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ value is null
: new Lib.Services.AesKey(value.AesKey.ToByteArray()),
PublicKey: new Lib.Services.RsaPublicKey(value.PublicKey.ToByteArray()),
CurrentPlan: value
.CurrentPlan?.Sessions
.Select(sessionBlueprintDao => sessionBlueprintDao.ToModel())
.CurrentPlan?.Sessions.Select(sessionBlueprintDao =>
sessionBlueprintDao.ToModel()
)
.ToImmutableList() ?? [],
ProfilePicture: value.ProfilePicture.IsEmpty
? null
Expand Down
58 changes: 29 additions & 29 deletions tests/LiftLog.Tests.App/Blueprints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@ namespace LiftLog.Tests;

public static class Blueprints
{
public static ExerciseBlueprint CreateExerciseBlueprint(
Func<ExerciseBlueprint, ExerciseBlueprint>? transform = null
)
{
return (transform ?? (e => e)).Invoke(
new ExerciseBlueprint(
Name: "Test Exercise",
Sets: 3,
RepsPerSet: 10,
WeightIncreaseOnSuccess: 2.5m,
RestBetweenSets: Rest.Medium,
SupersetWithNext: false,
Notes: "My exercise notes"
)
);
}
public static ExerciseBlueprint CreateExerciseBlueprint(
Func<ExerciseBlueprint, ExerciseBlueprint>? transform = null
)
{
return (transform ?? (e => e)).Invoke(
new ExerciseBlueprint(
Name: "Test Exercise",
Sets: 3,
RepsPerSet: 10,
WeightIncreaseOnSuccess: 2.5m,
RestBetweenSets: Rest.Medium,
SupersetWithNext: false,
Notes: "My exercise notes"
)
);
}

public static SessionBlueprint CreateSessionBlueprint()
{
return new SessionBlueprint(
Name: "Test Session",
Exercises:
[
CreateExerciseBlueprint(),
CreateExerciseBlueprint(e => e with { Name = "Test Exercise 2", RepsPerSet = 4 }),
CreateExerciseBlueprint(e => e with { Name = "Test Exercise 3", Sets = 4 }),
],
Notes: "My notes"
);
}
public static SessionBlueprint CreateSessionBlueprint()
{
return new SessionBlueprint(
Name: "Test Session",
Exercises:
[
CreateExerciseBlueprint(),
CreateExerciseBlueprint(e => e with { Name = "Test Exercise 2", RepsPerSet = 4 }),
CreateExerciseBlueprint(e => e with { Name = "Test Exercise 3", Sets = 4 }),
],
Notes: "My notes"
);
}
}
8 changes: 4 additions & 4 deletions tests/LiftLog.Tests.App/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace LiftLog.Tests;

public static class Helpers
{
public static ImmutableListValue<T> Repeat<T>(this T item, int times)
{
return Enumerable.Repeat(item, times).ToImmutableList();
}
public static ImmutableListValue<T> Repeat<T>(this T item, int times)
{
return Enumerable.Repeat(item, times).ToImmutableList();
}
}
128 changes: 64 additions & 64 deletions tests/LiftLog.Tests.App/Sessions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,70 @@ namespace LiftLog.Tests;

public static class Sessions
{
public static Session CreateSession(
SessionBlueprint? sessionBlueprint = null,
Func<Session, Session>? transform = null
)
{
sessionBlueprint ??= Blueprints.CreateSessionBlueprint();
return (transform ?? (s => s)).Invoke(
new Session(
Id: Guid.NewGuid(),
Blueprint: sessionBlueprint,
RecordedExercises: sessionBlueprint
.Exercises.Select(x => CreateRecordedExercise(x))
.ToImmutableList(),
Date: DateOnly.Parse("2021-04-05"),
Bodyweight: null
)
);
}
public static Session CreateSession(
SessionBlueprint? sessionBlueprint = null,
Func<Session, Session>? transform = null
)
{
sessionBlueprint ??= Blueprints.CreateSessionBlueprint();
return (transform ?? (s => s)).Invoke(
new Session(
Id: Guid.NewGuid(),
Blueprint: sessionBlueprint,
RecordedExercises: sessionBlueprint
.Exercises.Select(x => CreateRecordedExercise(x))
.ToImmutableList(),
Date: DateOnly.Parse("2021-04-05"),
Bodyweight: null
)
);
}

public static RecordedExercise CreateRecordedExercise(
ExerciseBlueprint? exerciseBlueprint = null,
Func<RecordedExercise, RecordedExercise>? transform = null
)
{
exerciseBlueprint ??= Blueprints.CreateExerciseBlueprint();
return (transform ?? (e => e)).Invoke(
new RecordedExercise(
Blueprint: exerciseBlueprint,
Weight: 0m,
PotentialSets: Enumerable
.Range(0, exerciseBlueprint.Sets)
.Select(
(i) =>
i switch
{
0
=> new PotentialSet(
new(
RepsCompleted: exerciseBlueprint.RepsPerSet,
CompletionTime: TimeOnly.Parse("14:32:00")
),
0
),
_ => new PotentialSet(null, 0)
}
)
.ToImmutableList(),
Notes: null,
PerSetWeight: false
)
);
}
public static RecordedExercise CreateRecordedExercise(
ExerciseBlueprint? exerciseBlueprint = null,
Func<RecordedExercise, RecordedExercise>? transform = null
)
{
exerciseBlueprint ??= Blueprints.CreateExerciseBlueprint();
return (transform ?? (e => e)).Invoke(
new RecordedExercise(
Blueprint: exerciseBlueprint,
Weight: 0m,
PotentialSets: Enumerable
.Range(0, exerciseBlueprint.Sets)
.Select(
(i) =>
i switch
{
0
=> new PotentialSet(
new(
RepsCompleted: exerciseBlueprint.RepsPerSet,
CompletionTime: TimeOnly.Parse("14:32:00")
),
0
),
_ => new PotentialSet(null, 0)
}
)
.ToImmutableList(),
Notes: null,
PerSetWeight: false
)
);
}

public static PotentialSet CreatePotentialSet(
decimal weight,
int repsCompleted = 10,
bool isEmpty = false
)
{
return isEmpty
? new PotentialSet(null, weight)
: new PotentialSet(
new(RepsCompleted: repsCompleted, CompletionTime: TimeOnly.Parse("14:32:00")),
weight
);
}
public static PotentialSet CreatePotentialSet(
decimal weight,
int repsCompleted = 10,
bool isEmpty = false
)
{
return isEmpty
? new PotentialSet(null, weight)
: new PotentialSet(
new(RepsCompleted: repsCompleted, CompletionTime: TimeOnly.Parse("14:32:00")),
weight
);
}
}

0 comments on commit 99eb7ae

Please sign in to comment.