mirror of
https://github.com/Biarity/Sieve.git
synced 2025-07-27 04:33:23 +02:00
Fix for Issue #19
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Sieve.Models;
|
||||
@@ -10,11 +7,11 @@ using SieveTests.Entities;
|
||||
|
||||
namespace SieveTests.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class PostsController : Controller
|
||||
{
|
||||
private ISieveProcessor _sieveProcessor;
|
||||
private ApplicationDbContext _dbContext;
|
||||
private readonly ISieveProcessor _sieveProcessor;
|
||||
private readonly ApplicationDbContext _dbContext;
|
||||
|
||||
public PostsController(ISieveProcessor sieveProcessor,
|
||||
ApplicationDbContext dbContext)
|
||||
|
@@ -1,13 +1,8 @@
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SieveTests.Entities
|
||||
{
|
||||
public class ApplicationDbContext : DbContext
|
||||
public class ApplicationDbContext : DbContext
|
||||
{
|
||||
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
|
||||
|
||||
|
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Sieve.Attributes;
|
||||
|
||||
namespace SieveTests.Entities
|
||||
{
|
||||
public class Post
|
||||
public class Post
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SieveTests.Migrations
|
||||
{
|
||||
@@ -20,10 +19,7 @@ namespace SieveTests.Migrations
|
||||
LikeCount = table.Column<int>(nullable: false),
|
||||
Title = table.Column<string>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Posts", x => x.Id);
|
||||
});
|
||||
constraints: table => table.PrimaryKey("PK_Posts", x => x.Id));
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
|
@@ -1,21 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SieveTests
|
||||
{
|
||||
public class Program
|
||||
public static class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var host = BuildWebHost(args);
|
||||
|
||||
|
||||
host.Run();
|
||||
}
|
||||
|
||||
|
@@ -2,14 +2,10 @@
|
||||
using Sieve.Models;
|
||||
using Sieve.Services;
|
||||
using SieveTests.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SieveTests.Services
|
||||
{
|
||||
public class ApplicationSieveProcessor : SieveProcessor
|
||||
public class ApplicationSieveProcessor : SieveProcessor
|
||||
{
|
||||
public ApplicationSieveProcessor(IOptions<SieveOptions> options, ISieveCustomSortMethods customSortMethods, ISieveCustomFilterMethods customFilterMethods) : base(options, customSortMethods, customFilterMethods)
|
||||
{
|
||||
|
@@ -1,20 +1,12 @@
|
||||
using Sieve.Services;
|
||||
using SieveTests.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SieveTests.Services
|
||||
{
|
||||
public class SieveCustomFilterMethods : ISieveCustomFilterMethods
|
||||
public class SieveCustomFilterMethods : ISieveCustomFilterMethods
|
||||
{
|
||||
public IQueryable<Post> IsNew(IQueryable<Post> source, string op, string value)
|
||||
{
|
||||
var result = source.Where(p => p.LikeCount < 100 &&
|
||||
p.CommentCount < 5);
|
||||
|
||||
return result;
|
||||
}
|
||||
public IQueryable<Post> IsNew(IQueryable<Post> source)
|
||||
=> source.Where(p => p.LikeCount < 100 && p.CommentCount < 5);
|
||||
}
|
||||
}
|
||||
|
@@ -1,23 +1,15 @@
|
||||
using Sieve.Services;
|
||||
using System.Linq;
|
||||
using Sieve.Services;
|
||||
using SieveTests.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SieveTests.Services
|
||||
{
|
||||
public class SieveCustomSortMethods : ISieveCustomSortMethods
|
||||
{
|
||||
public IQueryable<Post> Popularity(IQueryable<Post> source, bool useThenBy, bool desc)
|
||||
{
|
||||
var result = useThenBy ?
|
||||
((IOrderedQueryable<Post>)source).ThenBy(p => p.LikeCount) :
|
||||
source.OrderBy(p => p.LikeCount)
|
||||
public IQueryable<Post> Popularity(IQueryable<Post> source, bool useThenBy) => useThenBy
|
||||
? ((IOrderedQueryable<Post>)source).ThenBy(p => p.LikeCount)
|
||||
: source.OrderBy(p => p.LikeCount)
|
||||
.ThenBy(p => p.CommentCount)
|
||||
.ThenBy(p => p.DateCreated);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Sieve.Models;
|
||||
using Sieve.Services;
|
||||
using SieveTests.Entities;
|
||||
@@ -16,7 +10,7 @@ using SieveTests.Services;
|
||||
|
||||
namespace SieveTests
|
||||
{
|
||||
public class Startup
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
|
Reference in New Issue
Block a user