Skip to content

Commit

Permalink
CmsKit - Rafactoring - Change naming UrlSlug to Slug
Browse files Browse the repository at this point in the history
  • Loading branch information
enisn committed Feb 9, 2021
1 parent fca418f commit f277764
Show file tree
Hide file tree
Showing 38 changed files with 186 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BlogDto : EntityDto<Guid>
public string Name { get; set; }

[Required]
[DynamicMaxLength(typeof(BlogConsts), nameof(BlogConsts.MaxUrlSlugLength))]
public string UrlSlug { get; set; }
[DynamicMaxLength(typeof(BlogConsts), nameof(BlogConsts.MaxSlugLength))]
public string Slug { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class BlogPostDto : EntityDto<Guid>

public string Title { get; set; }

public string UrlSlug { get; set; }
public string Slug { get; set; }
public string ShortDescription { get; protected set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public class CreateUpdateBlogPostDto
[Required]
[DynamicStringLength(
typeof(BlogPostConsts),
nameof(BlogPostConsts.MaxUrlSlugLength),
nameof(BlogPostConsts.MinUrlSlugLength))]
public string UrlSlug { get; set; }
nameof(BlogPostConsts.MaxSlugLength),
nameof(BlogPostConsts.MinSlugLength))]
public string Slug { get; set; }

