Skip to content

Commit

Permalink
refactor: More code simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Feb 17, 2024
1 parent 7713d8b commit 30f187f
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ public ValueTask<IPagedList<TEntity>> GetAllAsync(
Expression<Func<TEntity, object>> orderBy = null,
bool descending = true,
int page = 1,
int pageSize = int.MaxValue)
{
return GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize);
}
int pageSize = int.MaxValue) =>
GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize);

public ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProjection>(
Expression<Func<TEntity, TProjection>> selector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ public async ValueTask<TEntity> GetByIdAsync(string id)
return await session.LoadAsync<TEntity>(id);
}

public async ValueTask<IPagedList<TEntity>> GetAllAsync(
public ValueTask<IPagedList<TEntity>> GetAllAsync(
Expression<Func<TEntity, bool>> filter = null,
Expression<Func<TEntity, object>> orderBy = null,
bool descending = true,
int page = 1,
int pageSize = int.MaxValue)
{
return await GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize);
}
int pageSize = int.MaxValue) =>
GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize);

public async ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProjection>(
Expression<Func<TEntity, TProjection>> selector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ public async ValueTask<TEntity> GetByIdAsync(string id)
return await blogDbContext.Set<TEntity>().SingleOrDefaultAsync(b => b.Id == id);
}

public async ValueTask<IPagedList<TEntity>> GetAllAsync(
public ValueTask<IPagedList<TEntity>> GetAllAsync(
Expression<Func<TEntity, bool>> filter = null,
Expression<Func<TEntity, object>> orderBy = null,
bool descending = true,
int page = 1,
int pageSize = int.MaxValue)
{
return await GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize);
}
int pageSize = int.MaxValue) =>
GetAllByProjectionAsync(s => s, filter, orderBy, descending, page, pageSize);

public async ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProjection>(
Expression<Func<TEntity, TProjection>> selector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class AuthExtensions
{
public static void UseAuthentication(this IServiceCollection services)
{
var authInformation = services.BuildServiceProvider().GetService<IOptions<AuthInformation>>();
var authInformation = services.BuildServiceProvider().GetRequiredService<IOptions<AuthInformation>>();

services.Configure<CookiePolicyOptions>(options =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/LinkDotNet.Blog.Web/Controller/RssFeedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static SyndicationItem CreateSyndicationItemFromBlogPost(string url, Blo

private static void AddCategories(Collection<SyndicationCategory> categories, BlogPostRssInfo blogPost)
{
foreach (var tag in blogPost.Tags ?? Array.Empty<string>())
foreach (var tag in blogPost.Tags ?? [])
{
categories.Add(new SyndicationCategory(tag));
}
Expand Down
2 changes: 1 addition & 1 deletion src/LinkDotNet.Blog.Web/DatabaseHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public DatabaseHealthCheck(IRepository<BlogPost> repository)

public Task<HealthCheckResult> CheckHealthAsync(
HealthCheckContext context,
CancellationToken cancellationToken = default) =>
CancellationToken cancellationToken = default) =>
repository.PerformHealthCheckAsync().AsTask();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ public sealed class FutureDateValidationAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value is null)
{
return ValidationResult.Success;
}

return (DateTime)value <= DateTime.UtcNow
? new ValidationResult("The scheduled publish date must be in the future.")
: ValidationResult.Success;
return value is not DateTime dt || dt > DateTime.UtcNow
? ValidationResult.Success
: new ValidationResult("The scheduled publish date must be in the future.");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace LinkDotNet.Blog.Web.Features.Components;

public record struct SelectionRange
public readonly record struct SelectionRange
{
public int Start { get; init; }

Expand Down

0 comments on commit 30f187f

Please sign in to comment.