Refactor components to enhance code clarity and maintainability by updating prop types to use Readonly for better immutability. Adjust Result class methods for consistency, and streamline query functions in ChannelDetail and other components to improve performance and readability.
This commit is contained in:
@@ -18,10 +18,10 @@ public class Result
|
||||
|
||||
public static Result Success() => new(true, Error.None);
|
||||
|
||||
public static Result Failure(Error error) => new(false, error);
|
||||
|
||||
public static Result<T> Success<T>(T value) => new(value, true, Error.None);
|
||||
|
||||
public static Result Failure(Error error) => new(false, error);
|
||||
|
||||
public static Result<T> Failure<T>(Error error) => new(default, false, error);
|
||||
}
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ public sealed class GroupExpander(IAppDbContext dbContext)
|
||||
e.ChannelId == channelId
|
||||
&& e.Kind == ScheduleEntryKind.Program
|
||||
&& e.ShowId != null
|
||||
&& showIds.Contains(e.ShowId!.Value)
|
||||
&& showIds.Contains(e.ShowId.Value)
|
||||
)
|
||||
.GroupBy(e => e.ShowId!.Value)
|
||||
.Select(g => new { ShowId = g.Key, LastPlayed = g.Max(e => e.StartsAtUtc) })
|
||||
@@ -221,7 +221,7 @@ public sealed class GroupExpander(IAppDbContext dbContext)
|
||||
e.ChannelId == channelId
|
||||
&& e.Kind == ScheduleEntryKind.Program
|
||||
&& e.ShowId != null
|
||||
&& showIds.Contains(e.ShowId!.Value)
|
||||
&& showIds.Contains(e.ShowId.Value)
|
||||
&& e.StartsAtUtc >= since
|
||||
)
|
||||
.Select(e => new { ShowId = e.ShowId!.Value, e.StartsAtUtc })
|
||||
|
||||
@@ -50,12 +50,8 @@ public sealed record PlanningRules(
|
||||
|
||||
// Пересекающиеся окна разрешаются в пользу строгого: детское время не должно
|
||||
// отменяться более широким окном, случайно наложенным сверху.
|
||||
ShowAudience? strictest = null;
|
||||
foreach (var window in windows.Where(w => w.Contains(moment)))
|
||||
strictest = strictest is { } current && current <= window.MaxAudience
|
||||
? current
|
||||
: window.MaxAudience;
|
||||
return strictest;
|
||||
var applicable = windows.Where(w => w.Contains(moment)).Select(w => w.MaxAudience).ToList();
|
||||
return applicable.Count > 0 ? applicable.Min() : null;
|
||||
}
|
||||
|
||||
public string ToJson() => JsonSerializer.Serialize(this, Options);
|
||||
|
||||
@@ -110,7 +110,7 @@ internal sealed class RoleService(
|
||||
if (currentRoles.Count > 0)
|
||||
await userManager.RemoveFromRolesAsync(user, currentRoles);
|
||||
|
||||
await userManager.AddToRoleAsync(user, role.Name!);
|
||||
await userManager.AddToRoleAsync(user, role.Name);
|
||||
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user