From a672e10faad434899d81ef9d0d0d5adbbc7841da Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 30 Apr 2021 16:52:55 +0800 Subject: refactor: ... --- .../Services/Api/BookmarkTimelineService.cs | 32 ++++++++-------------- 1 file changed, 11 insertions(+), 21 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 4fc20ecb..de70a9db 100644 --- a/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs +++ b/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs @@ -24,11 +24,8 @@ namespace Timeline.Services.Api public async Task AddBookmarkAsync(long userId, long timelineId) { - if (!await _userService.CheckUserExistenceAsync(userId)) - throw new UserNotExistException(userId); - - if (!await _timelineService.CheckTimelineExistenceAsync(timelineId)) - throw new TimelineNotExistException(timelineId); + await _userService.ThrowIfUserNotExist(userId); + await _timelineService.ThrowIfTimelineNotExist(timelineId); if (await _database.BookmarkTimelines.AnyAsync(t => t.TimelineId == timelineId && t.UserId == userId)) return false; @@ -46,8 +43,7 @@ namespace Timeline.Services.Api public async Task> GetBookmarksAsync(long userId) { - if (!await _userService.CheckUserExistenceAsync(userId)) - throw new UserNotExistException(userId); + await _userService.ThrowIfUserNotExist(userId); var entities = await _database.BookmarkTimelines.Where(t => t.UserId == userId).OrderBy(t => t.Rank).Select(t => new { t.TimelineId }).ToListAsync(); @@ -56,22 +52,19 @@ namespace Timeline.Services.Api public async Task IsBookmarkAsync(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true) { - if (checkUserExistence && !await _userService.CheckUserExistenceAsync(userId)) - throw new UserNotExistException(userId); + if (checkUserExistence) + await _userService.ThrowIfUserNotExist(userId); - if (checkTimelineExistence && !await _timelineService.CheckTimelineExistenceAsync(timelineId)) - throw new TimelineNotExistException(timelineId); + if (checkTimelineExistence) + await _timelineService.ThrowIfTimelineNotExist(timelineId); return await _database.BookmarkTimelines.AnyAsync(b => b.TimelineId == timelineId && b.UserId == userId); } public async Task MoveBookmarkAsync(long userId, long timelineId, long newPosition) { - if (!await _userService.CheckUserExistenceAsync(userId)) - throw new UserNotExistException(userId); - - if (!await _timelineService.CheckTimelineExistenceAsync(timelineId)) - throw new TimelineNotExistException(timelineId); + await _userService.ThrowIfUserNotExist(userId); + await _timelineService.ThrowIfTimelineNotExist(timelineId); var entity = await _database.BookmarkTimelines.SingleOrDefaultAsync(t => t.TimelineId == timelineId && t.UserId == userId); @@ -109,11 +102,8 @@ namespace Timeline.Services.Api public async Task RemoveBookmarkAsync(long userId, long timelineId) { - if (!await _userService.CheckUserExistenceAsync(userId)) - throw new UserNotExistException(userId); - - if (!await _timelineService.CheckTimelineExistenceAsync(timelineId)) - throw new TimelineNotExistException(timelineId); + await _userService.ThrowIfUserNotExist(userId); + await _timelineService.ThrowIfTimelineNotExist(timelineId); var entity = await _database.BookmarkTimelines.SingleOrDefaultAsync(t => t.UserId == userId && t.TimelineId == timelineId); -- cgit v1.2.3