diff options
author | crupest <crupest@outlook.com> | 2021-02-06 16:41:19 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-02-06 16:41:19 +0800 |
commit | d42d826ae863b20913321d229a168b05d723db73 (patch) | |
tree | 51831c60b08fabe9c83ce6ac3dbf1498310b9831 /BackEnd/Timeline | |
parent | 66658abde1220a53d0e022aaac8dd49a15034a34 (diff) | |
download | timeline-d42d826ae863b20913321d229a168b05d723db73.tar.gz timeline-d42d826ae863b20913321d229a168b05d723db73.tar.bz2 timeline-d42d826ae863b20913321d229a168b05d723db73.zip |
...
Diffstat (limited to 'BackEnd/Timeline')
-rw-r--r-- | BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequestContent.cs | 2 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Http/HttpTimelinePostPatchRequest.cs | 39 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/TimelinePostContentTypes.cs | 11 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/TimelineVisibility.cs (renamed from BackEnd/Timeline/Models/Timeline.cs) | 8 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Validation/TimelinePostContentTypeValidator.cs | 18 |
5 files changed, 71 insertions, 7 deletions
diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequestContent.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequestContent.cs index f4b300a9..12ab407f 100644 --- a/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequestContent.cs +++ b/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequestContent.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations;
+using Timeline.Models.Validation;
namespace Timeline.Models.Http
{
@@ -11,6 +12,7 @@ namespace Timeline.Models.Http /// Type of post content.
/// </summary>
[Required]
+ [TimelinePostContentType]
public string Type { get; set; } = default!;
/// <summary>
/// If post is of text type, this is the text.
diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePostPatchRequest.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePostPatchRequest.cs new file mode 100644 index 00000000..3dface29 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpTimelinePostPatchRequest.cs @@ -0,0 +1,39 @@ +using System;
+using Timeline.Models.Validation;
+
+namespace Timeline.Models.Http
+{
+ /// <summary>
+ /// The model of changing post content.
+ /// </summary>
+ public class HttpTimelinePostPatchRequestContent
+ {
+ /// <summary>
+ /// The new type of the post. If null, old type is used. This field can't be used alone. Use it with corresponding fields to change post content.
+ /// </summary>
+ [TimelinePostContentType]
+ public string? Type { get; set; }
+ /// <summary>
+ /// The new text. Null for not change.
+ /// </summary>
+ public string? Text { get; set; }
+ /// <summary>
+ /// The new data. Null for not change.
+ /// </summary>
+ public string? Data { get; set; }
+ }
+
+ public class HttpTimelinePostPatchRequest
+ {
+ /// <summary>
+ /// Change the time. Null for not change.
+ /// </summary>
+ public DateTime? Time { get; set; }
+
+ /// <summary>
+ /// Change the color. Null for not change.
+ /// </summary>
+ [Color]
+ public string? Color { get; set; }
+ }
+}
diff --git a/BackEnd/Timeline/Models/TimelinePostContentTypes.cs b/BackEnd/Timeline/Models/TimelinePostContentTypes.cs new file mode 100644 index 00000000..22763eba --- /dev/null +++ b/BackEnd/Timeline/Models/TimelinePostContentTypes.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic;
+
+namespace Timeline.Models
+{
+ public static class TimelinePostContentTypes
+ {
+ public static string[] AllTypes { get; } = new string[] { Text, Image };
+ public const string Text = "text";
+ public const string Image = "image";
+ }
+}
diff --git a/BackEnd/Timeline/Models/Timeline.cs b/BackEnd/Timeline/Models/TimelineVisibility.cs index 9f3eabdf..7c1e309b 100644 --- a/BackEnd/Timeline/Models/Timeline.cs +++ b/BackEnd/Timeline/Models/TimelineVisibility.cs @@ -1,4 +1,4 @@ -namespace Timeline.Models
+namespace Timeline.Models
{
public enum TimelineVisibility
{
@@ -15,10 +15,4 @@ /// </summary>
Private
}
-
- public static class TimelinePostContentTypes
- {
- public const string Text = "text";
- public const string Image = "image";
- }
}
diff --git a/BackEnd/Timeline/Models/Validation/TimelinePostContentTypeValidator.cs b/BackEnd/Timeline/Models/Validation/TimelinePostContentTypeValidator.cs new file mode 100644 index 00000000..483cce06 --- /dev/null +++ b/BackEnd/Timeline/Models/Validation/TimelinePostContentTypeValidator.cs @@ -0,0 +1,18 @@ +using System;
+
+namespace Timeline.Models.Validation
+{
+ public class TimelinePostContentTypeValidator : StringSetValidator
+ {
+ public TimelinePostContentTypeValidator() : base(TimelinePostContentTypes.AllTypes) { }
+ }
+
+ [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
+ public class TimelinePostContentTypeAttribute : ValidateWithAttribute
+ {
+ public TimelinePostContentTypeAttribute() : base(typeof(TimelinePostContentTypeValidator))
+ {
+
+ }
+ }
+}
|