Skip to content

Commit

Permalink
used ToJson() for YoutubeData
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Holub committed Nov 27, 2023
1 parent 8a00959 commit 55736e9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
7 changes: 4 additions & 3 deletions server/src/ShareLink.Dal/Configurations/LinkConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public void Configure(EntityTypeBuilder<Link> builder)
v => v.ToString(),
v => (LinkType)Enum.Parse(typeof(LinkType), v));

builder.Property(x => x.Youtube)
.HasColumnType("jsonb")
.IsRequired(false);
builder.OwnsOne<YoutubeData>(x => x.Youtube, d =>
{
d.ToJson();
});

builder.HasMany(x => x.Tags)
.WithMany(x => x.Links);
Expand Down
5 changes: 2 additions & 3 deletions server/src/ShareLink.Dal/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ShareLink.Application.Common.Abstraction;
Expand All @@ -21,4 +20,4 @@ public static IServiceCollection AddDalServices(

return services;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using ShareLink.Dal;
using ShareLink.Domain.Models;

#nullable disable

Expand All @@ -18,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.13")
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
Expand Down Expand Up @@ -93,9 +92,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.IsRequired()
.HasColumnType("text");

b.Property<YoutubeData>("Youtube")
.HasColumnType("jsonb");

b.HasKey("Id");

b.HasIndex("CreatedAt");
Expand Down Expand Up @@ -173,6 +169,30 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});

modelBuilder.Entity("ShareLink.Domain.Models.Link", b =>
{
b.OwnsOne("ShareLink.Domain.Models.YoutubeData", "Youtube", b1 =>
{
b1.Property<string>("LinkId")
.HasColumnType("text");

b1.Property<string>("VideoId")
.IsRequired()
.HasColumnType("text");

b1.HasKey("LinkId");

b1.ToTable("Links");

b1.ToJson("Youtube");

b1.WithOwner()
.HasForeignKey("LinkId");
});

b.Navigation("Youtube");
});
#pragma warning restore 612, 618
}
}
Expand Down

0 comments on commit 55736e9

Please sign in to comment.