[DynamicMaxLength(typeof(BlogPostConsts), nameof(BlogPostConsts.MaxShortDescriptionLength))]
public string ShortDescription { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IBlogPostAdminAppService
PagedAndSortedResultRequestDto,
CreateUpdateBlogPostDto>
{
Task<BlogPostDto> GetByUrlSlugAsync(string blogUrlSlug, string urlSlug);
Task<BlogPostDto> GetBySlugAsync(string blogSlug, string slug);

Task SetCoverImageAsync(Guid id, RemoteStreamContent streamContent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public BlogPostAdminAppService(
DeletePolicyName = CmsKitAdminPermissions.BlogPosts.Delete;
}

public virtual async Task<BlogPostDto> GetByUrlSlugAsync(string blogUrlSlug, string urlSlug)
public virtual async Task<BlogPostDto> GetBySlugAsync(string blogSlug, string blogPostSlug)
{
var blog = await BlogRepository.GetByUrlSlugAsync(blogUrlSlug);
var blog = await BlogRepository.GetBySlugAsync(blogSlug);

var blogPost = await BlogPostRepository.GetByUrlSlugAsync(blog.Id, urlSlug);
var blogPost = await BlogPostRepository.GetBySlugAsync(blog.Id, blogPostSlug);

return MapToGetOutputDto(blogPost);
}
Expand All @@ -73,7 +73,7 @@ public override async Task<BlogPostDto> CreateAsync(CreateUpdateBlogPostDto inpu
GuidGenerator.Create(),
input.BlogId,
input.Title,
input.UrlSlug,
input.Slug,
input.ShortDescription));

return MapToGetOutputDto(entity);
Expand All @@ -86,9 +86,9 @@ public override async Task<BlogPostDto> UpdateAsync(Guid id, CreateUpdateBlogPos

blogPost.SetTitle(input.Title);

if (blogPost.UrlSlug != input.UrlSlug)
if (blogPost.Slug != input.Slug)
{
await BlogPostManager.SetSlugUrlAsync(blogPost, input.UrlSlug);
await BlogPostManager.SetSlugUrlAsync(blogPost, input.Slug);
}

MapToEntity(input, blogPost);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public virtual Task<BlogPostDto> GetAsync(Guid id)
}

[HttpGet]
[Route("{blogUrlSlug}/{urlSlug}")]
[Route("{blogSlug}/{blogPostSlug}")]
[Authorize(CmsKitAdminPermissions.BlogPosts.Default)]
public virtual Task<BlogPostDto> GetByUrlSlugAsync(string blogUrlSlug, string urlSlug)
public virtual Task<BlogPostDto> GetBySlugAsync(string blogSlug, string blogPostSlug)
{
return BlogPostAdminAppService.GetByUrlSlugAsync(blogUrlSlug, urlSlug);
return BlogPostAdminAppService.GetBySlugAsync(blogSlug, blogPostSlug);
}

[HttpGet]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class BlogConsts
{
public static int MaxNameLength { get; set; } = 64;
public static int MaxUrlSlugLength { get; set; } = 64;
public static int MaxSlugLength { get; set; } = 64;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ public static class BlogPostConsts
{
public static int MaxTitleLength { get; set; } = 64;

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

public static int MinUrlSlugLength { get; set; } = 2;
public static int MinSlugLength { get; set; } = 2;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class Pages

public static class Blogs
{
public const string UrlSlugAlreadyExist = "CmsKit:BlogPost:0001";
public const string SlugAlreadyExist = "CmsKit:BlogPost:0001";
}
}
}
12 changes: 6 additions & 6 deletions modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/Blog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ public class Blog : FullAuditedAggregateRoot<Guid>, IMultiTenant
public Blog(
Guid id,
[NotNull] string name,
[NotNull] string urlSlug,
[NotNull] string slug,
[CanBeNull] Guid? tenantId = null) : base(id)
{
SetName(name);
SetUrlSlug(urlSlug);
SetSlug(slug);
TenantId = tenantId;
}

public string Name { get; protected set; }

public string UrlSlug { get; protected set; }
public string Slug { get; protected set; }

public Guid? TenantId { get; protected set; }

Expand All @@ -31,11 +31,11 @@ public void SetName(string name)
Name = Check.NotNullOrWhiteSpace(name, nameof(name), maxLength: BlogConsts.MaxNameLength);
}

public void SetUrlSlug(string urlSlug)
public void SetSlug(string slug)
{
Check.NotNullOrWhiteSpace(urlSlug, nameof(urlSlug), maxLength: BlogConsts.MaxNameLength);
Check.NotNullOrWhiteSpace(slug, nameof(slug), maxLength: BlogConsts.MaxNameLength);

UrlSlug = urlSlug.NormalizeAsUrlSlug();
Slug = slug.NormalizeSlug();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class BlogPost : FullAuditedAggregateRootWithUser<Guid, CmsUser>, IMultiT

public string Title { get; protected set; }

public string UrlSlug { get; protected set; }
public string Slug { get; protected set; }

public string ShortDescription { get; protected set; }

Expand All @@ -30,12 +30,12 @@ public BlogPost(
Guid id,
Guid blogId,
[NotNull] string title,
[NotNull] string urlSlug,
[NotNull] string slug,
[CanBeNull] string shortDescription = null) : base(id)
{
BlogId = blogId;
SetTitle(title);
SetUrlSlug(urlSlug);
SetSlug(slug);
ShortDescription = shortDescription;
}

Expand All @@ -44,11 +44,11 @@ public void SetTitle(string title)
Title = Check.NotNullOrWhiteSpace(title, nameof(title), BlogPostConsts.MaxTitleLength);
}

internal void SetUrlSlug(string urlSlug)
internal void SetSlug(string slug)
{
Check.NotNullOrWhiteSpace(urlSlug, nameof(urlSlug), BlogPostConsts.MaxUrlSlugLength, BlogPostConsts.MinUrlSlugLength);
Check.NotNullOrWhiteSpace(slug, nameof(slug), BlogPostConsts.MaxSlugLength, BlogPostConsts.MinSlugLength);

UrlSlug = urlSlug.NormalizeAsUrlSlug();
Slug = slug.NormalizeSlug();
}

public void SetShortDescription(string shortDescription)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task<BlogPost> CreateAsync(BlogPost blogPost)
{
await CheckBlogExistenceAsync(blogPost.BlogId);

await CheckUrlSlugExistenceAsync(blogPost.BlogId, blogPost.UrlSlug);
await CheckSlugExistenceAsync(blogPost.BlogId, blogPost.Slug);

return await blogPostRepository.InsertAsync(blogPost);
}
Expand All @@ -39,16 +39,16 @@ public async Task UpdateAsync(BlogPost blogPost)

public async Task SetSlugUrlAsync(BlogPost blogPost, string newSlug)
{
await CheckUrlSlugExistenceAsync(blogPost.BlogId, newSlug);
await CheckSlugExistenceAsync(blogPost.BlogId, newSlug);

blogPost.SetUrlSlug(newSlug);
blogPost.SetSlug(newSlug);
}

private async Task CheckUrlSlugExistenceAsync(Guid blogId, string urlSlug)
private async Task CheckSlugExistenceAsync(Guid blogId, string slug)
{
if (await blogPostRepository.SlugExistsAsync(blogId, urlSlug))
if (await blogPostRepository.SlugExistsAsync(blogId, slug))
{
throw new BlogPostUrlSlugAlreadyExistException(blogId, urlSlug);
throw new BlogPostSlugAlreadyExistException(blogId, slug);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using Volo.Abp;

namespace Volo.CmsKit.Blogs
{
public class BlogPostSlugAlreadyExistException : BusinessException
{
internal BlogPostSlugAlreadyExistException(string code = null, string message = null, string details = null, Exception innerException = null, Microsoft.Extensions.Logging.LogLevel logLevel = Microsoft.Extensions.Logging.LogLevel.Warning) : base(code, message, details, innerException, logLevel)
{
}

internal BlogPostSlugAlreadyExistException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext context) : base(serializationInfo, context)
{
}

public BlogPostSlugAlreadyExistException(Guid blogId, string slug)
{
Slug = slug;
BlogId = blogId;

Code = CmsKitErrorCodes.Blogs.SlugAlreadyExist;

WithData(nameof(Slug), Slug);
WithData(nameof(BlogId), BlogId);
}

public string Slug { get; }

public Guid BlogId { get; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using Slugify;
using System.Text.RegularExpressions;
using Unidecode.NET;

namespace Volo.CmsKit.Blogs.Extensions
{
public static class UrlSlugExtensions
public static class SlugExtensions
{
public static string NormalizeAsUrlSlug(this string value)
public static string NormalizeSlug(this string value)
{
var slugHelper = new SlugHelper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IBlogPostRepository : IBasicRepository<BlogPost, Guid>
{
Task<bool> SlugExistsAsync(Guid blogId, string slug, CancellationToken cancellationToken = default);

Task<BlogPost> GetByUrlSlugAsync(Guid blogId, string urlSlug, CancellationToken cancellationToken = default);
Task<BlogPost> GetBySlugAsync(Guid blogId, string Slug, CancellationToken cancellationToken = default);

Task<List<BlogPost>> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Volo.CmsKit.Blogs
{
public interface IBlogRepository : IBasicRepository<Blog, Guid>
{
public Task<Blog> GetByUrlSlugAsync(string urlSlug);
public Task<Blog> GetBySlugAsync(string slug);
Task<bool> ExistsAsync(Guid blogId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public EfCoreBlogPostRepository(IDbContextProvider<CmsKitDbContext> dbContextPro
{
}

public async Task<BlogPost> GetByUrlSlugAsync(Guid blogId, string urlSlug, CancellationToken cancellationToken = default)
public async Task<BlogPost> GetBySlugAsync(Guid blogId, string slug, CancellationToken cancellationToken = default)
{
var dbSet = await GetDbSetAsync();

return await dbSet
.Include(i=> i.Creator)
.Where(x =>
x.BlogId == blogId && x.UrlSlug.ToLower() == urlSlug)
x.BlogId == blogId && x.Slug.ToLower() == slug)
.FirstOrDefaultAsync(cancellationToken: cancellationToken)
?? throw new EntityNotFoundException(typeof(BlogPost));
}
Expand Down Expand Up @@ -60,7 +60,7 @@ public async Task<bool> SlugExistsAsync(Guid blogId, string slug, CancellationTo
{
var dbSet = await GetDbSetAsync();

return await dbSet.AnyAsync(x => x.BlogId == blogId && x.UrlSlug.ToLower() == slug, cancellationToken);
return await dbSet.AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public async Task<bool> ExistsAsync(Guid blogId)
return await (await GetQueryableAsync()).AnyAsync(x => x.Id == blogId);
}

public Task<Blog> GetByUrlSlugAsync(string urlSlug)
public Task<Blog> GetBySlugAsync(string slug)
{
return GetAsync(x => x.UrlSlug == urlSlug);
return GetAsync(x => x.Slug == slug);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static void ConfigureCmsKit(

b.Property(p => p.Name).IsRequired().HasMaxLength(BlogConsts.MaxNameLength);

b.Property(p => p.UrlSlug).IsRequired().HasMaxLength(BlogConsts.MaxUrlSlugLength);
b.Property(p => p.Slug).IsRequired().HasMaxLength(BlogConsts.MaxSlugLength);
});

builder.Entity<BlogPost>(b =>
Expand All @@ -209,11 +209,11 @@ public static void ConfigureCmsKit(

b.Property(p => p.Title).IsRequired().HasMaxLength(BlogPostConsts.MaxTitleLength);

b.Property(p => p.UrlSlug).IsRequired().HasMaxLength(BlogPostConsts.MaxUrlSlugLength);
b.Property(p => p.Slug).IsRequired().HasMaxLength(BlogPostConsts.MaxSlugLength);

b.Property(p => p.ShortDescription).HasMaxLength(BlogPostConsts.MaxShortDescriptionLength);

b.HasIndex(x => new { x.UrlSlug, x.BlogId });
b.HasIndex(x => new { x.Slug, x.BlogId });
});
}
else
Expand Down
Loading

0 comments on commit f277764

Please sign in to comment.