Skip to content

Commit

Permalink
refactor: Remove unused code from post repository #208
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray Fan authored and Ray Fan committed Oct 7, 2018
1 parent d35245a commit 9bba261
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 46 deletions.
11 changes: 1 addition & 10 deletions src/Fan.Blog/Data/IPostRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,11 @@ public interface IPostRepository : IRepository<Post>
/// <param name="type">If it's BlogPost it'll return category and tags with it.</param>
Task<Post> GetAsync(int id, EPostType type);

/// <summary>
/// Returns a <see cref="Post"/> by slug. If it is a BlogPost it'll return together with its
/// <see cref="Category"/> and <see cref="Tag"/>. Returns null if it's not found.
/// </summary>
/// <param name="slug"></param>
/// <param name="type">If it's BlogPost it'll return category and tags with it.</param>
/// <returns></returns>
Task<Post> GetAsync(string slug, EPostType type);

/// <summary>
/// Returns a <see cref="EPostStatus.Published"/> <see cref="Post"/>, returns null if it's not found.
/// </summary>
Task<Post> GetAsync(string slug, int year, int month, int day);

/// <summary>
/// Returns a list of posts and total post count by query or empty list if no posts found.
/// </summary>
Expand Down
22 changes: 0 additions & 22 deletions src/Fan.Blog/Data/SqlPostRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,6 @@ await _entities.Include(p => p.User).Include(p => p.Category).Include(p => p.Pos
await _entities.Include(p => p.User).SingleOrDefaultAsync(p => p.Id == id);
}

/// <summary>
/// Returns a <see cref="Post"/> by slug. If it is a BlogPost it'll return together with its
/// <see cref="Category"/> and <see cref="Tag"/>. Returns null if it's not found.
/// </summary>
/// <param name="slug"></param>
/// <param name="type">If it's BlogPost it'll return category and tags with it.</param>
/// <returns></returns>
public async Task<Post> GetAsync(string slug, EPostType type)
{
return (type == EPostType.BlogPost) ?
await _entities.Include(p => p.User).Include(p => p.Category).Include(p => p.PostTags).ThenInclude(p => p.Tag)
.SingleOrDefaultAsync(p =>
p.Type == EPostType.BlogPost &&
p.Status == EPostStatus.Published &&
p.Slug.Equals(slug, StringComparison.CurrentCultureIgnoreCase)) :
await _entities.Include(p => p.User)
.SingleOrDefaultAsync(p =>
p.Type == type &&
p.Status == EPostStatus.Published &&
p.Slug.Equals(slug, StringComparison.CurrentCultureIgnoreCase));
}

/// <summary>
/// Returns a <see cref="EPostStatus.Published"/> <see cref="Post"/>, returns null if it's not found.
/// </summary>
Expand Down
14 changes: 0 additions & 14 deletions test/Fan.Blog.IntegrationTests/SqlPostRepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,6 @@ public async void GetPost_By_Slug_Will_Return_Category_And_Tags_For_BlogPost()
Assert.True(post.PostTags.ToList()[0].Tag.Id == 1);
}

/// <summary>
/// Test for <see cref="SqlPostRepository.GetAsync(string, EPostType)"/> will return null
/// if the specified slug is not found.
/// </summary>
[Fact]
public async void GetPost_By_Slug_Will_Return_Null_If_Not_Found()
{
// Act: getting a post that is not there
var blogPost = await _postRepo.GetAsync("not-found", EPostType.BlogPost);

// Assert
Assert.Null(blogPost);
}

/// <summary>
/// Test for <see cref="SqlPostRepository.GetAsync(string, int, int, int)"/> will return null
/// if the specified slug and year, month, day combo is not found.
Expand Down

0 comments on commit 9bba261

Please sign in to comment.