diff options
author | crupest <crupest@outlook.com> | 2021-02-04 22:03:08 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-02-04 22:04:39 +0800 |
commit | 66658abde1220a53d0e022aaac8dd49a15034a34 (patch) | |
tree | c8712a2d8fc5e979dae64ea9bfcf590198429039 /BackEnd/Timeline/Services | |
parent | 90c74a29bb0bdc6972deb188fa13a8ec5c2870ed (diff) | |
download | timeline-66658abde1220a53d0e022aaac8dd49a15034a34.tar.gz timeline-66658abde1220a53d0e022aaac8dd49a15034a34.tar.bz2 timeline-66658abde1220a53d0e022aaac8dd49a15034a34.zip |
...
Diffstat (limited to 'BackEnd/Timeline/Services')
-rw-r--r-- | BackEnd/Timeline/Services/TimelinePostService.cs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Services/TimelinePostService.cs b/BackEnd/Timeline/Services/TimelinePostService.cs index c2b773ff..cf5f4e55 100644 --- a/BackEnd/Timeline/Services/TimelinePostService.cs +++ b/BackEnd/Timeline/Services/TimelinePostService.cs @@ -45,6 +45,17 @@ namespace Timeline.Services Task<List<TimelinePostEntity>> GetPosts(long timelineId, DateTime? modifiedSince = null, bool includeDeleted = false);
/// <summary>
+ /// Get a post of a timeline.
+ /// </summary>
+ /// <param name="timelineId">The id of the timeline of the post.</param>
+ /// <param name="postId">The id of the post.</param>
+ /// <param name="includeDelete">If true, return the entity even if it is deleted.</param>
+ /// <returns>The post.</returns>
+ /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
+ /// <exception cref="TimelinePostNotExistException">Thrown when post of <paramref name="postId"/> does not exist or has been deleted.</exception>
+ Task<TimelinePostEntity> GetPost(long timelineId, long postId, bool includeDelete = false);
+
+ /// <summary>
/// Get the etag of data of a post.
/// </summary>
/// <param name="timelineId">The id of the timeline of the post.</param>
@@ -189,6 +200,25 @@ namespace Timeline.Services return await query.ToListAsync();
}
+ public async Task<TimelinePostEntity> GetPost(long timelineId, long postId, bool includeDelete = false)
+ {
+ await CheckTimelineExistence(timelineId);
+
+ var post = await _database.TimelinePosts.Where(p => p.TimelineId == timelineId && p.LocalId == postId).SingleOrDefaultAsync();
+
+ if (post is null)
+ {
+ throw new TimelinePostNotExistException(timelineId, postId, false);
+ }
+
+ if (!includeDelete && post.Content is null)
+ {
+ throw new TimelinePostNotExistException(timelineId, postId, true);
+ }
+
+ return post;
+ }
+
public async Task<string> GetPostDataETag(long timelineId, long postId)
{
await CheckTimelineExistence(timelineId);
|