diff options
Diffstat (limited to 'BackEnd/Timeline/Models')
-rw-r--r-- | BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequestContent.cs | 2 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Http/HttpTimelinePostPatchRequest.cs | 19 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/Mapper/TimelineMapper.cs | 4 | ||||
-rw-r--r-- | BackEnd/Timeline/Models/TimelinePostContentTypes.cs | 14 | ||||
-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 |
6 files changed, 56 insertions, 9 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..2c6edf66 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpTimelinePostPatchRequest.cs @@ -0,0 +1,19 @@ +using System;
+using Timeline.Models.Validation;
+
+namespace Timeline.Models.Http
+{
+ 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/Mapper/TimelineMapper.cs b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs index 94e55237..88c96d8a 100644 --- a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs +++ b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs @@ -49,7 +49,7 @@ namespace Timeline.Models.Mapper isBookmark: userId is not null && await _bookmarkTimelineService.IsBookmark(userId.Value, entity.Id, false, false),
links: new HttpTimelineLinks(
self: urlHelper.ActionLink(nameof(TimelineController.TimelineGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { timeline = timelineName }),
- posts: urlHelper.ActionLink(nameof(TimelinePostController.PostList), nameof(TimelinePostController)[0..^nameof(Controller).Length], new { timeline = timelineName })
+ posts: urlHelper.ActionLink(nameof(TimelinePostController.List), nameof(TimelinePostController)[0..^nameof(Controller).Length], new { timeline = timelineName })
)
);
}
@@ -84,7 +84,7 @@ namespace Timeline.Models.Mapper (
type: TimelinePostContentTypes.Image,
text: null,
- url: urlHelper.ActionLink(nameof(TimelinePostController.PostDataGet), nameof(TimelinePostController)[0..^nameof(Controller).Length], new { timeline = timelineName, post = entity.LocalId }),
+ url: urlHelper.ActionLink(nameof(TimelinePostController.DataGet), nameof(TimelinePostController)[0..^nameof(Controller).Length], new { timeline = timelineName, post = entity.LocalId }),
eTag: $"\"{entity.Content}\""
),
_ => throw new DatabaseCorruptedException(string.Format(CultureInfo.InvariantCulture, "Unknown timeline post type {0}.", entity.ContentType))
diff --git a/BackEnd/Timeline/Models/TimelinePostContentTypes.cs b/BackEnd/Timeline/Models/TimelinePostContentTypes.cs new file mode 100644 index 00000000..ca5e79e1 --- /dev/null +++ b/BackEnd/Timeline/Models/TimelinePostContentTypes.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic;
+
+namespace Timeline.Models
+{
+ public static class TimelinePostContentTypes
+ {
+#pragma warning disable CA1819 // Properties should not return arrays
+ public static string[] AllTypes { get; } = new string[] { Text, Image };
+#pragma warning restore CA1819 // Properties should not return arrays
+
+ 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))
+ {
+
+ }
+ }
+}
|