aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Services/BookmarkTimelineService.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-01-07 22:13:24 +0800
committerGitHub <noreply@github.com>2021-01-07 22:13:24 +0800
commit05132389cd2db33ab3bdeaa2fbfae25fc8db8882 (patch)
treedaaa39d8d1d72b10caaa92cb65ba1635237ef2dc /BackEnd/Timeline/Services/BookmarkTimelineService.cs
parent191b92a161c4fdad532dbf471f5c33f8f4a97a23 (diff)
parent0bb2cc098506963ebf9ee06ec94b43c8d388543c (diff)
downloadtimeline-05132389cd2db33ab3bdeaa2fbfae25fc8db8882.tar.gz
timeline-05132389cd2db33ab3bdeaa2fbfae25fc8db8882.tar.bz2
timeline-05132389cd2db33ab3bdeaa2fbfae25fc8db8882.zip
Merge pull request #204 from crupest/back-dev
Timeline info includes highlight and bookmark info.
Diffstat (limited to 'BackEnd/Timeline/Services/BookmarkTimelineService.cs')
-rw-r--r--BackEnd/Timeline/Services/BookmarkTimelineService.cs23
1 files changed, 23 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Services/BookmarkTimelineService.cs b/BackEnd/Timeline/Services/BookmarkTimelineService.cs
index 4c8bfdae..4930686e 100644
--- a/BackEnd/Timeline/Services/BookmarkTimelineService.cs
+++ b/BackEnd/Timeline/Services/BookmarkTimelineService.cs
@@ -34,6 +34,18 @@ namespace Timeline.Services
Task<List<long>> GetBookmarks(long userId);
/// <summary>
+ /// Check if a timeline is a bookmark.
+ /// </summary>
+ /// <param name="userId">The user id.</param>
+ /// <param name="timelineId">Timeline id.</param>
+ /// <param name="checkUserExistence">If true it will throw when user does not exist.</param>
+ /// <param name="checkTimelineExistence">If true it will throw when timeline does not exist.</param>
+ /// <returns>True if timeline is a bookmark. Otherwise false.</returns>
+ /// <exception cref="UserNotExistException">Throw if user does not exist and <paramref name="checkUserExistence"/> is true.</exception>
+ /// <exception cref="TimelineNotExistException">Thrown if timeline does not exist and <paramref name="checkTimelineExistence"/> is true.</exception>
+ Task<bool> IsBookmark(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true);
+
+ /// <summary>
/// Add a bookmark to tail to a user.
/// </summary>
/// <param name="userId">User id of bookmark owner.</param>
@@ -110,6 +122,17 @@ namespace Timeline.Services
return entities.Select(e => e.TimelineId).ToList();
}
+ public async Task<bool> IsBookmark(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true)
+ {
+ if (checkUserExistence && !await _userService.CheckUserExistence(userId))
+ throw new UserNotExistException(userId);
+
+ if (checkTimelineExistence && !await _timelineService.CheckExistence(timelineId))
+ throw new TimelineNotExistException(timelineId);
+
+ return await _database.BookmarkTimelines.AnyAsync(b => b.TimelineId == timelineId && b.UserId == userId);
+ }
+
public async Task MoveBookmark(long userId, long timelineId, long newPosition)
{
if (!await _userService.CheckUserExistence(userId))