From c987364ce795c7f4fe837ad8c2a685558c25b0b5 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 4 Feb 2021 22:03:08 +0800 Subject: ... --- BackEnd/Timeline/Services/TimelinePostService.cs | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'BackEnd/Timeline/Services/TimelinePostService.cs') 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 @@ -44,6 +44,17 @@ namespace Timeline.Services /// Thrown when timeline does not exist. Task> GetPosts(long timelineId, DateTime? modifiedSince = null, bool includeDeleted = false); + /// + /// Get a post of a timeline. + /// + /// The id of the timeline of the post. + /// The id of the post. + /// If true, return the entity even if it is deleted. + /// The post. + /// Thrown when timeline does not exist. + /// Thrown when post of does not exist or has been deleted. + Task GetPost(long timelineId, long postId, bool includeDelete = false); + /// /// Get the etag of data of a post. /// @@ -189,6 +200,25 @@ namespace Timeline.Services return await query.ToListAsync(); } + public async Task 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 GetPostDataETag(long timelineId, long postId) { await CheckTimelineExistence(timelineId); -- cgit v1.2.3