2023-08-11 14:51:20 +00:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-08-06 14:57:23 +00:00
|
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
2023-08-12 19:13:47 +00:00
|
|
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
2023-08-06 14:57:23 +00:00
|
|
|
|
2023-08-13 16:33:54 +00:00
|
|
|
namespace OliverBooth.Data.Blog.Configuration;
|
2023-08-06 14:57:23 +00:00
|
|
|
|
|
|
|
internal sealed class BlogPostConfiguration : IEntityTypeConfiguration<BlogPost>
|
|
|
|
{
|
|
|
|
/// <inheritdoc />
|
|
|
|
public void Configure(EntityTypeBuilder<BlogPost> builder)
|
|
|
|
{
|
|
|
|
builder.ToTable("BlogPost");
|
|
|
|
builder.HasKey(e => e.Id);
|
|
|
|
|
2023-08-11 13:09:13 +00:00
|
|
|
builder.Property(e => e.Id);
|
2023-08-06 14:57:23 +00:00
|
|
|
builder.Property(e => e.WordPressId).IsRequired(false);
|
|
|
|
builder.Property(e => e.Slug).HasMaxLength(100).IsRequired();
|
|
|
|
builder.Property(e => e.AuthorId).IsRequired();
|
|
|
|
builder.Property(e => e.Published).IsRequired();
|
2023-08-07 22:42:59 +00:00
|
|
|
builder.Property(e => e.Updated).IsRequired(false);
|
2023-08-06 14:57:23 +00:00
|
|
|
builder.Property(e => e.Title).HasMaxLength(255).IsRequired();
|
|
|
|
builder.Property(e => e.Body).IsRequired();
|
2024-04-27 14:41:19 +00:00
|
|
|
builder.Property(e => e.Excerpt).HasMaxLength(512).IsRequired(false);
|
2023-08-07 23:20:21 +00:00
|
|
|
builder.Property(e => e.IsRedirect).IsRequired();
|
2023-08-12 19:13:47 +00:00
|
|
|
builder.Property(e => e.RedirectUrl).HasConversion<UriToStringConverter>().HasMaxLength(255).IsRequired(false);
|
2023-08-07 23:20:38 +00:00
|
|
|
builder.Property(e => e.EnableComments).IsRequired();
|
2023-08-08 11:39:49 +00:00
|
|
|
builder.Property(e => e.DisqusDomain).IsRequired(false);
|
|
|
|
builder.Property(e => e.DisqusIdentifier).IsRequired(false);
|
|
|
|
builder.Property(e => e.DisqusPath).IsRequired(false);
|
2024-02-23 16:50:43 +00:00
|
|
|
builder.Property(e => e.Visibility).HasConversion(new EnumToStringConverter<Visibility>()).IsRequired();
|
2023-08-20 13:22:52 +00:00
|
|
|
builder.Property(e => e.Password).HasMaxLength(255).IsRequired(false);
|
2023-09-23 21:08:25 +00:00
|
|
|
builder.Property(e => e.Tags).IsRequired()
|
|
|
|
.HasConversion(
|
|
|
|
tags => string.Join(' ', tags.Select(t => t.Replace(' ', '-'))),
|
|
|
|
tags => tags.Split(' ', StringSplitOptions.RemoveEmptyEntries)
|
|
|
|
.Select(t => t.Replace('-', ' ')).ToArray());
|
2023-08-06 14:57:23 +00:00
|
|
|
}
|
|
|
|
}
|