diff options
author | crupest <crupest@outlook.com> | 2021-05-05 16:18:33 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-05-05 16:18:33 +0800 |
commit | e110f4a41bd711192af28874f71f031a130f0b84 (patch) | |
tree | 08610c5476549edfbe8e9a2605b8876e026d89f5 /BackEnd/Timeline/Services | |
parent | 2a4b59c05236028ed1dc8304327b1ef484a376db (diff) | |
download | timeline-e110f4a41bd711192af28874f71f031a130f0b84.tar.gz timeline-e110f4a41bd711192af28874f71f031a130f0b84.tar.bz2 timeline-e110f4a41bd711192af28874f71f031a130f0b84.zip |
refactor: ...
Diffstat (limited to 'BackEnd/Timeline/Services')
10 files changed, 18 insertions, 37 deletions
diff --git a/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs b/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs index de70a9db..9d6ec93f 100644 --- a/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs +++ b/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs @@ -68,7 +68,10 @@ namespace Timeline.Services.Api var entity = await _database.BookmarkTimelines.SingleOrDefaultAsync(t => t.TimelineId == timelineId && t.UserId == userId);
- if (entity == null) throw new InvalidBookmarkException("You can't move a non-bookmark timeline.");
+ if (entity is null)
+ {
+ throw new EntityNotExistException(EntityTypes.BookmarkTimeline);
+ }
var oldPosition = entity.Rank;
diff --git a/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs b/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs index d4367e57..eb606ae6 100644 --- a/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs +++ b/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs @@ -81,7 +81,10 @@ namespace Timeline.Services.Api var entity = await _database.HighlightTimelines.SingleOrDefaultAsync(t => t.TimelineId == timelineId);
- if (entity == null) throw new InvalidHighlightTimelineException("You can't move a non-highlight timeline.");
+ if (entity is null)
+ {
+ throw new EntityNotExistException(EntityTypes.HighlightTimeline);
+ }
var oldPosition = entity.Order;
diff --git a/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs b/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs index c3cda450..468a885b 100644 --- a/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs +++ b/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs @@ -56,7 +56,7 @@ namespace Timeline.Services.Api /// <param name="newPosition">New position. Starts at 1.</param>
/// <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>
+ /// <exception cref="EntityNotExistException">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 56a0fb35..0ca6759c 100644 --- a/BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs +++ b/BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs @@ -49,7 +49,7 @@ namespace Timeline.Services.Api /// <param name="timelineId">The timeline name.</param>
/// <param name="newPosition">The new position. Starts at 1.</param>
/// <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>
+ /// <exception cref="EntityNotExistException">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.
diff --git a/BackEnd/Timeline/Services/Api/InvalidBookmarkException.cs b/BackEnd/Timeline/Services/Api/InvalidBookmarkException.cs deleted file mode 100644 index 39572b38..00000000 --- a/BackEnd/Timeline/Services/Api/InvalidBookmarkException.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System;
-
-namespace Timeline.Services.Api
-{
- [Serializable]
- public class InvalidBookmarkException : Exception
- {
- public InvalidBookmarkException() { }
- public InvalidBookmarkException(string message) : base(message) { }
- public InvalidBookmarkException(string message, Exception inner) : base(message, inner) { }
- protected InvalidBookmarkException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
- }
-}
diff --git a/BackEnd/Timeline/Services/Api/InvalidHighlightTimelineException.cs b/BackEnd/Timeline/Services/Api/InvalidHighlightTimelineException.cs deleted file mode 100644 index 13b04a6b..00000000 --- a/BackEnd/Timeline/Services/Api/InvalidHighlightTimelineException.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System;
-
-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) { }
- }
-}
diff --git a/BackEnd/Timeline/Services/EntityException.cs b/BackEnd/Timeline/Services/EntityException.cs index 7a302e5a..c4c2d700 100644 --- a/BackEnd/Timeline/Services/EntityException.cs +++ b/BackEnd/Timeline/Services/EntityException.cs @@ -10,11 +10,12 @@ namespace Timeline.Services public EntityException() { }
public EntityException(string? message) : base(message) { }
public EntityException(string? message, Exception? inner) : base(message, inner) { }
- public EntityException(EntityType entityType, IDictionary<string, object> constraints, string? message = null, Exception? inner = null)
+ public EntityException(EntityType entityType, IDictionary<string, object>? constraints = null, string? message = null, Exception? inner = null)
: base(message, inner)
{
EntityType = entityType;
- Constraints = constraints;
+ if (constraints is not null)
+ Constraints = constraints;
}
protected EntityException(
System.Runtime.Serialization.SerializationInfo info,
diff --git a/BackEnd/Timeline/Services/EntityNames.cs b/BackEnd/Timeline/Services/EntityNames.cs index 5df5e615..b1023624 100644 --- a/BackEnd/Timeline/Services/EntityNames.cs +++ b/BackEnd/Timeline/Services/EntityNames.cs @@ -7,5 +7,7 @@ public const string Timeline = "Timeline";
public const string TimelinePost = "TimelinePost";
public const string TimelinePostData = "TimelinePostData";
+ public const string BookmarkTimeline = "BookmarkTimeline";
+ public const string HighlightTimeline = "HighlightTimeline";
}
}
diff --git a/BackEnd/Timeline/Services/EntityNotExistException.cs b/BackEnd/Timeline/Services/EntityNotExistException.cs index 0c836fc4..6ae8442d 100644 --- a/BackEnd/Timeline/Services/EntityNotExistException.cs +++ b/BackEnd/Timeline/Services/EntityNotExistException.cs @@ -15,7 +15,7 @@ namespace Timeline.Services public EntityNotExistException() : base() { }
public EntityNotExistException(string? message) : base(message) { }
public EntityNotExistException(string? message, Exception? inner) : base(message, inner) { }
- public EntityNotExistException(EntityType entityType, IDictionary<string, object> constraints, string? message = null, Exception? inner = null)
+ public EntityNotExistException(EntityType entityType, IDictionary<string, object>? constraints = null, string? message = null, Exception? inner = null)
: base(entityType, constraints, message ?? Resource.ExceptionEntityNotExist, inner)
{
diff --git a/BackEnd/Timeline/Services/EntityTypes.cs b/BackEnd/Timeline/Services/EntityTypes.cs index d4884fd6..89c0a7ec 100644 --- a/BackEnd/Timeline/Services/EntityTypes.cs +++ b/BackEnd/Timeline/Services/EntityTypes.cs @@ -7,5 +7,7 @@ public static EntityType Timeline { get; } = new EntityType(EntityNames.Timeline);
public static EntityType TimelinePost { get; } = new EntityType(EntityNames.TimelinePost);
public static EntityType TimelinePostData { get; } = new EntityType(EntityNames.TimelinePostData);
+ public static EntityType BookmarkTimeline { get; } = new EntityType(EntityNames.BookmarkTimeline);
+ public static EntityType HighlightTimeline { get; } = new EntityType(EntityNames.HighlightTimeline);
}
}
|