diff options
Diffstat (limited to 'BackEnd/Timeline/Services/Api/HighlightTimelineService.cs')
-rw-r--r-- | BackEnd/Timeline/Services/Api/HighlightTimelineService.cs | 77 |
1 files changed, 5 insertions, 72 deletions
diff --git a/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs b/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs index 8224f1fe..a9d831ab 100644 --- a/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs +++ b/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore;
-using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
@@ -9,72 +8,6 @@ using Timeline.Services.User; namespace Timeline.Services.Api
{
-
- [Serializable]
- public class InvalidHighlightTimelineException : Exception
- {
- public InvalidHighlightTimelineException() { }
- public InvalidHighlightTimelineException(string message) : base(message) { }
- public InvalidHighlightTimelineException(string message, Exception inner) : base(message, inner) { }
- protected InvalidHighlightTimelineException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
- }
-
- /// <summary>
- /// Service that controls highlight timeline.
- /// </summary>
- public interface IHighlightTimelineService
- {
- /// <summary>
- /// Get all highlight timelines in order.
- /// </summary>
- /// <returns>Id list of all highlight timelines.</returns>
- Task<List<long>> GetHighlightTimelines();
-
- /// <summary>
- /// Check if a timeline is highlight timeline.
- /// </summary>
- /// <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>
- Task<bool> IsHighlightTimeline(long timelineId, bool checkTimelineExistence = true);
-
- /// <summary>
- /// Add a timeline to highlight list.
- /// </summary>
- /// <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>
- Task<bool> AddHighlightTimeline(long timelineId, long? operatorId);
-
- /// <summary>
- /// Remove a timeline from highlight list.
- /// </summary>
- /// <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>
- Task<bool> RemoveHighlightTimeline(long timelineId, long? operatorId);
-
- /// <summary>
- /// Move a highlight timeline to a new position.
- /// </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="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.
- /// If <paramref name="newPosition"/> is bigger than total count. Then move the timeline to tail.
- /// </remarks>
- Task MoveHighlightTimeline(long timelineId, long newPosition);
- }
-
public class HighlightTimelineService : IHighlightTimelineService
{
private readonly DatabaseContext _database;
@@ -90,7 +23,7 @@ namespace Timeline.Services.Api _clock = clock;
}
- public async Task<bool> AddHighlightTimeline(long timelineId, long? operatorId)
+ public async Task<bool> AddHighlightTimelineAsync(long timelineId, long? operatorId)
{
if (!await _timelineService.CheckTimelineExistenceAsync(timelineId))
throw new TimelineNotExistException(timelineId);
@@ -109,14 +42,14 @@ namespace Timeline.Services.Api return true;
}
- public async Task<List<long>> GetHighlightTimelines()
+ public async Task<List<long>> GetHighlightTimelinesAsync()
{
var entities = await _database.HighlightTimelines.OrderBy(t => t.Order).Select(t => new { t.TimelineId }).ToListAsync();
return entities.Select(e => e.TimelineId).ToList();
}
- public async Task<bool> RemoveHighlightTimeline(long timelineId, long? operatorId)
+ public async Task<bool> RemoveHighlightTimelineAsync(long timelineId, long? operatorId)
{
if (!await _timelineService.CheckTimelineExistenceAsync(timelineId))
throw new TimelineNotExistException(timelineId);
@@ -144,7 +77,7 @@ namespace Timeline.Services.Api return true;
}
- public async Task MoveHighlightTimeline(long timelineId, long newPosition)
+ public async Task MoveHighlightTimelineAsync(long timelineId, long newPosition)
{
if (!await _timelineService.CheckTimelineExistenceAsync(timelineId))
throw new TimelineNotExistException(timelineId);
@@ -183,7 +116,7 @@ namespace Timeline.Services.Api await transaction.CommitAsync();
}
- public async Task<bool> IsHighlightTimeline(long timelineId, bool checkTimelineExistence = true)
+ public async Task<bool> IsHighlightTimelineAsync(long timelineId, bool checkTimelineExistence = true)
{
if (checkTimelineExistence && !await _timelineService.CheckTimelineExistenceAsync(timelineId))
throw new TimelineNotExistException(timelineId);
|