From 86160e4a5697615452a7e06dc78f8be4c8b2515f Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 9 Apr 2022 19:30:39 +0800 Subject: ... --- .../Services/Timeline/ITimelinePostService.cs | 26 ++++++++++++++ .../Services/Timeline/TimelinePostService.cs | 42 ++++++++++++++++++++++ 2 files changed, 68 insertions(+) (limited to 'BackEnd/Timeline/Services') 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 @@ -78,6 +78,32 @@ namespace Timeline.Services.Timeline /// Thrown when post is deleted. Task GetPostV2Async(long timelineId, long postId); + /// + /// Get a data digest of a post. + /// + /// The timeline id. + /// The post id. + /// The index of the data. + /// The data digest. + /// Thrown when timeline does not exist. + /// Thrown when post of does not exist. + /// Thrown when post is deleted. + /// Thrown when data of that index does not exist. + Task GetPostDataDigestV2Async(long timelineId, long postId, long dataIndex); + + /// + /// Get a data of a post. + /// + /// The timeline id. + /// The post id. + /// The index of the data. + /// The data. + /// Thrown when timeline does not exist. + /// Thrown when post of does not exist. + /// Thrown when post is deleted. + /// Thrown when data of that index does not exist. + Task GetPostDataV2Async(long timelineId, long postId, long dataIndex); + /// /// Create a new post in timeline. /// 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 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 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); + } } } -- cgit v1.2.3