From b87abbb8ed0aa86a808b2f97e4d22b0ee1addd9f Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 29 Apr 2021 19:29:35 +0800 Subject: ... --- .../Services/Api/HighlightTimelineService.cs | 77 ++-------------------- 1 file changed, 5 insertions(+), 72 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 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) { } - } - - /// - /// Service that controls highlight timeline. - /// - public interface IHighlightTimelineService - { - /// - /// Get all highlight timelines in order. - /// - /// Id list of all highlight timelines. - Task> GetHighlightTimelines(); - - /// - /// Check if a timeline is highlight timeline. - /// - /// Timeline id. - /// If true it will throw if timeline does not exist. - /// True if timeline is highlight. Otherwise false. - /// Thrown when timeline does not exist and is true. - Task IsHighlightTimeline(long timelineId, bool checkTimelineExistence = true); - - /// - /// Add a timeline to highlight list. - /// - /// The timeline id. - /// The user id of operator. - /// True if timeline is actually added to highligh. False if it already is. - /// Thrown when timeline with given id does not exist. - /// Thrown when user with given operator id does not exist. - Task AddHighlightTimeline(long timelineId, long? operatorId); - - /// - /// Remove a timeline from highlight list. - /// - /// The timeline id. - /// The user id of operator. - /// True if deletion is actually performed. Otherwise false (timeline was not in the list). - /// Thrown when timeline with given id does not exist. - /// Thrown when user with given operator id does not exist. - Task RemoveHighlightTimeline(long timelineId, long? operatorId); - - /// - /// Move a highlight timeline to a new position. - /// - /// The timeline name. - /// The new position. Starts at 1. - /// Thrown when timeline with given id does not exist. - /// Thrown when given timeline is not a highlight timeline. - /// - /// If is smaller than 1. Then move the timeline to head. - /// If is bigger than total count. Then move the timeline to tail. - /// - 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 AddHighlightTimeline(long timelineId, long? operatorId) + public async Task 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> GetHighlightTimelines() + public async Task> 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 RemoveHighlightTimeline(long timelineId, long? operatorId) + public async Task 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 IsHighlightTimeline(long timelineId, bool checkTimelineExistence = true) + public async Task IsHighlightTimelineAsync(long timelineId, bool checkTimelineExistence = true) { if (checkTimelineExistence && !await _timelineService.CheckTimelineExistenceAsync(timelineId)) throw new TimelineNotExistException(timelineId); -- cgit v1.2.3