From 3591f59453846e235ce77e15adde6092dbbedac3 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 6 Feb 2021 16:41:19 +0800 Subject: ... --- .../Http/HttpTimelinePostCreateRequestContent.cs | 2 ++ .../Models/Http/HttpTimelinePostPatchRequest.cs | 39 ++++++++++++++++++++++ BackEnd/Timeline/Models/Timeline.cs | 24 ------------- .../Timeline/Models/TimelinePostContentTypes.cs | 11 ++++++ BackEnd/Timeline/Models/TimelineVisibility.cs | 18 ++++++++++ .../Validation/TimelinePostContentTypeValidator.cs | 18 ++++++++++ 6 files changed, 88 insertions(+), 24 deletions(-) create mode 100644 BackEnd/Timeline/Models/Http/HttpTimelinePostPatchRequest.cs delete mode 100644 BackEnd/Timeline/Models/Timeline.cs create mode 100644 BackEnd/Timeline/Models/TimelinePostContentTypes.cs create mode 100644 BackEnd/Timeline/Models/TimelineVisibility.cs create mode 100644 BackEnd/Timeline/Models/Validation/TimelinePostContentTypeValidator.cs (limited to 'BackEnd/Timeline/Models') 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. /// [Required] + [TimelinePostContentType] public string Type { get; set; } = default!; /// /// 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 +{ + /// + /// The model of changing post content. + /// + public class HttpTimelinePostPatchRequestContent + { + /// + /// 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. + /// + [TimelinePostContentType] + public string? Type { get; set; } + /// + /// The new text. Null for not change. + /// + public string? Text { get; set; } + /// + /// The new data. Null for not change. + /// + public string? Data { get; set; } + } + + public class HttpTimelinePostPatchRequest + { + /// + /// Change the time. Null for not change. + /// + public DateTime? Time { get; set; } + + /// + /// Change the color. Null for not change. + /// + [Color] + public string? Color { get; set; } + } +} diff --git a/BackEnd/Timeline/Models/Timeline.cs b/BackEnd/Timeline/Models/Timeline.cs deleted file mode 100644 index 9f3eabdf..00000000 --- a/BackEnd/Timeline/Models/Timeline.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace Timeline.Models -{ - public enum TimelineVisibility - { - /// - /// All people including those without accounts. - /// - Public, - /// - /// Only people signed in. - /// - Register, - /// - /// Only member. - /// - Private - } - - public static class TimelinePostContentTypes - { - public const string Text = "text"; - public const string Image = "image"; - } -} 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/TimelineVisibility.cs b/BackEnd/Timeline/Models/TimelineVisibility.cs new file mode 100644 index 00000000..7c1e309b --- /dev/null +++ b/BackEnd/Timeline/Models/TimelineVisibility.cs @@ -0,0 +1,18 @@ +namespace Timeline.Models +{ + public enum TimelineVisibility + { + /// + /// All people including those without accounts. + /// + Public, + /// + /// Only people signed in. + /// + Register, + /// + /// Only member. + /// + Private + } +} 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)) + { + + } + } +} -- cgit v1.2.3