From 1a44a615ad79054218d493f8bc4bf8563201002b Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 7 Jan 2021 20:48:47 +0800 Subject: feat: Add check existence feature to bookmark and highlight service. --- .../Timeline/Services/BookmarkTimelineService.cs | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'BackEnd/Timeline/Services/BookmarkTimelineService.cs') 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 @@ -33,6 +33,18 @@ namespace Timeline.Services /// Thrown when user does not exist. Task> GetBookmarks(long userId); + /// + /// Check if a timeline is a bookmark. + /// + /// The user id. + /// Timeline id. + /// If true it will throw when user does not exist. + /// If true it will throw when timeline does not exist. + /// True if timeline is a bookmark. Otherwise false. + /// Throw if user does not exist and is true. + /// Thrown if timeline does not exist and is true. + Task IsBookmark(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true); + /// /// Add a bookmark to tail to a user. /// @@ -110,6 +122,17 @@ namespace Timeline.Services return entities.Select(e => e.TimelineId).ToList(); } + public async Task 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)) -- cgit v1.2.3