diff options
author | crupest <crupest@outlook.com> | 2020-07-10 22:50:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-10 22:50:01 +0800 |
commit | 15e7467e6089537f0f3e2290f14a99b8a1fc2d76 (patch) | |
tree | a0ba363d1df5d1846f3a46bae4d0ffe7b72e1c89 /Timeline/Services/TimelineService.cs | |
parent | 838f9377514b03404afa1d6b6e42e981174178b5 (diff) | |
parent | 3735e7fecd2c9eaf525cedb55912f918aad20779 (diff) | |
download | timeline-15e7467e6089537f0f3e2290f14a99b8a1fc2d76.tar.gz timeline-15e7467e6089537f0f3e2290f14a99b8a1fc2d76.tar.bz2 timeline-15e7467e6089537f0f3e2290f14a99b8a1fc2d76.zip |
Merge pull request #115 from crupest/post-deleted
Add timeline post deleted field.
Diffstat (limited to 'Timeline/Services/TimelineService.cs')
-rw-r--r-- | Timeline/Services/TimelineService.cs | 60 |
1 files changed, 23 insertions, 37 deletions
diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index 73f6c8ef..a0d72ad3 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -96,20 +96,8 @@ namespace Timeline.Services /// Get all the posts in the timeline.
/// </summary>
/// <param name="timelineName">The name of the timeline.</param>
- /// <returns>A list of all posts.</returns>
- /// <exception cref="ArgumentNullException">Thrown when <paramref name="timelineName"/> is null.</exception>
- /// <exception cref="ArgumentException">Throw when <paramref name="timelineName"/> is of bad format.</exception>
- /// <exception cref="TimelineNotExistException">
- /// Thrown when timeline with name <paramref name="timelineName"/> does not exist.
- /// If it is a personal timeline, then inner exception is <see cref="UserNotExistException"/>.
- /// </exception>
- Task<List<TimelinePost>> GetPosts(string timelineName);
-
- /// <summary>
- /// Get the posts that have been modified since a given time in the timeline.
- /// </summary>
- /// <param name="timelineName">The name of the timeline.</param>
/// <param name="modifiedSince">The time that posts have been modified since.</param>
+ /// <param name="includeDeleted">Whether include deleted posts.</param>
/// <returns>A list of all posts.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="timelineName"/> is null.</exception>
/// <exception cref="ArgumentException">Throw when <paramref name="timelineName"/> is of bad format.</exception>
@@ -117,7 +105,7 @@ namespace Timeline.Services /// Thrown when timeline with name <paramref name="timelineName"/> does not exist.
/// If it is a personal timeline, then inner exception is <see cref="UserNotExistException"/>.
/// </exception>
- Task<List<TimelinePost>> GetPosts(string timelineName, DateTime modifiedSince);
+ Task<List<TimelinePost>> GetPosts(string timelineName, DateTime? modifiedSince = null, bool includeDeleted = false);
/// <summary>
/// Get the etag of data of a post.
@@ -399,21 +387,23 @@ namespace Timeline.Services private async Task<TimelinePost> MapTimelinePostFromEntity(TimelinePostEntity entity, string timelineName)
{
- if (entity.Content == null)
- {
- throw new ArgumentException(ExceptionPostDeleted, nameof(entity));
- }
+
var author = await _userService.GetUserById(entity.AuthorId);
- var type = entity.ContentType;
+ ITimelinePostContent? content = null;
- ITimelinePostContent content = type switch
+ if (entity.Content != null)
{
- TimelinePostContentTypes.Text => new TextTimelinePostContent(entity.Content),
- TimelinePostContentTypes.Image => new ImageTimelinePostContent(entity.Content),
- _ => throw new DatabaseCorruptedException(string.Format(CultureInfo.InvariantCulture, ExceptionDatabaseUnknownContentType, type))
- };
+ var type = entity.ContentType;
+
+ content = type switch
+ {
+ TimelinePostContentTypes.Text => new TextTimelinePostContent(entity.Content),
+ TimelinePostContentTypes.Image => new ImageTimelinePostContent(entity.Content),
+ _ => throw new DatabaseCorruptedException(string.Format(CultureInfo.InvariantCulture, ExceptionDatabaseUnknownContentType, type))
+ };
+ }
return new TimelinePost(
id: entity.LocalId,
@@ -519,29 +509,25 @@ namespace Timeline.Services return await MapTimelineFromEntity(timelineEntity);
}
- public async Task<List<TimelinePost>> GetPosts(string timelineName)
+ public async Task<List<TimelinePost>> GetPosts(string timelineName, DateTime? modifiedSince = null, bool includeDeleted = false)
{
if (timelineName == null)
throw new ArgumentNullException(nameof(timelineName));
var timelineId = await FindTimelineId(timelineName);
- var postEntities = await _database.TimelinePosts.OrderBy(p => p.Time).Where(p => p.TimelineId == timelineId && p.Content != null).ToListAsync();
+ var query = _database.TimelinePosts.OrderBy(p => p.Time).Where(p => p.TimelineId == timelineId);
- var posts = new List<TimelinePost>();
- foreach (var entity in postEntities)
+ if (!includeDeleted)
{
- posts.Add(await MapTimelinePostFromEntity(entity, timelineName));
+ query = query.Where(p => p.Content != null);
}
- return posts;
- }
- public async Task<List<TimelinePost>> GetPosts(string timelineName, DateTime modifiedSince)
- {
- if (timelineName == null)
- throw new ArgumentNullException(nameof(timelineName));
+ if (modifiedSince.HasValue)
+ {
+ query = query.Where(p => p.LastUpdated >= modifiedSince);
+ }
- var timelineId = await FindTimelineId(timelineName);
- var postEntities = await _database.TimelinePosts.OrderBy(p => p.Time).Where(p => p.TimelineId == timelineId && p.Content != null && p.LastUpdated >= modifiedSince).ToListAsync();
+ var postEntities = await query.ToListAsync();
var posts = new List<TimelinePost>();
foreach (var entity in postEntities)
|