Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions PhantomDave.BankTracking.Api/Types/Mutations/DashboardMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ namespace PhantomDave.BankTracking.Api.Types.Mutations;
[ExtendObjectType(OperationTypeNames.Mutation)]
public class DashboardMutations
{
private const int MaxDashboardNameLength = 100;

private static string TruncateName(string? name)
{
var trimmed = name?.Trim() ?? string.Empty;
return trimmed.Length > MaxDashboardNameLength ? trimmed[..MaxDashboardNameLength] : trimmed;
}
Comment on lines +15 to +19
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TruncateName method duplicates the exact logic already present in DashboardService.NormalizeName (lines 206-215 in DashboardService.cs), violating the DRY principle. Additionally, this creates an architectural inconsistency: FinanceRecordMutations delegates to FinanceRecordService for all operations, while DashboardMutations bypasses DashboardService entirely.

Consider refactoring these mutations to inject and use DashboardService instead of IUnitOfWork, similar to how FinanceRecordMutations uses FinanceRecordService. This would:

  • Eliminate code duplication
  • Maintain consistency with the established pattern
  • Keep all dashboard business logic centralized in the service layer

Copilot uses AI. Check for mistakes.

public async Task<DashboardType> CreateDashboard(
[Service] IUnitOfWork unitOfWork,
[Service] IHttpContextAccessor httpContextAccessor,
Expand All @@ -20,7 +28,7 @@ public async Task<DashboardType> CreateDashboard(
var dashboard = new Dashboard
{
AccountId = accountId,
Name = input.Name?.Trim() ?? string.Empty
Name = TruncateName(input.Name)
};

await unitOfWork.Dashboards.AddAsync(dashboard);
Expand Down Expand Up @@ -48,7 +56,7 @@ public async Task<DashboardType> UpdateDashboard(

if (input.Name != null)
{
dashboard.Name = input.Name.Trim();
dashboard.Name = TruncateName(input.Name);
}

await unitOfWork.SaveChangesAsync();
Expand Down
Loading