diff options
Diffstat (limited to 'BackEnd/Timeline/Services')
-rw-r--r-- | BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs | 26 | ||||
-rw-r--r-- | BackEnd/Timeline/Services/Timeline/TimelinePostService.cs | 42 |
2 files changed, 68 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs b/BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs index f595af87..af36933c 100644 --- a/BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs +++ b/BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs @@ -79,6 +79,32 @@ namespace Timeline.Services.Timeline Task<TimelinePostEntity> GetPostV2Async(long timelineId, long postId);
/// <summary>
+ /// Get a data digest of a post.
+ /// </summary>
+ /// <param name="timelineId">The timeline id.</param>
+ /// <param name="postId">The post id.</param>
+ /// <param name="dataIndex">The index of the data.</param>
+ /// <returns>The data digest.</returns>
+ /// <exception cref="EntityNotExistException">Thrown when timeline does not exist.</exception>
+ /// <exception cref="EntityNotExistException">Thrown when post of <paramref name="postId"/> does not exist.</exception>
+ /// <exception cref="EntityDeletedException">Thrown when post is deleted.</exception>
+ /// <exception cref="EntityNotExistException">Thrown when data of that index does not exist.</exception>
+ Task<ICacheableDataDigest> GetPostDataDigestV2Async(long timelineId, long postId, long dataIndex);
+
+ /// <summary>
+ /// Get a data of a post.
+ /// </summary>
+ /// <param name="timelineId">The timeline id.</param>
+ /// <param name="postId">The post id.</param>
+ /// <param name="dataIndex">The index of the data.</param>
+ /// <returns>The data.</returns>
+ /// <exception cref="EntityNotExistException">Thrown when timeline does not exist.</exception>
+ /// <exception cref="EntityNotExistException">Thrown when post of <paramref name="postId"/> does not exist.</exception>
+ /// <exception cref="EntityDeletedException">Thrown when post is deleted.</exception>
+ /// <exception cref="EntityNotExistException">Thrown when data of that index does not exist.</exception>
+ Task<ByteData> GetPostDataV2Async(long timelineId, long postId, long dataIndex);
+
+ /// <summary>
/// Create a new post in timeline.
/// </summary>
/// <param name="timelineId">The id of the timeline to create post against.</param>
diff --git a/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs b/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs index 644e989f..e0212cb7 100644 --- a/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs +++ b/BackEnd/Timeline/Services/Timeline/TimelinePostService.cs @@ -434,5 +434,47 @@ namespace Timeline.Services.Timeline return post; } + + public async Task<ICacheableDataDigest> GetPostDataDigestV2Async(long timelineId, long postId, long dataIndex) + { + await _timelineService.ThrowIfTimelineNotExist(timelineId);
+
+ var postEntity = await _database.TimelinePosts.Where(p => p.TimelineId == timelineId && p.LocalId == postId).Select(p => new { p.Id, p.Deleted }).SingleOrDefaultAsync();
+
+ if (postEntity is null)
+ throw CreatePostNotExistException(timelineId, postId, false);
+
+ if (postEntity.Deleted)
+ throw CreatePostDeletedException(timelineId, postId);
+
+ var dataEntity = await _database.TimelinePostData.Where(d => d.PostId == postEntity.Id && d.Index == dataIndex).SingleOrDefaultAsync();
+
+ if (dataEntity is null)
+ throw CreatePostDataNotExistException(timelineId, postId, dataIndex);
+
+ return new CacheableDataDigest(dataEntity.DataTag, dataEntity.LastUpdated); + } + + public async Task<ByteData> GetPostDataV2Async(long timelineId, long postId, long dataIndex) + { + await _timelineService.ThrowIfTimelineNotExist(timelineId);
+
+ var postEntity = await _database.TimelinePosts.Where(p => p.TimelineId == timelineId && p.LocalId == postId).Select(p => new { p.Id, p.Deleted }).SingleOrDefaultAsync();
+
+ if (postEntity is null)
+ throw CreatePostNotExistException(timelineId, postId, false);
+
+ if (postEntity.Deleted)
+ throw CreatePostDeletedException(timelineId, postId);
+
+ var dataEntity = await _database.TimelinePostData.Where(d => d.PostId == postEntity.Id && d.Index == dataIndex).SingleOrDefaultAsync();
+
+ if (dataEntity is null)
+ throw CreatePostDataNotExistException(timelineId, postId, dataIndex);
+
+ var data = await _dataManager.GetEntryAndCheck(dataEntity.DataTag, $"Timeline {timelineId}, post {postId}, data {dataIndex} requires this data.");
+
+ return new ByteData(data, dataEntity.Kind); + } }
}
|