aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Services/Api
diff options
context:
space:
mode:
Diffstat (limited to 'BackEnd/Timeline/Services/Api')
-rw-r--r--BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs32
-rw-r--r--BackEnd/Timeline/Services/Api/HighlightTimelineService.cs21
-rw-r--r--BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs18
-rw-r--r--BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs12
4 files changed, 35 insertions, 48 deletions
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<bool> 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<List<long>> 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<bool> 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<bool> 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);
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<bool> 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<bool> 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<bool> 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);
}
diff --git a/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs b/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs
index 18feee54..63b4affa 100644
--- a/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs
+++ b/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs
@@ -15,7 +15,7 @@ namespace Timeline.Services.Api
/// </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>
+ /// <exception cref="EntityNotExistException">Thrown when user does not exist.</exception>
Task<List<long>> GetBookmarksAsync(long userId);
/// <summary>
@@ -26,8 +26,8 @@ namespace Timeline.Services.Api
/// <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>
+ /// <exception cref="EntityNotExistException">Throw if user does not exist and <paramref name="checkUserExistence"/> is true.</exception>
+ /// <exception cref="EntityNotExistException">Thrown if timeline does not exist and <paramref name="checkTimelineExistence"/> is true.</exception>
Task<bool> IsBookmarkAsync(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true);
/// <summary>
@@ -36,8 +36,8 @@ namespace Timeline.Services.Api
/// <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>
+ /// <exception cref="EntityNotExistException">Thrown when user does not exist.</exception>
+ /// <exception cref="EntityNotExistException">Thrown when timeline does not exist.</exception>
Task<bool> AddBookmarkAsync(long userId, long timelineId);
/// <summary>
@@ -46,8 +46,8 @@ namespace Timeline.Services.Api
/// <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>
+ /// <exception cref="EntityNotExistException">Thrown when user does not exist.</exception>
+ /// <exception cref="EntityNotExistException">Thrown when timeline does not exist.</exception>
Task<bool> RemoveBookmarkAsync(long userId, long timelineId);
/// <summary>
@@ -56,8 +56,8 @@ namespace Timeline.Services.Api
/// <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="EntityNotExistException">Thrown when user does not exist.</exception>
+ /// <exception cref="EntityNotExistException">Thrown when timeline does not exist.</exception>
/// <exception cref="InvalidBookmarkException">Thrown when the timeline is not a bookmark.</exception>
Task MoveBookmarkAsync(long userId, long timelineId, long newPosition);
}
diff --git a/BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs b/BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs
index 4f14d19b..2e488778 100644
--- a/BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs
+++ b/BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs
@@ -22,7 +22,7 @@ namespace Timeline.Services.Api
/// <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>
+ /// <exception cref="EntityNotExistException">Thrown when timeline does not exist and <paramref name="checkTimelineExistence"/> is true.</exception>
Task<bool> IsHighlightTimelineAsync(long timelineId, bool checkTimelineExistence = true);
/// <summary>
@@ -31,8 +31,8 @@ namespace Timeline.Services.Api
/// <param name="timelineId">The timeline id.</param>
/// <param name="operatorId">The user id of operator.</param>
/// <returns>True if timeline is actually added to highligh. False if it already is.</returns>
- /// <exception cref="TimelineNotExistException">Thrown when timeline with given id does not exist.</exception>
- /// <exception cref="UserNotExistException">Thrown when user with given operator id does not exist.</exception>
+ /// <exception cref="EntityNotExistException">Thrown when timeline with given id does not exist.</exception>
+ /// <exception cref="EntityNotExistException">Thrown when user with given operator id does not exist.</exception>
Task<bool> AddHighlightTimelineAsync(long timelineId, long? operatorId);
/// <summary>
@@ -41,8 +41,8 @@ namespace Timeline.Services.Api
/// <param name="timelineId">The timeline id.</param>
/// <param name="operatorId">The user id of operator.</param>
/// <returns>True if deletion is actually performed. Otherwise false (timeline was not in the list).</returns>
- /// <exception cref="TimelineNotExistException">Thrown when timeline with given id does not exist.</exception>
- /// <exception cref="UserNotExistException">Thrown when user with given operator id does not exist.</exception>
+ /// <exception cref="EntityNotExistException">Thrown when timeline with given id does not exist.</exception>
+ /// <exception cref="EntityNotExistException">Thrown when user with given operator id does not exist.</exception>
Task<bool> RemoveHighlightTimelineAsync(long timelineId, long? operatorId);
/// <summary>
@@ -50,7 +50,7 @@ namespace Timeline.Services.Api
/// </summary>
/// <param name="timelineId">The timeline name.</param>
/// <param name="newPosition">The new position. Starts at 1.</param>
- /// <exception cref="TimelineNotExistException">Thrown when timeline with given id does not exist.</exception>
+ /// <exception cref="EntityNotExistException">Thrown when timeline with given id does not exist.</exception>
/// <exception cref="InvalidHighlightTimelineException">Thrown when given timeline is not a highlight timeline.</exception>
/// <remarks>
/// If <paramref name="newPosition"/> is smaller than 1. Then move the timeline to head.