aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Services
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-02-10 14:31:31 +0800
committercrupest <crupest@outlook.com>2021-02-10 14:31:31 +0800
commit98df0fb9fe94b703325f09bf765904a11e8a7d4c (patch)
tree544f7af5bdac4726404cc466e61947471949ffaa /BackEnd/Timeline/Services
parent4ea535d93753826ec900879560d876cec4d58c38 (diff)
downloadtimeline-98df0fb9fe94b703325f09bf765904a11e8a7d4c.tar.gz
timeline-98df0fb9fe94b703325f09bf765904a11e8a7d4c.tar.bz2
timeline-98df0fb9fe94b703325f09bf765904a11e8a7d4c.zip
...
Diffstat (limited to 'BackEnd/Timeline/Services')
-rw-r--r--BackEnd/Timeline/Services/Exceptions/TimelinePostNoDataException.cs15
-rw-r--r--BackEnd/Timeline/Services/TimelinePostCreateDataException.cs16
-rw-r--r--BackEnd/Timeline/Services/TimelinePostDataNotExistException.cs15
-rw-r--r--BackEnd/Timeline/Services/TimelinePostService.cs68
4 files changed, 53 insertions, 61 deletions
diff --git a/BackEnd/Timeline/Services/Exceptions/TimelinePostNoDataException.cs b/BackEnd/Timeline/Services/Exceptions/TimelinePostNoDataException.cs
deleted file mode 100644
index c4b6bf62..00000000
--- a/BackEnd/Timeline/Services/Exceptions/TimelinePostNoDataException.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-
-namespace Timeline.Services.Exceptions
-{
- [Serializable]
- public class TimelinePostNoDataException : Exception
- {
- public TimelinePostNoDataException() : this(null, null) { }
- public TimelinePostNoDataException(string? message) : this(message, null) { }
- public TimelinePostNoDataException(string? message, Exception? inner) : base(Resources.Services.Exceptions.TimelineNoDataException.AppendAdditionalMessage(message), inner) { }
- protected TimelinePostNoDataException(
- System.Runtime.Serialization.SerializationInfo info,
- System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
- }
-}
diff --git a/BackEnd/Timeline/Services/TimelinePostCreateDataException.cs b/BackEnd/Timeline/Services/TimelinePostCreateDataException.cs
new file mode 100644
index 00000000..fd1e6664
--- /dev/null
+++ b/BackEnd/Timeline/Services/TimelinePostCreateDataException.cs
@@ -0,0 +1,16 @@
+namespace Timeline.Services
+{
+ [System.Serializable]
+ public class TimelinePostCreateDataException : System.Exception
+ {
+ public TimelinePostCreateDataException() { }
+ public TimelinePostCreateDataException(string message) : base(message) { }
+ public TimelinePostCreateDataException(string message, System.Exception inner) : base(message, inner) { }
+ public TimelinePostCreateDataException(long index, string? message, System.Exception? inner = null) : base(message, inner) { Index = index; }
+ protected TimelinePostCreateDataException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
+
+ public long Index { get; }
+ }
+}
diff --git a/BackEnd/Timeline/Services/TimelinePostDataNotExistException.cs b/BackEnd/Timeline/Services/TimelinePostDataNotExistException.cs
new file mode 100644
index 00000000..eac7a771
--- /dev/null
+++ b/BackEnd/Timeline/Services/TimelinePostDataNotExistException.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace Timeline.Services
+{
+ [Serializable]
+ public class TimelinePostDataNotExistException : Exception
+ {
+ public TimelinePostDataNotExistException() : this(null, null) { }
+ public TimelinePostDataNotExistException(string? message) : this(message, null) { }
+ public TimelinePostDataNotExistException(string? message, Exception? inner) : base(message, inner) { }
+ protected TimelinePostDataNotExistException(
+ System.Runtime.Serialization.SerializationInfo info,
+ System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
+ }
+}
diff --git a/BackEnd/Timeline/Services/TimelinePostService.cs b/BackEnd/Timeline/Services/TimelinePostService.cs
index 98841478..cea702a1 100644
--- a/BackEnd/Timeline/Services/TimelinePostService.cs
+++ b/BackEnd/Timeline/Services/TimelinePostService.cs
@@ -7,6 +7,7 @@ using System.Linq;
using System.Threading.Tasks;
using Timeline.Entities;
using Timeline.Helpers;
+using Timeline.Helpers.Cache;
using Timeline.Models;
using Timeline.Models.Validation;
using Timeline.Services.Exceptions;
@@ -14,49 +15,15 @@ using static Timeline.Resources.Services.TimelineService;
namespace Timeline.Services
{
- public class TimelinePostDataDigest
- {
- public TimelinePostDataDigest(string kind, string eTag, DateTime lastModified)
- {
- Kind = kind;
- ETag = eTag;
- LastModified = lastModified;
- }
-
- public string Kind { get; set; }
- public string ETag { get; set; }
- public DateTime LastModified { get; set; }
- }
-
- public class TimelinePostData
- {
- public TimelinePostData(string kind, byte[] data, string eTag, DateTime lastModified)
- {
- Kind = kind;
- Data = data;
- ETag = eTag;
- LastModified = lastModified;
- }
-
- public string Kind { get; set; }
-
-#pragma warning disable CA1819 // Properties should not return arrays
- public byte[] Data { get; set; }
-#pragma warning restore CA1819 // Properties should not return arrays
-
- public string ETag { get; set; }
- public DateTime LastModified { get; set; }
- }
-
public class TimelinePostCreateRequestData
{
- public TimelinePostCreateRequestData(string kind, byte[] data)
+ public TimelinePostCreateRequestData(string contentType, byte[] data)
{
- Kind = kind;
+ ContentType = contentType;
Data = data;
}
- public string Kind { get; set; }
+ public string ContentType { get; set; }
#pragma warning disable CA1819 // Properties should not return arrays
public byte[] Data { get; set; }
#pragma warning restore CA1819 // Properties should not return arrays
@@ -69,14 +36,13 @@ namespace Timeline.Services
/// <summary>If not set, current time is used.</summary>
public DateTime? Time { get; set; }
- public List<TimelinePostCreateRequestData> Content { get; set; } = new List<TimelinePostCreateRequestData>();
+ public List<TimelinePostCreateRequestData> DataList { get; set; } = new List<TimelinePostCreateRequestData>();
}
public class TimelinePostPatchRequest
{
public string? Color { get; set; }
public DateTime? Time { get; set; }
- public List<TimelinePostCreateRequestData?>? Content { get; set; }
}
public interface ITimelinePostService
@@ -102,18 +68,29 @@ namespace Timeline.Services
/// <exception cref="TimelinePostNotExistException">Thrown when post of <paramref name="postId"/> does not exist or has been deleted.</exception>
Task<TimelinePostEntity> GetPost(long timelineId, long postId, bool includeDelete = false);
- Task<TimelinePostDataDigest> GetPostDataDigest(long timelineId, long postId, long dataIndex);
+ /// <summary>
+ /// Get the data digest of a post.
+ /// </summary>
+ /// <param name="timelineId">The timeline id.</param>
+ /// <param name="postId">The post id.</param>
+ /// <param name="dataIndex">The index of the data.</param>
+ /// <returns>The data digest.</returns>
+ /// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
+ /// <exception cref="TimelinePostNotExistException">Thrown when post of <paramref name="postId"/> does not exist or has been deleted.</exception>
+ /// <exception cref="TimelinePostDataNotExistException">Thrown when data of that index does not exist.</exception>
+ Task<ICacheableDataDigest> GetPostDataDigest(long timelineId, long postId, long dataIndex);
/// <summary>
/// Get the data of a post.
/// </summary>
- /// <param name="timelineId">The id of the timeline of the post.</param>
- /// <param name="postId">The id of the post.</param>
- /// <returns>The etag of the data.</returns>
+ /// <param name="timelineId">The timeline id.</param>
+ /// <param name="postId">The post id.</param>
+ /// <param name="dataIndex">The index of the data.</param>
+ /// <returns>The data.</returns>
/// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
/// <exception cref="TimelinePostNotExistException">Thrown when post of <paramref name="postId"/> does not exist or has been deleted.</exception>
- /// <exception cref="TimelinePostNoDataException">Thrown when post has no data.</exception>
- Task<TimelinePostData> GetPostData(long timelineId, long postId, long dataIndex);
+ /// <exception cref="TimelinePostDataNotExistException">Thrown when data of that index does not exist.</exception>
+ Task<ByteData> GetPostData(long timelineId, long postId, long dataIndex);
/// <summary>
/// Create a new post in timeline.
@@ -140,7 +117,6 @@ namespace Timeline.Services
/// <exception cref="ArgumentException">Thrown when <paramref name="request"/> is of invalid format.</exception>
/// <exception cref="TimelineNotExistException">Thrown when timeline does not exist.</exception>
/// <exception cref="TimelinePostNotExistException">Thrown when post does not exist.</exception>
- /// <exception cref="ImageException">Thrown if data is not a image. Validated by <see cref="ImageValidator"/>.</exception>
Task<TimelinePostEntity> PatchPost(long timelineId, long postId, TimelinePostPatchRequest request);
/// <summary>