Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #82 from kysect/refactor/table-layout-storage
Browse files Browse the repository at this point in the history
Refactor/table layout storage
  • Loading branch information
ronimizy authored Feb 7, 2022
2 parents 16f8a97 + 2a9b0e4 commit e07b07f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using SeaInk.Core.Entities;
using SeaInk.Core.TableLayout;
using SeaInk.Core.TableLayout.Components;
using SeaInk.Core.TableLayout.ComponentsBase;
using SeaInk.Infrastructure.DataAccess.Exceptions;
using SeaInk.Infrastructure.DataAccess.Models;
using SeaInk.Utility.Extensions;

namespace SeaInk.Infrastructure.DataAccess.Database
{
Expand Down Expand Up @@ -36,7 +37,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
ConfigureMentor(modelBuilder);
ConfigureStudent(modelBuilder);

// ConfigureTableComponents(modelBuilder);
modelBuilder.Entity<StudyGroupSubjectLayout>()
.Property(ssg => ssg.Layout)
.HasConversion(
component => JsonConvert.SerializeObject(component),
s => JsonConvert.DeserializeObject<TableLayoutComponent>(s)
.ThrowIfNull(new FailedTableLayoutComponentDeserializationException(s)));
}

private static void ConfigureAssignment(ModelBuilder modelBuilder)
Expand Down Expand Up @@ -91,16 +97,5 @@ private static void ConfigureStudyGroupSubject(ModelBuilder modelBuilder)
.Navigation(ssg => ssg.Mentors)
.HasField("_mentors");
}

private static void ConfigureTableComponents(ModelBuilder modelBuilder)
{
modelBuilder.Entity<LabelComponent>().Property(x => x.Id).ValueGeneratedNever();
modelBuilder.Entity(typeof(CompositeLayoutComponent<>)).HasMany("_components");
modelBuilder.Entity<LabelComponent>().Property("_value");

modelBuilder.Entity<TableLayoutComponent>().HasOne<HeaderLayoutComponent>("_header");
modelBuilder.Entity<HeaderLayoutComponent>().HasOne<HorizontalStackLayoutComponent<LayoutComponent>>("_stack");
modelBuilder.Entity<AssignmentsComponent>().HasOne<HorizontalStackLayoutComponent<AssignmentColumnComponent>>("_stack");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using SeaInk.Core.TableLayout;
using SeaInk.Core.Tools;

namespace SeaInk.Infrastructure.DataAccess.Exceptions;

public class FailedTableLayoutComponentDeserializationException : SeaInkException
{
public FailedTableLayoutComponentDeserializationException(string serialized)
: base($"{nameof(TableLayoutComponent)} deserialization failed. Value:\n{serialized}") { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit e07b07f

Please sign in to comment.