aboutsummaryrefslogtreecommitdiff
path: root/BackEnd
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-01-07 20:48:47 +0800
committercrupest <crupest@outlook.com>2021-01-07 20:48:47 +0800
commit1a44a615ad79054218d493f8bc4bf8563201002b (patch)
tree26a0bf762190b75cb1cb2570a4e2870594063898 /BackEnd
parente701f8bab033dd364673215e66d58a1cb9fea339 (diff)
downloadtimeline-1a44a615ad79054218d493f8bc4bf8563201002b.tar.gz
timeline-1a44a615ad79054218d493f8bc4bf8563201002b.tar.bz2
timeline-1a44a615ad79054218d493f8bc4bf8563201002b.zip
feat: Add check existence feature to bookmark and highlight service.
Diffstat (limited to 'BackEnd')
-rw-r--r--BackEnd/Timeline/Services/BookmarkTimelineService.cs23
-rw-r--r--BackEnd/Timeline/Services/HighlightTimelineService.cs17
2 files changed, 40 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))
diff --git a/BackEnd/Timeline/Services/HighlightTimelineService.cs b/BackEnd/Timeline/Services/HighlightTimelineService.cs
index bf0aac91..557478c7 100644
--- a/BackEnd/Timeline/Services/HighlightTimelineService.cs
+++ b/BackEnd/Timeline/Services/HighlightTimelineService.cs
@@ -32,6 +32,15 @@ namespace Timeline.Services
Task<List<long>> GetHighlightTimelines();
/// <summary>
+ /// Check if a timeline is highlight timeline.
+ /// </summary>
+ /// <param name="timelineId">Timeline id.</param>
+ /// <param name="checkTimelineExistence">If true it will throw if timeline does not exist.</param>
+ /// <returns>True if timeline is highlight. Otherwise false.</returns>
+ /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist and <paramref name="checkTimelineExistence"/> is true.</exception>
+ Task<bool> IsHighlightTimeline(long timelineId, bool checkTimelineExistence = true);
+
+ /// <summary>
/// Add a timeline to highlight list.
/// </summary>
/// <param name="timelineId">The timeline id.</param>
@@ -172,5 +181,13 @@ namespace Timeline.Services
await transaction.CommitAsync();
}
+
+ public async Task<bool> IsHighlightTimeline(long timelineId, bool checkTimelineExistence = true)
+ {
+ if (checkTimelineExistence && !await _timelineService.CheckExistence(timelineId))
+ throw new TimelineNotExistException(timelineId);
+
+ return await _database.HighlightTimelines.AnyAsync(t => t.TimelineId == timelineId);
+ }
}
}