diff options
author | crupest <crupest@outlook.com> | 2020-03-16 19:07:13 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-03-16 19:07:13 +0800 |
commit | 7e393559d2883a37b1be0c82cccc06bc97c3d102 (patch) | |
tree | 07d96d3ab8ca909019cbb1225d533fe4aa2a57ac | |
parent | b20c488a9b02807cfa117b10dd8906271af03614 (diff) | |
download | timeline-7e393559d2883a37b1be0c82cccc06bc97c3d102.tar.gz timeline-7e393559d2883a37b1be0c82cccc06bc97c3d102.tar.bz2 timeline-7e393559d2883a37b1be0c82cccc06bc97c3d102.zip |
Hotfix a bug in post data.
-rw-r--r-- | Timeline/Controllers/TimelineController.cs | 2 | ||||
-rw-r--r-- | Timeline/Services/BadPostTypeException.cs | 21 | ||||
-rw-r--r-- | Timeline/Services/TimelineService.cs | 12 |
3 files changed, 28 insertions, 7 deletions
diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index f1781ff3..5b894e26 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -134,7 +134,7 @@ namespace Timeline.Controllers {
return NotFound(ErrorResponse.TimelineController.PostNotExist());
}
- catch (InvalidOperationException)
+ catch (BadPostTypeException)
{
return BadRequest(ErrorResponse.TimelineController.PostNoData());
}
diff --git a/Timeline/Services/BadPostTypeException.cs b/Timeline/Services/BadPostTypeException.cs new file mode 100644 index 00000000..795ca2b6 --- /dev/null +++ b/Timeline/Services/BadPostTypeException.cs @@ -0,0 +1,21 @@ +using System;
+
+namespace Timeline.Services
+{
+ [Serializable]
+ public class BadPostTypeException : Exception
+ {
+ public BadPostTypeException() { }
+ public BadPostTypeException(string message) : base(message) { }
+ public BadPostTypeException(string message, Exception inner) : base(message, inner) { }
+ public BadPostTypeException(string requestType, string requiredType) : this() { RequestType = requestType; RequiredType = requiredType; }
+ public BadPostTypeException(string requestType, string requiredType, string message) : this(message) { RequestType = requestType; RequiredType = requiredType; }
+ public BadPostTypeException(string requestType, string requiredType, string message, Exception inner) : this(message, inner) { RequestType = requestType; RequiredType = requiredType; }
+ protected BadPostTypeException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
+
+ public string RequestType { get; set; } = "";
+ public string RequiredType { get; set; } = "";
+ }
+}
diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index b26016e5..aecfeeec 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -102,7 +102,7 @@ namespace Timeline.Services /// <exception cref="ArgumentException">See remarks of <see cref="IBaseTimelineService"/>.</exception>
/// <exception cref="TimelineNotExistException">See remarks of <see cref="IBaseTimelineService"/>.</exception>
/// <exception cref="TimelinePostNotExistException">Thrown when post of <paramref name="postId"/> does not exist or has been deleted.</exception>
- /// <exception cref="InvalidOperationException">Thrown when post has no data. See remarks.</exception>
+ /// <exception cref="BadPostTypeException">Thrown when post has no data. See remarks.</exception>
/// <seealso cref="GetPostData(string, long)"/>
Task<string> GetPostDataETag(string name, long postId);
@@ -116,7 +116,7 @@ namespace Timeline.Services /// <exception cref="ArgumentException">See remarks of <see cref="IBaseTimelineService"/>.</exception>
/// <exception cref="TimelineNotExistException">See remarks of <see cref="IBaseTimelineService"/>.</exception>
/// <exception cref="TimelinePostNotExistException">Thrown when post of <paramref name="postId"/> does not exist or has been deleted.</exception>
- /// <exception cref="InvalidOperationException">Thrown when post has no data. See remarks.</exception>
+ /// <exception cref="BadPostTypeException">Thrown when post has no data. See remarks.</exception>
/// <remarks>
/// Use this method to retrieve the image of image post.
/// </remarks>
@@ -425,7 +425,7 @@ namespace Timeline.Services throw new ArgumentNullException(nameof(name));
var timelineId = await FindTimelineId(name);
- var postEntity = await Database.TimelinePosts.Where(p => p.LocalId == postId).SingleOrDefaultAsync();
+ var postEntity = await Database.TimelinePosts.Where(p => p.TimelineId == timelineId && p.LocalId == postId).SingleOrDefaultAsync();
if (postEntity == null)
throw new TimelinePostNotExistException(name, postId);
@@ -434,7 +434,7 @@ namespace Timeline.Services throw new TimelinePostNotExistException(name, postId, true);
if (postEntity.ContentType != TimelinePostContentTypes.Image)
- throw new InvalidOperationException(ExceptionGetDataNonImagePost);
+ throw new BadPostTypeException(postEntity.ContentType, TimelinePostContentTypes.Image, ExceptionGetDataNonImagePost);
var tag = postEntity.Content;
@@ -447,7 +447,7 @@ namespace Timeline.Services throw new ArgumentNullException(nameof(name));
var timelineId = await FindTimelineId(name);
- var postEntity = await Database.TimelinePosts.Where(p => p.LocalId == postId).SingleOrDefaultAsync();
+ var postEntity = await Database.TimelinePosts.Where(p => p.TimelineId == timelineId && p.LocalId == postId).SingleOrDefaultAsync();
if (postEntity == null)
throw new TimelinePostNotExistException(name, postId);
@@ -456,7 +456,7 @@ namespace Timeline.Services throw new TimelinePostNotExistException(name, postId, true);
if (postEntity.ContentType != TimelinePostContentTypes.Image)
- throw new InvalidOperationException(ExceptionGetDataNonImagePost);
+ throw new BadPostTypeException(postEntity.ContentType, TimelinePostContentTypes.Image, ExceptionGetDataNonImagePost);
var tag = postEntity.Content;
|