Skip to content

Commit c5cbc5d

Browse files
committed
Enable the possibility to only create draft
1 parent 316897c commit c5cbc5d

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

LinkDotNet.Blog.UnitTests/Web/Shared/Admin/CreateNewBlogPostTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public void ShouldCreateNewBlogPostWhenValidDataGiven()
2222
cut.Find("#short").Change("My short Description");
2323
cut.Find("#content").Change("My content");
2424
cut.Find("#preview").Change("My preview url");
25+
cut.Find("#published").Change(false);
2526
cut.Find("#tags").Change("Tag1,Tag2,Tag3");
2627

2728
cut.Find("form").Submit();
@@ -32,6 +33,7 @@ public void ShouldCreateNewBlogPostWhenValidDataGiven()
3233
blogPost.ShortDescription.Should().Be("My short Description");
3334
blogPost.Content.Should().Be("My content");
3435
blogPost.PreviewImageUrl.Should().Be("My preview url");
36+
blogPost.IsPublished.Should().BeFalse();
3537
blogPost.Tags.Should().HaveCount(3);
3638
blogPost.Tags.Select(t => t.Content).Should().Contain(new[] { "Tag1", "Tag2", "Tag3" });
3739
}

LinkDotNet.Blog.Web/Pages/Admin/CreateNewBlogPostPage.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@inject IRepository _repository
88
@inject IToastService _toastService
99

10-
<CreateNewBlogPost Title="Create new BlogPost" OnBlogPostCreated="@(blogPost => StoreBlogPostAsync(blogPost))" ></CreateNewBlogPost>
10+
<CreateNewBlogPost Title="Create new BlogPost" OnBlogPostCreated="@(StoreBlogPostAsync)" ></CreateNewBlogPost>
1111

1212
@code {
1313
private async Task StoreBlogPostAsync(BlogPost blogPost)

LinkDotNet.Blog.Web/Shared/Admin/CreateNewBlogPost.razor

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
<label for="preview">Preview-Url</label>
2626
<InputText class="form-control" id="preview" @bind-Value="_model.PreviewImageUrl"/>
2727
</div>
28+
<div class="form-check">
29+
<InputCheckbox class="form-check-input" id="published" @bind-Value="_model.IsPublished" />
30+
<label class="form-check-label" for="published">Publish</label><br/>
31+
<small id="published" class="form-text text-muted">If this blog post is only draft uncheck the box</small>
32+
</div>
2833
<div class="form-group">
2934
<label for="tags">Tags</label>
3035
<InputText class="form-control" id="tags" @bind-Value="_model.Tags"/>

LinkDotNet.Blog.Web/Shared/Admin/CreateNewModel.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class CreateNewModel
2121
[Required]
2222
public string PreviewImageUrl { get; set; }
2323

24+
[Required]
25+
public bool IsPublished { get; set; } = true;
26+
2427
public string Tags { get; set; }
2528

2629
public static CreateNewModel FromBlogPost(BlogPost blogPost)
@@ -32,6 +35,7 @@ public static CreateNewModel FromBlogPost(BlogPost blogPost)
3235
Tags = blogPost.Tags != null ? string.Join(",", blogPost.Tags.Select(t => t.Content)) : null,
3336
Title = blogPost.Title,
3437
ShortDescription = blogPost.ShortDescription,
38+
IsPublished = blogPost.IsPublished,
3539
PreviewImageUrl = blogPost.PreviewImageUrl,
3640
};
3741
}
@@ -40,7 +44,7 @@ public BlogPost ToBlogPost()
4044
{
4145
var tags = string.IsNullOrWhiteSpace(Tags) ? ArraySegment<string>.Empty : Tags.Split(",");
4246

43-
var blogPost = BlogPost.Create(Title, ShortDescription, Content, PreviewImageUrl, true, tags);
47+
var blogPost = BlogPost.Create(Title, ShortDescription, Content, PreviewImageUrl, IsPublished, tags);
4448
blogPost.Id = Id;
4549
return blogPost;
4650
}

0 commit comments

Comments
 (0)