aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests2/TimelinePostTest3.cs9
-rw-r--r--BackEnd/Timeline/Controllers/TimelinePostV2Controller.cs6
-rw-r--r--BackEnd/Timeline/Services/Timeline/ITimelinePostService.cs26
-rw-r--r--BackEnd/Timeline/Services/Timeline/TimelinePostService.cs42
4 files changed, 81 insertions, 2 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests2/TimelinePostTest3.cs b/BackEnd/Timeline.Tests/IntegratedTests2/TimelinePostTest3.cs
index 5313a7c8..f760bd03 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests2/TimelinePostTest3.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests2/TimelinePostTest3.cs
@@ -70,6 +70,15 @@ namespace Timeline.Tests.IntegratedTests2
}
[Fact]
+ public async Task PostDataGetDeleted()
+ {
+ using var client = CreateClientAsUser();
+ await client.TestSendAsync(HttpMethod.Delete, "v2/timelines/user/hello/posts/1", expectedStatusCode: HttpStatusCode.NoContent);
+ await client.TestSendAsync(HttpMethod.Get, "v2/timelines/user/hello/posts/1/data", expectedStatusCode: HttpStatusCode.Gone);
+ await client.TestSendAsync(HttpMethod.Get, "v2/timelines/user/hello/posts/1/data/1", expectedStatusCode: HttpStatusCode.Gone);
+ }
+
+ [Fact]
public async Task PostDataGetNotExist()
{
using var client = CreateClientAsUser();
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);
+ }
}
}