-
-
Notifications
You must be signed in to change notification settings - Fork 87
feat: Added templates for blog post editor #481
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| using System; | ||
|
|
||
| namespace LinkDotNet.Blog.Domain; | ||
|
|
||
| public sealed class BlogPostTemplate : Entity | ||
| { | ||
| public string Name { get; private set; } = default!; | ||
|
|
||
| public string Title { get; private set; } = default!; | ||
|
|
||
| public string ShortDescription { get; private set; } = default!; | ||
|
|
||
| public string Content { get; private set; } = default!; | ||
|
|
||
| public static BlogPostTemplate Create(string name, string title, string shortDescription, string content) | ||
| { | ||
| return new BlogPostTemplate | ||
| { | ||
| Name = name, | ||
| Title = title, | ||
| ShortDescription = shortDescription, | ||
| Content = content | ||
| }; | ||
| } | ||
|
|
||
| public void Update(string name, string title, string shortDescription, string content) | ||
| { | ||
| Name = name; | ||
| Title = title; | ||
| ShortDescription = shortDescription; | ||
| Content = content; | ||
| } | ||
|
Comment on lines
+26
to
+32
|
||
| } | ||
|
Comment on lines
+1
to
+33
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | ||||||
| using System; | ||||||
| using Microsoft.EntityFrameworkCore.Migrations; | ||||||
|
|
||||||
| #nullable disable | ||||||
|
|
||||||
| namespace LinkDotNet.Blog.Web.Migrations; | ||||||
|
|
||||||
| /// <inheritdoc /> | ||||||
| public partial class AddBlogPostTemplate : Migration | ||||||
| { | ||||||
| /// <inheritdoc /> | ||||||
| protected override void Up(MigrationBuilder migrationBuilder) | ||||||
| { | ||||||
| ArgumentNullException.ThrowIfNull(migrationBuilder); | ||||||
|
|
||||||
| migrationBuilder.AlterColumn<string>( | ||||||
| name: "AuthorName", | ||||||
| table: "BlogPosts", | ||||||
| type: "TEXT", | ||||||
| maxLength: 256, | ||||||
| nullable: true, | ||||||
| oldClrType: typeof(string), | ||||||
| oldType: "nvarchar(256)", | ||||||
| oldMaxLength: 256, | ||||||
| oldNullable: true); | ||||||
|
|
||||||
| migrationBuilder.CreateTable( | ||||||
| name: "BlogPostTemplates", | ||||||
| columns: table => new | ||||||
| { | ||||||
| Id = table.Column<string>(type: "TEXT", unicode: false, nullable: false), | ||||||
| Name = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false), | ||||||
| Title = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false), | ||||||
| ShortDescription = table.Column<string>(type: "TEXT", nullable: false), | ||||||
| Content = table.Column<string>(type: "TEXT", nullable: false) | ||||||
| }, | ||||||
| constraints: table => | ||||||
| { | ||||||
| table.PrimaryKey("PK_BlogPostTemplates", x => x.Id); | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| /// <inheritdoc /> | ||||||
| protected override void Down(MigrationBuilder migrationBuilder) | ||||||
| { | ||||||
| ArgumentNullException.ThrowIfNull(migrationBuilder); | ||||||
|
|
||||||
| migrationBuilder.DropTable( | ||||||
| name: "BlogPostTemplates"); | ||||||
|
|
||||||
| migrationBuilder.AlterColumn<string>( | ||||||
| name: "AuthorName", | ||||||
| table: "BlogPosts", | ||||||
| type: "TEXT", | ||||||
| maxLength: 256, | ||||||
| nullable: true, | ||||||
| oldClrType: typeof(string), | ||||||
| oldType: "nvarchar(256)", | ||||||
|
||||||
| oldType: "nvarchar(256)", | |
| oldType: "TEXT", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Create method lacks input validation. Based on the ShortCode entity pattern in this codebase (which includes ArgumentException.ThrowIfNullOrWhiteSpace for name validation), this method should validate that the name parameter is not null or whitespace before creating the entity. Without validation, invalid entities can be created and persisted to the database.