Skip to content
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

CMS Kit - Pages Refactorings #7860

Merged
merged 4 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore.Migrations;

namespace Volo.CmsKit.Migrations
{
public partial class Page_Remove_Description : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Description",
table: "CmsPages");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Description",
table: "CmsPages",
type: "nvarchar(512)",
maxLength: 512,
nullable: true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1545,10 +1545,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("datetime2")
.HasColumnName("DeletionTime");

b.Property<string>("Description")
.HasMaxLength(512)
.HasColumnType("nvarchar(512)");

b.Property<string>("ExtraProperties")
.HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ public class CreatePageInputDto
[Required]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Slug { get; set; }

[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxDescriptionLength))]
public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ public class PageDto : AuditedEntityDto<Guid>
public string Title { get; set; }

public string Slug { get; set; }

public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ public class UpdatePageInputDto
[Required]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Slug { get; set; }

[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxDescriptionLength))]
public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public virtual async Task<PageDto> CreateAsync(CreatePageInputDto input)
{
await CheckPageSlugAsync(input.Slug);

var page = new Page(GuidGenerator.Create(), input.Title, input.Slug, input.Description, CurrentTenant?.Id);
var page = new Page(GuidGenerator.Create(), input.Title, input.Slug, CurrentTenant?.Id);
enisn marked this conversation as resolved.
Show resolved Hide resolved
enisn marked this conversation as resolved.
Show resolved Hide resolved

await PageRepository.InsertAsync(page);

Expand All @@ -69,7 +69,6 @@ public virtual async Task<PageDto> UpdateAsync(Guid id, UpdatePageInputDto input

page.SetTitle(input.Title);
page.SetSlug(input.Slug);
page.Description = input.Description;

await PageRepository.UpdateAsync(page);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@ public class PageConsts
public static int MaxTitleLength { get; set; } = 256;

public static int MaxSlugLength { get; set; } = 256;

public static int MaxDescriptionLength { get; set; } = 512;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ public class Page : FullAuditedAggregateRoot<Guid>, IMultiTenant

[NotNull] public virtual string Slug { get; protected set; }

[CanBeNull] public virtual string Description { get; set; }

protected Page()
{
}

public Page(Guid id, [NotNull] string title, [NotNull] string slug, [CanBeNull] string description = null,
Guid? tenantId = null) : base(id)
public Page(Guid id, [NotNull] string title, [NotNull] string slug, [CanBeNull]Guid? tenantId = null) : base(id)
{
Title = Check.NotNullOrEmpty(title, nameof(title), PageConsts.MaxTitleLength);
Slug = Check.NotNullOrEmpty(slug, nameof(slug), PageConsts.MaxSlugLength);
Description = Check.Length(description, nameof(description), PageConsts.MaxDescriptionLength);

TenantId = tenantId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ public static class CmsKitDbContextModelCreatingExtensions

b.Property(x => x.Title).IsRequired().HasMaxLength(PageConsts.MaxTitleLength);
b.Property(x => x.Slug).IsRequired().HasMaxLength(PageConsts.MaxSlugLength);
b.Property(x => x.Description).HasMaxLength(PageConsts.MaxDescriptionLength);

b.HasIndex(x => new { x.TenantId, Url = x.Slug });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ public PagePublicAppService(IPageRepository pageRepository)

public virtual async Task<PageDto> FindBySlugAsync(string slug)
{
PageDto pageDto = null;
var page = await PageRepository.FindBySlugAsync(slug);

if (page !=null)
if (page == null)
{
pageDto = ObjectMapper.Map<Page, PageDto>(page);
return null;
}
return pageDto;

return ObjectMapper.Map<Page, PageDto>(page);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task ShouldGetAsync()
{
var page = await _pageAdminAppService.GetAsync(_data.Page_1_Id);

page.Description.ShouldBe(_data.Page_1_Description);
page.Title.ShouldBe(_data.Page_1_Title);
}

[Fact]
Expand Down Expand Up @@ -94,7 +94,6 @@ public async Task ShouldUpdatePageAsync()
var dto = new UpdatePageInputDto
{
Title = _data.Page_1_Title + "++",
Description = "new description",
Slug = _data.Page_1_Slug+ "test"
};

Expand All @@ -107,9 +106,6 @@ public async Task ShouldUpdatePageAsync()

updatedPage.Slug.ShouldNotBe(_data.Page_1_Slug);
updatedPage.Slug.ShouldBe(dto.Slug);

updatedPage.Description.ShouldNotBe(_data.Page_1_Description);
updatedPage.Description.ShouldBe(dto.Description);
}

[Fact]
Expand All @@ -118,7 +114,6 @@ public async Task ShouldNotUpdateWithExistUrlAsync()
var dto = new UpdatePageInputDto
{
Title = _data.Page_1_Title + "++",
Description = "new description",
Slug = _data.Page_2_Slug
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ private async Task SeedTagsAsync()

private async Task SeedPagesAsync()
{
var page1 = new Page(_cmsKitTestData.Page_1_Id, _cmsKitTestData.Page_1_Title, _cmsKitTestData.Page_1_Slug, _cmsKitTestData.Page_1_Description);
var page1 = new Page(_cmsKitTestData.Page_1_Id, _cmsKitTestData.Page_1_Title, _cmsKitTestData.Page_1_Slug);
var page1Content = new Content(_guidGenerator.Create(), nameof(Page), page1.Id.ToString(), _cmsKitTestData.Page_1_Content);

await _pageRepository.InsertAsync(page1);
await _contentRepository.InsertAsync(page1Content);

var page2 = new Page(_cmsKitTestData.Page_2_Id, _cmsKitTestData.Page_2_Title, _cmsKitTestData.Page_2_Slug, _cmsKitTestData.Page_2_Description);
var page2 = new Page(_cmsKitTestData.Page_2_Id, _cmsKitTestData.Page_2_Title, _cmsKitTestData.Page_2_Slug);
var page2Content = new Content(_guidGenerator.Create(), nameof(Page), page2.Id.ToString(), _cmsKitTestData.Page_2_Content);

await _pageRepository.InsertAsync(page2);
Expand Down
4 changes: 0 additions & 4 deletions modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public class CmsKitTestData : ISingletonDependency

public string Page_1_Slug { get; } = "imagine-dragons-believer-lyrics";

public string Page_1_Description { get; } = "You can get the lyrics of the music.";

public Guid Page_1_Id { get; } = Guid.NewGuid();

public string Page_1_Content => Content_1;
Expand All @@ -57,8 +55,6 @@ public class CmsKitTestData : ISingletonDependency

public string Page_2_Slug { get; } = "imagine-dragons-believer-lyrics-2";

public string Page_2_Description { get; } = "You can get the lyrics of the music.";

public Guid Page_2_Id { get; } = Guid.NewGuid();

public string Page_2_Content => Content_2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task ShouldGetByUrlAsync()
var page = await _pageRepository.GetBySlugAsync(_cmsKitTestData.Page_1_Slug);

page.ShouldNotBeNull();
page.Description.ShouldBe(_cmsKitTestData.Page_1_Description);
page.Title.ShouldBe(_cmsKitTestData.Page_1_Title);
}

[Fact]
Expand All @@ -65,7 +65,7 @@ public async Task ShouldFindByUrlAsync()
var page = await _pageRepository.FindBySlugAsync(_cmsKitTestData.Page_1_Slug);

page.ShouldNotBeNull();
page.Description.ShouldBe(_cmsKitTestData.Page_1_Description);
page.Title.ShouldBe(_cmsKitTestData.Page_1_Title);
}

[Fact]
Expand Down