diff options
Diffstat (limited to 'BackEnd/Timeline')
3 files changed, 72 insertions, 2 deletions
diff --git a/BackEnd/Timeline/Controllers/TimelinePostV2Controller.cs b/BackEnd/Timeline/Controllers/TimelinePostV2Controller.cs index 3a694e31..6e4b265f 100644 --- a/BackEnd/Timeline/Controllers/TimelinePostV2Controller.cs +++ b/BackEnd/Timeline/Controllers/TimelinePostV2Controller.cs @@ -80,6 +80,7 @@ namespace Timeline.Controllers [ProducesResponseType(typeof(void), StatusCodes.Status304NotModified)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status410Gone)] [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] public async Task<ActionResult<ByteData>> DataIndexGetAsync([FromRoute][Username] string owner, [FromRoute][TimelineName] string timeline, [FromRoute] long post) { @@ -92,6 +93,7 @@ namespace Timeline.Controllers [ProducesResponseType(typeof(void), StatusCodes.Status304NotModified)] [ProducesResponseType(StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status410Gone)] [ProducesResponseType(StatusCodes.Status422UnprocessableEntity)] public async Task<ActionResult> DataGetAsync([FromRoute][Username] string owner, [FromRoute][TimelineName] string timeline, [FromRoute] long post, [FromRoute(Name = "data_index")][Range(0, 100)] long dataIndex) { @@ -103,10 +105,10 @@ namespace Timeline.Controllers } return await DataCacheHelper.GenerateActionResult(this, - () => _postService.GetPostDataDigestAsync(timelineId, post, dataIndex), + () => _postService.GetPostDataDigestV2Async(timelineId, post, dataIndex), async () => { - var data = await _postService.GetPostDataAsync(timelineId, post, dataIndex); + var data = await _postService.GetPostDataV2Async(timelineId, post, dataIndex); if (data.ContentType == MimeTypes.TextMarkdown) { return new ByteData(_markdownProcessor.Process(data.Data, Url, timeline, post), data.ContentType); 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); + } }
}
|