diff options
author | crupest <crupest@outlook.com> | 2020-08-27 01:13:31 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-08-27 01:13:31 +0800 |
commit | 7936281edc1ac592cd318b8dccb37f3c4e7334e8 (patch) | |
tree | 033a69be9b3db46ad50f8b2703d73de99245f95c | |
parent | d5cc18a9ea161b28e1a7acd67a0c4558ba265800 (diff) | |
download | timeline-7936281edc1ac592cd318b8dccb37f3c4e7334e8.tar.gz timeline-7936281edc1ac592cd318b8dccb37f3c4e7334e8.tar.bz2 timeline-7936281edc1ac592cd318b8dccb37f3c4e7334e8.zip |
Timeline title feature.
-rw-r--r-- | Timeline.Tests/IntegratedTests/TimelineTest.cs | 29 | ||||
-rw-r--r-- | Timeline.Tests/Services/TimelineServiceTest.cs | 27 | ||||
-rw-r--r-- | Timeline/Models/Http/Timeline.cs | 4 | ||||
-rw-r--r-- | Timeline/Models/Http/TimelineController.cs | 5 | ||||
-rw-r--r-- | Timeline/Models/Timeline.cs | 2 | ||||
-rw-r--r-- | Timeline/Services/TimelineService.cs | 11 |
6 files changed, 77 insertions, 1 deletions
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<TimelineInfo>()
+ .Which;
+ timeline.Title.Should().Be(timeline.Name);
+ }
+
+ {
+ var res = await client.PatchAsJsonAsync(urlGenerator(1), new TimelinePatchRequest { Title = "atitle" });
+ res.Should().HaveStatusCode(200)
+ .And.HaveJsonBody<TimelineInfo>()
+ .Which.Title.Should().Be("atitle");
+ }
+
+ {
+ var res = await client.GetAsync(urlGenerator(1));
+ res.Should().HaveStatusCode(200)
+ .And.HaveJsonBody<TimelineInfo>()
+ .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 /// </summary>
public string UniqueId { get; set; } = default!;
/// <summary>
+ /// Title.
+ /// </summary>
+ public string Title { get; set; } = default!;
+ /// <summary>
/// Name of timeline.
/// </summary>
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 @@ -57,6 +57,11 @@ namespace Timeline.Models.Http public class TimelinePatchRequest
{
/// <summary>
+ /// New title. Null for not change.
+ /// </summary>
+ public string? Title { get; set; }
+
+ /// <summary>
/// New description. Null for not change.
/// </summary>
public string? Description { get; set; }
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;
|