From a46460a3cc71497bc7d360ab3d7068059bc7a0cc Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 4 Feb 2021 21:26:01 +0800 Subject: ... --- .../IntegratedTests/TimelinePostTest.cs | 27 ++++++++++++++++++++++ .../Timeline/Controllers/TimelinePostController.cs | 6 +++-- BackEnd/Timeline/Models/Http/HttpTimelinePost.cs | 7 +++++- .../Models/Http/HttpTimelinePostCreateRequest.cs | 7 ++++++ BackEnd/Timeline/Models/Mapper/TimelineMapper.cs | 1 + 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs index ae7afda1..f05ed7af 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelinePostTest.cs @@ -473,5 +473,32 @@ namespace Timeline.Tests.IntegratedTests } } + [Theory] + [MemberData(nameof(TimelineNameGeneratorTestData))] + public async Task Color(TimelineNameGenerator generator) + { + using var client = await CreateClientAsUser(); + + HttpTimelinePostCreateRequestContent CreateRequestContent() => new() + { + Type = "text", + Text = "aaa" + }; + + await client.TestPostAssertInvalidModelAsync($"timelines/{generator(1)}/posts", new HttpTimelinePostCreateRequest + { + Content = CreateRequestContent(), + Color = "#1" + }); + + { + var post = await client.TestPostAsync($"timelines/{generator(1)}/posts", new HttpTimelinePostCreateRequest + { + Content = CreateRequestContent(), + Color = "#aabbcc" + }); + post.Color.Should().Be("#aabbcc"); + } + } } } diff --git a/BackEnd/Timeline/Controllers/TimelinePostController.cs b/BackEnd/Timeline/Controllers/TimelinePostController.cs index 6b7ba411..3f31decf 100644 --- a/BackEnd/Timeline/Controllers/TimelinePostController.cs +++ b/BackEnd/Timeline/Controllers/TimelinePostController.cs @@ -135,6 +135,8 @@ namespace Timeline.Controllers TimelinePostEntity post; + TimelinePostCommonProperties properties = new TimelinePostCommonProperties { Color = body.Color, Time = body.Time }; + if (content.Type == TimelinePostContentTypes.Text) { var text = content.Text; @@ -142,7 +144,7 @@ namespace Timeline.Controllers { return BadRequest(ErrorResponse.Common.CustomMessage_InvalidModel(Resources.Messages.TimelineController_TextContentTextRequired)); } - post = await _postService.CreateTextPost(timelineId, userId, text, new TimelinePostCommonProperties { Time = body.Time }); + post = await _postService.CreateTextPost(timelineId, userId, text, properties); } else if (content.Type == TimelinePostContentTypes.Image) { @@ -163,7 +165,7 @@ namespace Timeline.Controllers try { - post = await _postService.CreateImagePost(timelineId, userId, data, new TimelinePostCommonProperties { Time = body.Time }); + post = await _postService.CreateImagePost(timelineId, userId, data, properties); } catch (ImageException) { diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs index a563bea0..5981d7a4 100644 --- a/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs +++ b/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs @@ -9,13 +9,14 @@ namespace Timeline.Models.Http { public HttpTimelinePost() { } - public HttpTimelinePost(long id, HttpTimelinePostContent? content, bool deleted, DateTime time, HttpUser? author, DateTime lastUpdated) + public HttpTimelinePost(long id, HttpTimelinePostContent? content, bool deleted, DateTime time, HttpUser? author, string? color, DateTime lastUpdated) { Id = id; Content = content; Deleted = deleted; Time = time; Author = author; + Color = color; LastUpdated = lastUpdated; } @@ -40,6 +41,10 @@ namespace Timeline.Models.Http /// public HttpUser? Author { get; set; } = default!; /// + /// The color. + /// + public string? Color { get; set; } + /// /// Last updated time. /// public DateTime LastUpdated { get; set; } = default!; diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs index cfbec029..b25adf36 100644 --- a/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs +++ b/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel.DataAnnotations; +using Timeline.Models.Validation; namespace Timeline.Models.Http { @@ -15,5 +16,11 @@ namespace Timeline.Models.Http /// Time of the post. If not set, current time will be used. /// public DateTime? Time { get; set; } + + /// + /// Color of the post. + /// + [Color] + public string? Color { get; set; } } } diff --git a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs index 25abf0ba..94e55237 100644 --- a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs +++ b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs @@ -106,6 +106,7 @@ namespace Timeline.Models.Mapper deleted: content is null, time: entity.Time, author: author, + color: entity.Color, lastUpdated: entity.LastUpdated ); } -- cgit v1.2.3