From a672e10faad434899d81ef9d0d0d5adbbc7841da Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 30 Apr 2021 16:52:55 +0800 Subject: refactor: ... --- .../Services/Api/HighlightTimelineService.cs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'BackEnd/Timeline/Services/Api/HighlightTimelineService.cs') diff --git a/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs b/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs index a9d831ab..d4367e57 100644 --- a/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs +++ b/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs @@ -25,12 +25,11 @@ namespace Timeline.Services.Api public async Task AddHighlightTimelineAsync(long timelineId, long? operatorId) { - if (!await _timelineService.CheckTimelineExistenceAsync(timelineId)) - throw new TimelineNotExistException(timelineId); + await _timelineService.ThrowIfTimelineNotExist(timelineId); - if (operatorId.HasValue && !await _userService.CheckUserExistenceAsync(operatorId.Value)) + if (operatorId.HasValue) { - throw new UserNotExistException(null, operatorId.Value, "User with given operator id does not exist.", null); + await _userService.ThrowIfUserNotExist(operatorId.Value); } var alreadyIs = await _database.HighlightTimelines.AnyAsync(t => t.TimelineId == timelineId); @@ -51,12 +50,11 @@ namespace Timeline.Services.Api public async Task RemoveHighlightTimelineAsync(long timelineId, long? operatorId) { - if (!await _timelineService.CheckTimelineExistenceAsync(timelineId)) - throw new TimelineNotExistException(timelineId); + await _timelineService.ThrowIfTimelineNotExist(timelineId); - if (operatorId.HasValue && !await _userService.CheckUserExistenceAsync(operatorId.Value)) + if (operatorId.HasValue) { - throw new UserNotExistException(null, operatorId.Value, "User with given operator id does not exist.", null); + await _userService.ThrowIfUserNotExist(operatorId.Value); } var entity = await _database.HighlightTimelines.SingleOrDefaultAsync(t => t.TimelineId == timelineId); @@ -79,8 +77,7 @@ namespace Timeline.Services.Api public async Task MoveHighlightTimelineAsync(long timelineId, long newPosition) { - if (!await _timelineService.CheckTimelineExistenceAsync(timelineId)) - throw new TimelineNotExistException(timelineId); + await _timelineService.ThrowIfTimelineNotExist(timelineId); var entity = await _database.HighlightTimelines.SingleOrDefaultAsync(t => t.TimelineId == timelineId); @@ -118,8 +115,8 @@ namespace Timeline.Services.Api public async Task IsHighlightTimelineAsync(long timelineId, bool checkTimelineExistence = true) { - if (checkTimelineExistence && !await _timelineService.CheckTimelineExistenceAsync(timelineId)) - throw new TimelineNotExistException(timelineId); + if (checkTimelineExistence) + await _timelineService.ThrowIfTimelineNotExist(timelineId); return await _database.HighlightTimelines.AnyAsync(t => t.TimelineId == timelineId); } -- cgit v1.2.3