aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Models
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-03-06 22:28:32 +0800
committercrupest <crupest@outlook.com>2020-03-06 22:28:32 +0800
commit99cf6981e7528b8e53f73ba91a7d6a0cf01f3a1f (patch)
treef7a5aee626f4771a0c75ddc67c0b13b67c472a10 /Timeline/Models
parenta37874830399c193392cc78367efcecbe8275ceb (diff)
downloadtimeline-99cf6981e7528b8e53f73ba91a7d6a0cf01f3a1f.tar.gz
timeline-99cf6981e7528b8e53f73ba91a7d6a0cf01f3a1f.tar.bz2
timeline-99cf6981e7528b8e53f73ba91a7d6a0cf01f3a1f.zip
Init development of post image feature.
Diffstat (limited to 'Timeline/Models')
-rw-r--r--Timeline/Models/Http/TimelineCommon.cs35
-rw-r--r--Timeline/Models/Http/TimelineController.cs11
2 files changed, 43 insertions, 3 deletions
diff --git a/Timeline/Models/Http/TimelineCommon.cs b/Timeline/Models/Http/TimelineCommon.cs
index d0dfd837..3be4f895 100644
--- a/Timeline/Models/Http/TimelineCommon.cs
+++ b/Timeline/Models/Http/TimelineCommon.cs
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
+using System.Text.Json.Serialization;
using Timeline.Controllers;
namespace Timeline.Models.Http
@@ -21,10 +22,42 @@ namespace Timeline.Models.Http
Private
}
+ public static class TimelinePostContentTypes
+ {
+ public const string Text = "text";
+ public const string Image = "image";
+ }
+
+ public interface ITimelinePostContent
+ {
+ public string Type { get; }
+ }
+
+ public class TextTimelinePostContent : ITimelinePostContent
+ {
+ public TextTimelinePostContent() { }
+ public TextTimelinePostContent(string text) { Text = text; }
+
+ public string Type { get; } = TimelinePostContentTypes.Text;
+ public string Text { get; set; } = "";
+ }
+
+ public class ImageTimelinePostContent : ITimelinePostContent
+ {
+ public ImageTimelinePostContent() { }
+ public ImageTimelinePostContent(string dataTag) { DataTag = dataTag; }
+
+ public string Type { get; } = TimelinePostContentTypes.Image;
+ [JsonIgnore]
+ public string DataTag { get; set; } = "";
+ public string? Url { get; set; } = null;
+ }
+
public class TimelinePostInfo
{
public long Id { get; set; }
- public string Content { get; set; } = default!;
+ // use object to make json serializer use the runtime type
+ public object Content { get; set; } = default!;
public DateTime Time { get; set; }
public UserInfo Author { get; set; } = default!;
public DateTime LastUpdated { get; set; } = default!;
diff --git a/Timeline/Models/Http/TimelineController.cs b/Timeline/Models/Http/TimelineController.cs
index 6d461bb9..ce5f3b98 100644
--- a/Timeline/Models/Http/TimelineController.cs
+++ b/Timeline/Models/Http/TimelineController.cs
@@ -4,10 +4,17 @@ using Timeline.Models.Validation;
namespace Timeline.Models.Http
{
+ public class TimelinePostCreateRequestContent
+ {
+ [Required]
+ public string Type { get; set; } = default!;
+ public string? Text { get; set; }
+ public string? Data { get; set; }
+ }
+
public class TimelinePostCreateRequest
{
- [Required(AllowEmptyStrings = true)]
- public string Content { get; set; } = default!;
+ public TimelinePostCreateRequestContent Content { get; set; } = default!;
public DateTime? Time { get; set; }
}