|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using MongoDB.Driver; |
|
|
|
using MongoDB.Driver.Linq; |
|
|
|
@ -16,27 +17,27 @@ namespace Volo.Blogging.Posts |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<List<Post>> GetPostsByBlogId(Guid id) |
|
|
|
public async Task<List<Post>> GetPostsByBlogId(Guid id, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
return await (await GetMongoQueryableAsync()).Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync(); |
|
|
|
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync(GetCancellationToken(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null) |
|
|
|
public async Task<bool> IsPostUrlInUseAsync(Guid blogId, string url, Guid? excludingPostId = null, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var query = (await GetMongoQueryableAsync()).Where(p => blogId == p.BlogId && p.Url == url); |
|
|
|
var query = (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(p => blogId == p.BlogId && p.Url == url); |
|
|
|
|
|
|
|
if (excludingPostId != null) |
|
|
|
{ |
|
|
|
query = query.Where(p => excludingPostId != p.Id); |
|
|
|
} |
|
|
|
|
|
|
|
return await query.AnyAsync(); |
|
|
|
return await query.AnyAsync(GetCancellationToken(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<Post> GetPostByUrl(Guid blogId, string url) |
|
|
|
public async Task<Post> GetPostByUrl(Guid blogId, string url, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var post = await (await GetMongoQueryableAsync()).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url); |
|
|
|
var post = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url, GetCancellationToken(cancellationToken)); |
|
|
|
|
|
|
|
if (post == null) |
|
|
|
{ |
|
|
|
@ -46,16 +47,16 @@ namespace Volo.Blogging.Posts |
|
|
|
return post; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<List<Post>> GetOrderedList(Guid blogId, bool @descending = false) |
|
|
|
public async Task<List<Post>> GetOrderedList(Guid blogId, bool @descending = false, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var query = (await GetMongoQueryableAsync()).Where(x => x.BlogId == blogId); |
|
|
|
var query = (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(x => x.BlogId == blogId); |
|
|
|
|
|
|
|
if (!descending) |
|
|
|
{ |
|
|
|
return await query.OrderBy(x => x.CreationTime).ToListAsync(); |
|
|
|
return await query.OrderBy(x => x.CreationTime).ToListAsync(GetCancellationToken(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
return await query.OrderByDescending(x => x.CreationTime).ToListAsync(); |
|
|
|
return await query.OrderByDescending(x => x.CreationTime).ToListAsync(GetCancellationToken(cancellationToken)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|