diff options
author | crupest <crupest@outlook.com> | 2021-04-29 19:29:35 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-04-29 19:29:35 +0800 |
commit | b87abbb8ed0aa86a808b2f97e4d22b0ee1addd9f (patch) | |
tree | bf8c16169dce15e78fd41c00a364b028771433e5 /BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs | |
parent | b4c08ef8e7eb7d3f7d8a37d04fd478326cb75d2c (diff) | |
download | timeline-b87abbb8ed0aa86a808b2f97e4d22b0ee1addd9f.tar.gz timeline-b87abbb8ed0aa86a808b2f97e4d22b0ee1addd9f.tar.bz2 timeline-b87abbb8ed0aa86a808b2f97e4d22b0ee1addd9f.zip |
...
Diffstat (limited to 'BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs')
-rw-r--r-- | BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs | 79 |
1 files changed, 5 insertions, 74 deletions
diff --git a/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs b/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs index 37b55199..4fc20ecb 100644 --- a/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs +++ b/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore;
-using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -10,74 +9,6 @@ using Timeline.Services.User; namespace Timeline.Services.Api
{
- [Serializable]
- public class InvalidBookmarkException : Exception
- {
- public InvalidBookmarkException() { }
- public InvalidBookmarkException(string message) : base(message) { }
- public InvalidBookmarkException(string message, Exception inner) : base(message, inner) { }
- protected InvalidBookmarkException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
- }
-
- /// <summary>
- /// Service interface that manages timeline bookmarks.
- /// </summary>
- public interface IBookmarkTimelineService
- {
- /// <summary>
- /// Get bookmarks of a user.
- /// </summary>
- /// <param name="userId">User id of bookmark owner.</param>
- /// <returns>Id of Bookmark timelines in order.</returns>
- /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
- 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>
- /// <param name="timelineId">Timeline id.</param>
- /// <returns>True if timeline is added to bookmark. False if it already is.</returns>
- /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
- /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
- Task<bool> AddBookmark(long userId, long timelineId);
-
- /// <summary>
- /// Remove a bookmark from a user.
- /// </summary>
- /// <param name="userId">User id of bookmark owner.</param>
- /// <param name="timelineId">Timeline id.</param>
- /// <returns>True if deletion is performed. False if bookmark does not exist.</returns>
- /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
- /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
- Task<bool> RemoveBookmark(long userId, long timelineId);
-
- /// <summary>
- /// Move bookmark to a new position.
- /// </summary>
- /// <param name="userId">User id of bookmark owner.</param>
- /// <param name="timelineId">Timeline name.</param>
- /// <param name="newPosition">New position. Starts at 1.</param>
- /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
- /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
- /// <exception cref="InvalidBookmarkException">Thrown when the timeline is not a bookmark.</exception>
- Task MoveBookmark(long userId, long timelineId, long newPosition);
- }
-
public class BookmarkTimelineService : IBookmarkTimelineService
{
private readonly DatabaseContext _database;
@@ -91,7 +22,7 @@ namespace Timeline.Services.Api _timelineService = timelineService;
}
- public async Task<bool> AddBookmark(long userId, long timelineId)
+ public async Task<bool> AddBookmarkAsync(long userId, long timelineId)
{
if (!await _userService.CheckUserExistenceAsync(userId))
throw new UserNotExistException(userId);
@@ -113,7 +44,7 @@ namespace Timeline.Services.Api return true;
}
- public async Task<List<long>> GetBookmarks(long userId)
+ public async Task<List<long>> GetBookmarksAsync(long userId)
{
if (!await _userService.CheckUserExistenceAsync(userId))
throw new UserNotExistException(userId);
@@ -123,7 +54,7 @@ namespace Timeline.Services.Api return entities.Select(e => e.TimelineId).ToList();
}
- public async Task<bool> IsBookmark(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true)
+ public async Task<bool> IsBookmarkAsync(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true)
{
if (checkUserExistence && !await _userService.CheckUserExistenceAsync(userId))
throw new UserNotExistException(userId);
@@ -134,7 +65,7 @@ namespace Timeline.Services.Api return await _database.BookmarkTimelines.AnyAsync(b => b.TimelineId == timelineId && b.UserId == userId);
}
- public async Task MoveBookmark(long userId, long timelineId, long newPosition)
+ public async Task MoveBookmarkAsync(long userId, long timelineId, long newPosition)
{
if (!await _userService.CheckUserExistenceAsync(userId))
throw new UserNotExistException(userId);
@@ -176,7 +107,7 @@ namespace Timeline.Services.Api await transaction.CommitAsync();
}
- public async Task<bool> RemoveBookmark(long userId, long timelineId)
+ public async Task<bool> RemoveBookmarkAsync(long userId, long timelineId)
{
if (!await _userService.CheckUserExistenceAsync(userId))
throw new UserNotExistException(userId);
|