From 35f6584f47676353733f1cc9182d84ed4ded5cbc Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 27 Aug 2020 01:13:31 +0800 Subject: Timeline title feature. --- Timeline.Tests/IntegratedTests/TimelineTest.cs | 29 ++++++++++++++++++++++++++ Timeline.Tests/Services/TimelineServiceTest.cs | 27 ++++++++++++++++++++++++ Timeline/Models/Http/Timeline.cs | 4 ++++ Timeline/Models/Http/TimelineController.cs | 5 +++++ Timeline/Models/Timeline.cs | 2 ++ Timeline/Services/TimelineService.cs | 11 +++++++++- 6 files changed, 77 insertions(+), 1 deletion(-) diff --git a/Timeline.Tests/IntegratedTests/TimelineTest.cs b/Timeline.Tests/IntegratedTests/TimelineTest.cs index 3b4b1754..302b2195 100644 --- a/Timeline.Tests/IntegratedTests/TimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/TimelineTest.cs @@ -1407,5 +1407,34 @@ namespace Timeline.Tests.IntegratedTests .Which.Should().BeEquivalentTo(timeline); } } + + [Theory] + [MemberData(nameof(TimelineUrlGeneratorData))] + public async Task Title(TimelineUrlGenerator urlGenerator) + { + using var client = await CreateClientAsUser(); + + { + var res = await client.GetAsync(urlGenerator(1)); + var timeline = res.Should().HaveStatusCode(200) + .And.HaveJsonBody() + .Which; + timeline.Title.Should().Be(timeline.Name); + } + + { + var res = await client.PatchAsJsonAsync(urlGenerator(1), new TimelinePatchRequest { Title = "atitle" }); + res.Should().HaveStatusCode(200) + .And.HaveJsonBody() + .Which.Title.Should().Be("atitle"); + } + + { + var res = await client.GetAsync(urlGenerator(1)); + res.Should().HaveStatusCode(200) + .And.HaveJsonBody() + .Which.Title.Should().Be("atitle"); + } + } } } diff --git a/Timeline.Tests/Services/TimelineServiceTest.cs b/Timeline.Tests/Services/TimelineServiceTest.cs index 36e5ed0c..558ec597 100644 --- a/Timeline.Tests/Services/TimelineServiceTest.cs +++ b/Timeline.Tests/Services/TimelineServiceTest.cs @@ -271,5 +271,32 @@ namespace Timeline.Tests.Services posts.Should().HaveCount(4); } } + + [Theory] + [InlineData("@admin")] + [InlineData("tl")] + public async Task Title(string timelineName) + { + var _ = TimelineHelper.ExtractTimelineName(timelineName, out var isPersonal); + if (!isPersonal) + await _timelineService.CreateTimeline(timelineName, await _userService.GetUserIdByUsername("user")); + + { + var timeline = await _timelineService.GetTimeline(timelineName); + timeline.Title.Should().Be(timelineName); + } + + { + await _timelineService.ChangeProperty(timelineName, new TimelineChangePropertyRequest { Title = null }); + var timeline = await _timelineService.GetTimeline(timelineName); + timeline.Title.Should().Be(timelineName); + } + + { + await _timelineService.ChangeProperty(timelineName, new TimelineChangePropertyRequest { Title = "atitle" }); + var timeline = await _timelineService.GetTimeline(timelineName); + timeline.Title.Should().Be("atitle"); + } + } } } diff --git a/Timeline/Models/Http/Timeline.cs b/Timeline/Models/Http/Timeline.cs index 6498fa74..3596af18 100644 --- a/Timeline/Models/Http/Timeline.cs +++ b/Timeline/Models/Http/Timeline.cs @@ -68,6 +68,10 @@ namespace Timeline.Models.Http /// public string UniqueId { get; set; } = default!; /// + /// Title. + /// + public string Title { get; set; } = default!; + /// /// Name of timeline. /// public string Name { get; set; } = default!; diff --git a/Timeline/Models/Http/TimelineController.cs b/Timeline/Models/Http/TimelineController.cs index aad361ee..95bae3e6 100644 --- a/Timeline/Models/Http/TimelineController.cs +++ b/Timeline/Models/Http/TimelineController.cs @@ -56,6 +56,11 @@ namespace Timeline.Models.Http /// public class TimelinePatchRequest { + /// + /// New title. Null for not change. + /// + public string? Title { get; set; } + /// /// New description. Null for not change. /// diff --git a/Timeline/Models/Timeline.cs b/Timeline/Models/Timeline.cs index 34c253a0..42906053 100644 --- a/Timeline/Models/Timeline.cs +++ b/Timeline/Models/Timeline.cs @@ -74,6 +74,7 @@ namespace Timeline.Models public string UniqueID { get; set; } = default!; public string Name { get; set; } = default!; public DateTime NameLastModified { get; set; } = default!; + public string Title { get; set; } = default!; public string Description { get; set; } = default!; public User Owner { get; set; } = default!; public TimelineVisibility Visibility { get; set; } @@ -86,6 +87,7 @@ namespace Timeline.Models public class TimelineChangePropertyRequest { + public string? Title { get; set; } public string? Description { get; set; } public TimelineVisibility? Visibility { get; set; } } diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index 01f7f5fd..2f0bf2c5 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -405,11 +405,14 @@ namespace Timeline.Services members.Add(await _userService.GetUserById(memberEntity.UserId)); } + var name = entity.Name ?? ("@" + owner.Username); + return new Models.Timeline { UniqueID = entity.UniqueId, - Name = entity.Name ?? ("@" + owner.Username), + Name = name, NameLastModified = entity.NameLastModified, + Title = string.IsNullOrEmpty(entity.Title) ? name : entity.Title, Description = entity.Description ?? "", Owner = owner, Visibility = entity.Visibility, @@ -834,6 +837,12 @@ namespace Timeline.Services var changed = false; + if (newProperties.Title != null) + { + changed = true; + timelineEntity.Title = newProperties.Title; + } + if (newProperties.Description != null) { changed = true; -- cgit v1.2.3