aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Services
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-05-13 15:53:08 +0800
committercrupest <crupest@outlook.com>2021-05-13 15:53:08 +0800
commit5b059ad031b87fc2e3beaf1b650fc365b34b86ba (patch)
treedd56141734ad3c97ae1a6c8e8a9b4f25ebabeca3 /BackEnd/Timeline/Services
parentaea8e41def7eab0d4e9f339ff14143f5441ae71d (diff)
downloadtimeline-5b059ad031b87fc2e3beaf1b650fc365b34b86ba.tar.gz
timeline-5b059ad031b87fc2e3beaf1b650fc365b34b86ba.tar.bz2
timeline-5b059ad031b87fc2e3beaf1b650fc365b34b86ba.zip
feat: Posts pagination.
Diffstat (limited to 'BackEnd/Timeline/Services')
-rw-r--r--BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs4
-rw-r--r--BackEnd/Timeline/Services/Timeline/Resource.Designer.cs18
-rw-r--r--BackEnd/Timeline/Services/Timeline/Resource.resx6
-rw-r--r--BackEnd/Timeline/Services/Timeline/TimelinePostService.cs14
4 files changed, 40 insertions, 2 deletions
diff --git a/BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs b/BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs
index 92984938..c0edf857 100644
--- a/BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs
+++ b/BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs
@@ -16,9 +16,11 @@ namespace Timeline.Services.Timeline
/// <param name="timelineId">The id of the timeline.</param>
/// <param name="modifiedSince">The time that posts have been modified since.</param>
/// <param name="includeDeleted">Whether include deleted posts.</param>
+ /// <param name="page">The page number. Starts from 0. If null, do not do pagination.</param>
+ /// <param name="numberPerPage">Count of entities per page. If null, 20.</param>
/// <returns>A list of all posts.</returns>
/// <exception cref="EntityNotExistException">Thrown when timeline does not exist.</exception>
- Task<List<TimelinePostEntity>> GetPostsAsync(long timelineId, DateTime? modifiedSince = null, bool includeDeleted = false);
+ Task<List<TimelinePostEntity>> GetPostsAsync(long timelineId, DateTime? modifiedSince = null, bool includeDeleted = false, int? page = null, int? numberPerPage = null);
/// <summary>
/// Get a post of a timeline.
diff --git a/BackEnd/Timeline/Services/Timeline/Resource.Designer.cs b/BackEnd/Timeline/Services/Timeline/Resource.Designer.cs
index 5ad03011..f5112cd9 100644
--- a/BackEnd/Timeline/Services/Timeline/Resource.Designer.cs
+++ b/BackEnd/Timeline/Services/Timeline/Resource.Designer.cs
@@ -106,6 +106,24 @@ namespace Timeline.Services.Timeline {
}
/// <summary>
+ /// Looks up a localized string similar to Number per page can&apos;t be zero or negative..
+ /// </summary>
+ internal static string ExceptionNumberPerPageZeroOrNegative {
+ get {
+ return ResourceManager.GetString("ExceptionNumberPerPageZeroOrNegative", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Page number can&apos;t be negative..
+ /// </summary>
+ internal static string ExceptionPageNegative {
+ get {
+ return ResourceManager.GetString("ExceptionPageNegative", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Image validation failed..
/// </summary>
internal static string ExceptionPostDataImageInvalid {
diff --git a/BackEnd/Timeline/Services/Timeline/Resource.resx b/BackEnd/Timeline/Services/Timeline/Resource.resx
index cc293d05..1d61a1bb 100644
--- a/BackEnd/Timeline/Services/Timeline/Resource.resx
+++ b/BackEnd/Timeline/Services/Timeline/Resource.resx
@@ -132,6 +132,12 @@
<data name="ExceptionGeneralTimelineNameBadFormat" xml:space="preserve">
<value>This timeline name is neither a valid personal timeline name nor a valid ordinary timeline name. {0}</value>
</data>
+ <data name="ExceptionNumberPerPageZeroOrNegative" xml:space="preserve">
+ <value>Number per page can't be zero or negative.</value>
+ </data>
+ <data name="ExceptionPageNegative" xml:space="preserve">
+ <value>Page number can't be negative.</value>
+ </data>
<data name="ExceptionPostDataImageInvalid" xml:space="preserve">
<value>Image validation failed.</value>
</data>
diff --git a/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs b/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs
index a0961a8d..ee1002e0 100644
--- a/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs
+++ b/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs
@@ -64,8 +64,14 @@ namespace Timeline.Services.Timeline
});
}
- public async Task<List<TimelinePostEntity>> GetPostsAsync(long timelineId, DateTime? modifiedSince = null, bool includeDeleted = false)
+ public async Task<List<TimelinePostEntity>> GetPostsAsync(long timelineId, DateTime? modifiedSince = null, bool includeDeleted = false, int? page = null, int? numberPerPage = 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);
+
+
await _basicTimelineService.ThrowIfTimelineNotExist(timelineId);
modifiedSince = modifiedSince?.MyToUtc();
@@ -84,6 +90,12 @@ namespace Timeline.Services.Timeline
query = query.OrderBy(p => p.Time);
+ if (page.HasValue)
+ {
+ var npp = numberPerPage.GetValueOrDefault(20);
+ query = query.Skip(npp * (page.Value - 1)).Take(npp);
+ }
+
return await query.ToListAsync();
}