From b87abbb8ed0aa86a808b2f97e4d22b0ee1addd9f Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 29 Apr 2021 19:29:35 +0800 Subject: ... --- .../Services/Api/BookmarkTimelineService.cs | 79 ++-------------------- 1 file changed, 5 insertions(+), 74 deletions(-) (limited to 'BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs') 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) { } - } - - /// - /// Service interface that manages timeline bookmarks. - /// - public interface IBookmarkTimelineService - { - /// - /// Get bookmarks of a user. - /// - /// User id of bookmark owner. - /// Id of Bookmark timelines in order. - /// 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. - /// - /// User id of bookmark owner. - /// Timeline id. - /// True if timeline is added to bookmark. False if it already is. - /// Thrown when user does not exist. - /// Thrown when timeline does not exist. - Task AddBookmark(long userId, long timelineId); - - /// - /// Remove a bookmark from a user. - /// - /// User id of bookmark owner. - /// Timeline id. - /// True if deletion is performed. False if bookmark does not exist. - /// Thrown when user does not exist. - /// Thrown when timeline does not exist. - Task RemoveBookmark(long userId, long timelineId); - - /// - /// Move bookmark to a new position. - /// - /// User id of bookmark owner. - /// Timeline name. - /// New position. Starts at 1. - /// Thrown when user does not exist. - /// Thrown when timeline does not exist. - /// Thrown when the timeline is not a bookmark. - 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 AddBookmark(long userId, long timelineId) + public async Task 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> GetBookmarks(long userId) + public async Task> 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 IsBookmark(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true) + public async Task 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 RemoveBookmark(long userId, long timelineId) + public async Task RemoveBookmarkAsync(long userId, long timelineId) { if (!await _userService.CheckUserExistenceAsync(userId)) throw new UserNotExistException(userId); -- cgit v1.2.3