From 953dc06c00f0744e2ccbef9ca5b52cf975b5c0eb Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Fri, 27 Oct 2017 13:03:46 -0500 Subject: [PATCH] wire up init fluent configurations closes #144 --- data/{Language.json => Languages.json} | 2 +- data/{List.json => Lists.json} | 0 src/FilterLists.Data/Entities/BaseEntity.cs | 10 --- src/FilterLists.Data/Entities/FilterList.cs | 54 +-------------- src/FilterLists.Data/Entities/Maintainer.cs | 19 ------ .../BaseEntityConfiguration.cs | 17 ++++- .../FilterListTypeConfiguration.cs | 67 ++++++++++++++++++- .../LanguageTypeConfiguration.cs | 21 ++++++ .../MaintainerTypeConfiguration.cs | 23 ++++++- 9 files changed, 127 insertions(+), 86 deletions(-) rename data/{Language.json => Languages.json} (99%) rename data/{List.json => Lists.json} (100%) diff --git a/data/Language.json b/data/Languages.json similarity index 99% rename from data/Language.json rename to data/Languages.json index 1b6f41631..9454135f7 100644 --- a/data/Language.json +++ b/data/Languages.json @@ -1,5 +1,5 @@ { - "Language": [ + "Languages": [ { "Iso6391": "ab", "Iso6392": "abk", diff --git a/data/List.json b/data/Lists.json similarity index 100% rename from data/List.json rename to data/Lists.json diff --git a/src/FilterLists.Data/Entities/BaseEntity.cs b/src/FilterLists.Data/Entities/BaseEntity.cs index 7f34685bc..1b7f2991e 100644 --- a/src/FilterLists.Data/Entities/BaseEntity.cs +++ b/src/FilterLists.Data/Entities/BaseEntity.cs @@ -1,21 +1,11 @@ using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using Newtonsoft.Json; namespace FilterLists.Data.Entities { public abstract class BaseEntity { - [Key] - [DatabaseGenerated(DatabaseGeneratedOption.Identity)] - [JsonIgnore] public long Id { get; set; } - - [JsonIgnore] public DateTime CreatedDateUtc { get; set; } - - [JsonIgnore] public DateTime? ModifiedDateUtc { get; set; } } } \ No newline at end of file diff --git a/src/FilterLists.Data/Entities/FilterList.cs b/src/FilterLists.Data/Entities/FilterList.cs index e9af96704..1763eba54 100644 --- a/src/FilterLists.Data/Entities/FilterList.cs +++ b/src/FilterLists.Data/Entities/FilterList.cs @@ -1,71 +1,19 @@ using System.Collections.Generic; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using Newtonsoft.Json; namespace FilterLists.Data.Entities { public class FilterList : BaseEntity { public List Languages { get; set; } - - [JsonIgnore] public virtual Maintainer Maintainer { get; set; } - - [Description( - @"A brief description of the list's functionality. Preferably, this is quoted (if non-English, translate to English via translator or Google Translate for consistency) from the list's documentation or composed by a maintainer of the list. If neither are available, a generic description should be composed by the FilterLists contributor.")] - [MaxLength(1022)] public string Description { get; set; } - - [Description(@"The URL to the list's documentation page from which the description was quoted if applicable.")] - [Url] - [MaxLength(2083)] - [MinLength(6)] public string DescriptionSourceUrl { get; set; } - - [Description( - @"The URL to the list's donation page. This could be a custom PayPal or similar link, or a link to a web page discussing various donation options. Pull requests that include changes to this link will undergo further verification to prevent fraud.")] - [Url] - [MaxLength(2083)] - [MinLength(6)] public string DonateUrl { get; set; } - - [Description(@"The email address of the list's maintainer(s) if publicly available.")] - [EmailAddress] - [MaxLength(126)] - [MinLength(7)] - public string Email { get; set; } - - [Description(@"The URL to the list's forum where issues, change requests, etc. are discussed.")] - [Url] - [MaxLength(2083)] - [MinLength(6)] + public string EmailAddress { get; set; } public string ForumUrl { get; set; } - - [Description( - @"The URL to the list's home page. Preferably, this is stated in the header of the list. Alternatively, it could be a custom domain, GitHub page, blog post, forum post, etc. that serves as a primary source of information for the list.")] - [Url] - [MaxLength(2083)] - [MinLength(6)] public string HomeUrl { get; set; } - - [Description(@"The URL to the list's GitHub Issues.")] - [Url] - [MaxLength(2083)] - [MinLength(6)] public string IssuesUrl { get; set; } - - [Description(@"The name of the list as stated by the list maintainer(s) in title case.")] - [Required] - [MaxLength(126)] public string Name { get; set; } - - [Description( - @"The URL to the list in raw text format. zip files and other formats are acceptable if no text format is available.")] - [Required] - [Url] - [MaxLength(2083)] - [MinLength(6)] public string ViewUrl { get; set; } } } \ No newline at end of file diff --git a/src/FilterLists.Data/Entities/Maintainer.cs b/src/FilterLists.Data/Entities/Maintainer.cs index 1f4fbdbee..03c5cac46 100644 --- a/src/FilterLists.Data/Entities/Maintainer.cs +++ b/src/FilterLists.Data/Entities/Maintainer.cs @@ -1,32 +1,13 @@ using System.Collections.Generic; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; namespace FilterLists.Data.Entities { public class Maintainer : BaseEntity { public List FilterLists { get; set; } - - [Description(@"The email address of the list maintainer.")] - [EmailAddress] - [MaxLength(126)] - [MinLength(7)] public string Email { get; set; } - - [Description(@"The URL to the list maintainer's home page.")] - [Url] - [MaxLength(2083)] - [MinLength(6)] public string HomeUrl { get; set; } - - [Description(@"The name of the list maintainer.")] - [Required] - [MaxLength(126)] public string Name { get; set; } - - [Description(@"The Twitter handle of the list maintainer.")] - [MaxLength(126)] public string TwitterHandle { get; set; } } } \ No newline at end of file diff --git a/src/FilterLists.Data/EntityTypeConfigurations/BaseEntityConfiguration.cs b/src/FilterLists.Data/EntityTypeConfigurations/BaseEntityConfiguration.cs index 433f951b1..7a05c717e 100644 --- a/src/FilterLists.Data/EntityTypeConfigurations/BaseEntityConfiguration.cs +++ b/src/FilterLists.Data/EntityTypeConfigurations/BaseEntityConfiguration.cs @@ -1,6 +1,7 @@ using FilterLists.Data.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Newtonsoft.Json; namespace FilterLists.Data.EntityTypeConfigurations { @@ -8,7 +9,21 @@ public class BaseEntityTypeConfiguration : IEntityTypeConfiguration entityTypeBuilder) { - entityTypeBuilder.Property(b => b.CreatedDateUtc).HasDefaultValueSql("CURRENT_TIMESTAMP"); + entityTypeBuilder.HasKey(b => b.Id); + + entityTypeBuilder.Property(b => b.Id) + .HasAnnotation("JsonIgnore", new JsonIgnoreAttribute()) + .ValueGeneratedOnAdd(); + + entityTypeBuilder.Property(b => b.CreatedDateUtc) + .HasAnnotation("JsonIgnore", new JsonIgnoreAttribute()) + .HasColumnType("TIMESTAMP") + .ValueGeneratedOnAdd(); + + entityTypeBuilder.Property(b => b.ModifiedDateUtc) + .HasAnnotation("JsonIgnore", new JsonIgnoreAttribute()) + .HasColumnType("TIMESTAMP") + .ValueGeneratedOnUpdate(); } } } \ No newline at end of file diff --git a/src/FilterLists.Data/EntityTypeConfigurations/FilterListTypeConfiguration.cs b/src/FilterLists.Data/EntityTypeConfigurations/FilterListTypeConfiguration.cs index b3f828d54..3e12c84a7 100644 --- a/src/FilterLists.Data/EntityTypeConfigurations/FilterListTypeConfiguration.cs +++ b/src/FilterLists.Data/EntityTypeConfigurations/FilterListTypeConfiguration.cs @@ -1,5 +1,8 @@ -using FilterLists.Data.Entities; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using FilterLists.Data.Entities; using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Newtonsoft.Json; namespace FilterLists.Data.EntityTypeConfigurations { @@ -7,6 +10,68 @@ public class FilterListTypeConfiguration : BaseEntityTypeConfiguration entityTypeBuilder) { + entityTypeBuilder.Property(b => b.Maintainer) + .HasAnnotation("JsonIgnore", new JsonIgnoreAttribute()); + + entityTypeBuilder.Property(b => b.Description) + .HasAnnotation("Description", + new DescriptionAttribute( + "A brief description of the list's functionality. Preferably, this is quoted (if non-English, translate to English via translator or Google Translate for consistency) from the list's documentation or composed by a maintainer of the list. If neither are available, a generic description should be composed by the FilterLists contributor.")) + .HasMaxLength(1022); + + entityTypeBuilder.Property(b => b.DescriptionSourceUrl) + .HasAnnotation("Description", + new DescriptionAttribute( + "The URL to the list's documentation page from which the description was quoted if applicable.")) + .HasAnnotation("Url", new UrlAttribute()) + .HasMaxLength(2083); + + entityTypeBuilder.Property(b => b.DonateUrl) + .HasAnnotation("Description", + new DescriptionAttribute( + "The URL to the list's donation page. This could be a custom PayPal or similar link, or a link to a web page discussing various donation options. Pull requests that include changes to this link will undergo further verification to prevent fraud.")) + .HasAnnotation("Url", new UrlAttribute()) + .HasMaxLength(2083); + + entityTypeBuilder.Property(b => b.EmailAddress) + .HasAnnotation("Description", + new DescriptionAttribute("The email address for communicating issues or comments about the list.")) + .HasAnnotation("EmailAddress", new EmailAddressAttribute()) + .HasMaxLength(126); + + entityTypeBuilder.Property(b => b.ForumUrl) + .HasAnnotation("Description", + new DescriptionAttribute( + "The URL to the list's forum where issues, change requests, etc. are discussed.")) + .HasAnnotation("Url", new UrlAttribute()) + .HasMaxLength(2083); + + entityTypeBuilder.Property(b => b.HomeUrl) + .HasAnnotation("Description", + new DescriptionAttribute( + "The URL to the list's home page. Preferably, this is stated in the header of the list. Alternatively, it could be a custom domain, GitHub page, blog post, forum post, etc. that serves as a primary source of information for the list.")) + .HasAnnotation("Url", new UrlAttribute()) + .HasMaxLength(2083); + + entityTypeBuilder.Property(b => b.IssuesUrl) + .HasAnnotation("Description", new DescriptionAttribute("The URL to the list's GitHub Issues.")) + .HasAnnotation("Url", new UrlAttribute()) + .HasMaxLength(2083); + + entityTypeBuilder.Property(b => b.Name) + .HasAnnotation("Description", + new DescriptionAttribute("The name of the list as stated by the list maintainer(s) in title case.")) + .IsRequired() + .HasMaxLength(126); + + entityTypeBuilder.Property(b => b.IssuesUrl) + .HasAnnotation("Description", + new DescriptionAttribute( + "The URL to the list in raw text format. zip files and other formats are acceptable if no text format is available.")) + .IsRequired() + .HasAnnotation("Url", new UrlAttribute()) + .HasMaxLength(2083); + base.Configure(entityTypeBuilder); } } diff --git a/src/FilterLists.Data/EntityTypeConfigurations/LanguageTypeConfiguration.cs b/src/FilterLists.Data/EntityTypeConfigurations/LanguageTypeConfiguration.cs index 936f5ca5c..a67be5b78 100644 --- a/src/FilterLists.Data/EntityTypeConfigurations/LanguageTypeConfiguration.cs +++ b/src/FilterLists.Data/EntityTypeConfigurations/LanguageTypeConfiguration.cs @@ -7,6 +7,27 @@ public class LanguageTypeConfiguration : BaseEntityTypeConfiguration { public override void Configure(EntityTypeBuilder entityTypeBuilder) { + entityTypeBuilder.Property(b => b.Iso6391) + .HasMaxLength(2); + + entityTypeBuilder.Property(b => b.Iso6392) + .HasMaxLength(3); + + entityTypeBuilder.Property(b => b.Iso6392B) + .HasMaxLength(3); + + entityTypeBuilder.Property(b => b.Iso6392T) + .HasMaxLength(3); + + entityTypeBuilder.Property(b => b.Iso6393) + .HasMaxLength(3); + + entityTypeBuilder.Property(b => b.LocalName) + .HasMaxLength(126); + + entityTypeBuilder.Property(b => b.Name) + .HasMaxLength(126); + base.Configure(entityTypeBuilder); } } diff --git a/src/FilterLists.Data/EntityTypeConfigurations/MaintainerTypeConfiguration.cs b/src/FilterLists.Data/EntityTypeConfigurations/MaintainerTypeConfiguration.cs index f4e8184b0..d7d531f5f 100644 --- a/src/FilterLists.Data/EntityTypeConfigurations/MaintainerTypeConfiguration.cs +++ b/src/FilterLists.Data/EntityTypeConfigurations/MaintainerTypeConfiguration.cs @@ -1,4 +1,6 @@ -using FilterLists.Data.Entities; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using FilterLists.Data.Entities; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace FilterLists.Data.EntityTypeConfigurations @@ -7,6 +9,25 @@ public class MaintainerTypeConfiguration : BaseEntityTypeConfiguration entityTypeBuilder) { + entityTypeBuilder.Property(b => b.Email) + .HasAnnotation("Description", new DescriptionAttribute("The email address of the list maintainer.")) + .HasAnnotation("EmailAddress", new EmailAddressAttribute()) + .HasMaxLength(126); + + entityTypeBuilder.Property(b => b.HomeUrl) + .HasAnnotation("Description", new DescriptionAttribute("The URL to the list maintainer's home page.")) + .HasAnnotation("Url", new UrlAttribute()) + .HasMaxLength(2083); + + entityTypeBuilder.Property(b => b.Name) + .HasAnnotation("Description", new DescriptionAttribute("The name of the list maintainer.")) + .IsRequired() + .HasMaxLength(126); + + entityTypeBuilder.Property(b => b.TwitterHandle) + .HasAnnotation("Description", new DescriptionAttribute("The Twitter handle of the list maintainer.")) + .HasMaxLength(126); + base.Configure(entityTypeBuilder); } }