From fc0521d81aa2293b94ea40b79ec0df80966c0278 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 16 Mar 2020 19:07:13 +0800 Subject: Hotfix a bug in post data. --- Timeline/Services/BadPostTypeException.cs | 21 +++++++++++++++++++++ Timeline/Services/TimelineService.cs | 12 ++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 Timeline/Services/BadPostTypeException.cs (limited to 'Timeline/Services') 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 /// See remarks of . /// See remarks of . /// Thrown when post of does not exist or has been deleted. - /// Thrown when post has no data. See remarks. + /// Thrown when post has no data. See remarks. /// Task GetPostDataETag(string name, long postId); @@ -116,7 +116,7 @@ namespace Timeline.Services /// See remarks of . /// See remarks of . /// Thrown when post of does not exist or has been deleted. - /// Thrown when post has no data. See remarks. + /// Thrown when post has no data. See remarks. /// /// Use this method to retrieve the image of image post. /// @@ -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; -- cgit v1.2.3