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 | 7d54e0b8b7ca84488fdcba90c68169a85b4d45c6 (patch) | |
tree | cf2fa58eef25e5bf871d8a71b15ac6694e357b54 | |
parent | 51e1205d3a9c72a5734a842536630cea69359107 (diff) | |
download | timeline-7d54e0b8b7ca84488fdcba90c68169a85b4d45c6.tar.gz timeline-7d54e0b8b7ca84488fdcba90c68169a85b4d45c6.tar.bz2 timeline-7d54e0b8b7ca84488fdcba90c68169a85b4d45c6.zip |
refactor: ...
13 files changed, 28 insertions, 57 deletions
diff --git a/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs b/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs index bfbf82f3..551a41e2 100644 --- a/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs +++ b/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs @@ -92,16 +92,9 @@ namespace Timeline.Controllers [ProducesResponseType(401)]
public async Task<ActionResult> Move([FromBody] HttpBookmarkTimelineMoveRequest request)
{
- try
- {
- var timelineId = await _timelineService.GetTimelineIdByNameAsync(request.Timeline);
- await _service.MoveBookmarkAsync(GetUserId(), timelineId, request.NewPosition!.Value);
- return Ok();
- }
- catch (InvalidBookmarkException)
- {
- return BadRequest(new CommonResponse(ErrorCodes.BookmarkTimelineController.NonBookmark, "You can't move a non-bookmark timeline."));
- }
+ var timelineId = await _timelineService.GetTimelineIdByNameAsync(request.Timeline);
+ await _service.MoveBookmarkAsync(GetUserId(), timelineId, request.NewPosition!.Value);
+ return OkWithCommonResponse();
}
}
}
diff --git a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs index 24201126..127392db 100644 --- a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs +++ b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs @@ -93,16 +93,9 @@ namespace Timeline.Controllers [ProducesResponseType(403)]
public async Task<ActionResult> Move([FromBody] HttpHighlightTimelineMoveRequest body)
{
- try
- {
- var timelineId = await _timelineService.GetTimelineIdByNameAsync(body.Timeline);
- await _service.MoveHighlightTimelineAsync(timelineId, body.NewPosition!.Value);
- return Ok();
- }
- catch (InvalidHighlightTimelineException)
- {
- return BadRequest(new CommonResponse(ErrorCodes.HighlightTimelineController.NonHighlight, "Can't move a non-highlight timeline."));
- }
+ var timelineId = await _timelineService.GetTimelineIdByNameAsync(body.Timeline);
+ await _service.MoveHighlightTimelineAsync(timelineId, body.NewPosition!.Value);
+ return OkWithCommonResponse();
}
}
}
diff --git a/BackEnd/Timeline/ErrorCodes.cs b/BackEnd/Timeline/ErrorCodes.cs index 79054a6f..be532c0c 100644 --- a/BackEnd/Timeline/ErrorCodes.cs +++ b/BackEnd/Timeline/ErrorCodes.cs @@ -43,6 +43,8 @@ public const int Timeline = 2_001_00_02;
public const int TimelinePost = 2_001_00_03;
public const int TimelinePostData = 2_001_00_04;
+ public const int BookmarkTimeline = 2_001_00_05;
+ public const int HighlightTimeline = 2_001_00_06;
}
public static class Conflict
@@ -52,6 +54,8 @@ public const int Timeline = 2_002_00_02;
public const int TimelinePost = 2_002_00_03;
public const int TimelinePostData = 2_002_00_04;
+ public const int BookmarkTimeline = 2_002_00_05;
+ public const int HighlightTimeline = 2_002_00_06;
}
public static class TokenController
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);
}
}
|