diff options
Diffstat (limited to 'BackEnd/Timeline')
3 files changed, 9 insertions, 18 deletions
diff --git a/BackEnd/Timeline/Controllers/V2/TimelinePostV2Controller.cs b/BackEnd/Timeline/Controllers/V2/TimelinePostV2Controller.cs index 8b7101e4..a6d12ae4 100644 --- a/BackEnd/Timeline/Controllers/V2/TimelinePostV2Controller.cs +++ b/BackEnd/Timeline/Controllers/V2/TimelinePostV2Controller.cs @@ -47,7 +47,7 @@ namespace Timeline.Controllers.V2 { return Forbid(); } - var postPage = await _postService.GetPostsV2Async(timelineId, modifiedSince, page, pageSize); + var postPage = await _postService.GetPostsV2Async(timelineId, page ?? 1, pageSize ?? 20, modifiedSince); var items = await MapListAsync<HttpTimelinePost>(postPage.Items); return postPage.WithItems(items); } diff --git a/BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs b/BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs index af36933c..105ceb54 100644 --- a/BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs +++ b/BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs @@ -65,7 +65,7 @@ namespace Timeline.Services.Timeline /// <param name="numberPerPage">Number per page.</param> /// <returns>A task containing a page of post entity.</returns> /// <exception cref="EntityNotExistException">Thrown when timeline does not exist.</exception> - Task<Page<TimelinePostEntity>> GetPostsV2Async(long timelineId, DateTime? modifiedSince = null, int? page = null, int? numberPerPage = null);
+ Task<Page<TimelinePostEntity>> GetPostsV2Async(long timelineId, int page, int numberPerPage, DateTime? modifiedSince = null);
/// <summary> /// Get a post of a timeline. diff --git a/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs b/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs index e0212cb7..8fee0467 100644 --- a/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs +++ b/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs @@ -382,13 +382,12 @@ namespace Timeline.Services.Timeline return timelineEntity.OwnerId == modifierId || postEntity.AuthorId == modifierId;
} - public async Task<Page<TimelinePostEntity>> GetPostsV2Async(long timelineId, DateTime? modifiedSince = null, int? page = null, int? numberPerPage = null) + public async Task<Page<TimelinePostEntity>> GetPostsV2Async(long timelineId, int page, int pageSize, DateTime? modifiedSince = null) { - if (page.HasValue && page < 0)
- throw new ArgumentOutOfRangeException(nameof(page), Resource.ExceptionPageNegative);
- if (numberPerPage.HasValue && numberPerPage <= 0)
- throw new ArgumentOutOfRangeException(nameof(numberPerPage), Resource.ExceptionNumberPerPageZeroOrNegative);
-
+ if (page <= 0)
+ throw new ArgumentOutOfRangeException(nameof(page));
+ if (pageSize <= 0)
+ throw new ArgumentOutOfRangeException(nameof(pageSize));
var timeline = await _timelineService.GetTimelineAsync(timelineId);
@@ -401,19 +400,11 @@ namespace Timeline.Services.Timeline query = query.Where(p => p.LastUpdated >= modifiedSince || (p.Author != null && p.Author.UsernameChangeTime >= modifiedSince));
}
- query = query.OrderBy(p => p.Time); + query = query.OrderBy(p => p.Time).Skip(pageSize * (page - 1)).Take(pageSize); - var pageNumber = page.GetValueOrDefault(1); - var pageSize = numberPerPage.GetValueOrDefault(20);
-
- if (pageNumber > 1)
- {
- query = query.Skip(pageSize * (pageNumber - 1)).Take(pageSize);
- }
-
var items = await query.ToListAsync(); - return new Page<TimelinePostEntity>(pageNumber, pageSize, timeline.CurrentPostLocalId, items); + return new Page<TimelinePostEntity>(page, pageSize, timeline.CurrentPostLocalId, items); } public async Task<TimelinePostEntity> GetPostV2Async(long timelineId, long postId) |