Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EES-5740 Backend work for filter hierarchies #5479

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore.Migrations;

namespace GovUk.Education.ExploreEducationStatistics.Admin.Migrations.ContentMigrations
{
/// <inheritdoc />
public partial class EES5740_AddFilterHierarchiesColumnToFilesTable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "FilterHierarchies",
table: "Files",
type: "nvarchar(max)",
nullable: true,
defaultValue: null);

migrationBuilder.Sql("""
UPDATE [dbo].[Files]
SET FilterHierarchies = '[]'
WHERE Type = 'Data';
""");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "FilterHierarchies",
table: "Files");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.IsRequired()
.HasColumnType("nvarchar(max)");

b.Property<string>("FilterHierarchies")
.HasColumnType("nvarchar(max)");

b.Property<Guid?>("ReplacedById")
.HasColumnType("uniqueidentifier");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;

namespace GovUk.Education.ExploreEducationStatistics.Common.ViewModels;

public record DataSetFileFilterHierarchyViewModel(
Guid RootFilterId,
List<Guid> ChildFilterIds,
List<Guid> RootOptionIds,
List<DataSetFileFilterHierarchyTierViewModel> Tiers
);

public record DataSetFileFilterHierarchyTierViewModel(
int Level,
Dictionary<Guid, List<Guid>> Hierarchy
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#nullable enable
using System;
using System.Collections.Generic;

namespace GovUk.Education.ExploreEducationStatistics.Content.Model;

public record DataSetFileFilterHierarchy(
Guid RootFilterId,
List<Guid> ChildFilterIds, // in order of the tiers
List<Guid> RootOptionIds,
List<Dictionary<Guid, List<Guid>>> Tiers // also in order i.e. Tier[0] is root -> childFilterIds[0], Tier[1] is childFilterIds[0] -> childFilterIds[1], etc.
);
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class FilterMeta
public string? Hint { get; set; }

public required string ColumnName { get; set; }

[JsonIgnore]
public string? GroupCsvColumn { get; set; }
}

public class IndicatorMeta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,13 @@ private static void ConfigureFile(ModelBuilder modelBuilder)
? DateTime.SpecifyKind(v.Value, DateTimeKind.Utc)
: null);
entity.Property(p => p.DataSetFileMeta)
.HasConversion( // You might want to use EF8 JSON support instead of this
.HasConversion(
v => JsonConvert.SerializeObject(v),
v => JsonConvert.DeserializeObject<DataSetFileMeta>(v));
entity.Property(p => p.FilterHierarchies)
.HasConversion(
v => JsonConvert.SerializeObject(v),
v => JsonConvert.DeserializeObject<List<DataSetFileFilterHierarchy>>(v));
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
using System;
using System.Collections.Generic;
using GovUk.Education.ExploreEducationStatistics.Common.Model;

namespace GovUk.Education.ExploreEducationStatistics.Content.Model
Expand All @@ -24,6 +25,8 @@ public class File : ICreatedTimestamp<DateTime?>

public DataSetFileMeta? DataSetFileMeta { get; set; }

public List<DataSetFileFilterHierarchy>? FilterHierarchies { get; set; }

public Guid? ReplacedById { get; set; }

public File? ReplacedBy { get; set; }
Expand Down
Loading
Loading