aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-04-24 15:46:12 +0800
committercrupest <crupest@outlook.com>2022-04-24 15:46:12 +0800
commit69c760dbbbdb774957316a98bc135e69d8328dd8 (patch)
tree3279d38db535c5bdd48e8003d981c593ba00edd4
parent3bc8ee1de171f0bd8e226542d75c842c5b2e7175 (diff)
downloadtimeline-69c760dbbbdb774957316a98bc135e69d8328dd8.tar.gz
timeline-69c760dbbbdb774957316a98bc135e69d8328dd8.tar.bz2
timeline-69c760dbbbdb774957316a98bc135e69d8328dd8.zip
...
-rw-r--r--BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs8
-rw-r--r--BackEnd/Timeline/Models/Http/HttpUserLinks.cs7
-rw-r--r--BackEnd/Timeline/Services/Mapper/TimelineMapper.cs15
-rw-r--r--BackEnd/Timeline/Services/Mapper/UserMapper.cs6
-rw-r--r--BackEnd/Timeline/Services/Timeline/MarkdownProcessor.cs2
5 files changed, 20 insertions, 18 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs
index 72553248..5fab2bdb 100644
--- a/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs
+++ b/BackEnd/Timeline.Tests/IntegratedTests/TimelineTest.cs
@@ -33,8 +33,8 @@ namespace Timeline.Tests.IntegratedTests
body.Members.Should().NotBeNull().And.BeEmpty();
var links = body._links;
links.Should().NotBeNull();
- links.Self.Should().EndWith("timelines/@user1");
- links.Posts.Should().EndWith("timelines/@user1/posts");
+ links.Self.Should().NotBeNull();
+ links.Posts.Should().NotBeNull();
}
{
@@ -45,8 +45,8 @@ namespace Timeline.Tests.IntegratedTests
body.Members.Should().NotBeNull().And.BeEmpty();
var links = body._links;
links.Should().NotBeNull();
- links.Self.Should().EndWith("timelines/t1");
- links.Posts.Should().EndWith("timelines/t1/posts");
+ links.Self.Should().NotBeNull();
+ links.Posts.Should().NotBeNull();
}
}
diff --git a/BackEnd/Timeline/Models/Http/HttpUserLinks.cs b/BackEnd/Timeline/Models/Http/HttpUserLinks.cs
index d5f909c2..a1ba6f6f 100644
--- a/BackEnd/Timeline/Models/Http/HttpUserLinks.cs
+++ b/BackEnd/Timeline/Models/Http/HttpUserLinks.cs
@@ -8,11 +8,10 @@
{
public HttpUserLinks() { }
- public HttpUserLinks(string self, string avatar, string timeline)
+ public HttpUserLinks(string self, string avatar)
{
Self = self;
Avatar = avatar;
- Timeline = timeline;
}
/// <summary>
@@ -23,9 +22,5 @@
/// Avatar url.
/// </summary>
public string Avatar { get; set; } = default!;
- /// <summary>
- /// Personal timeline url.
- /// </summary>
- public string Timeline { get; set; } = default!;
}
}
diff --git a/BackEnd/Timeline/Services/Mapper/TimelineMapper.cs b/BackEnd/Timeline/Services/Mapper/TimelineMapper.cs
index a59b906c..be517c9a 100644
--- a/BackEnd/Timeline/Services/Mapper/TimelineMapper.cs
+++ b/BackEnd/Timeline/Services/Mapper/TimelineMapper.cs
@@ -73,11 +73,14 @@ namespace Timeline.Services.Mapper
postable = await _timelineService.IsMemberOfAsync(entity.Id, userId.Value);
}
+ var nameV2 = entity.Name is null ? "self" : entity.Name;
+ var ownerUsername = entity.Owner.Username;
+
return new HttpTimeline(
uniqueId: entity.UniqueId,
title: string.IsNullOrEmpty(entity.Title) ? timelineName : entity.Title,
name: timelineName,
- nameV2: entity.Name is null ? "self" : entity.Name,
+ nameV2: nameV2,
nameLastModifed: entity.NameLastModified,
description: entity.Description ?? "",
owner: await _userMapper.MapAsync(entity.Owner, urlHelper, user),
@@ -91,13 +94,17 @@ namespace Timeline.Services.Mapper
manageable: manageable,
postable: postable,
links: new HttpTimelineLinks(
- self: urlHelper.ActionLink(nameof(TimelineController.TimelineGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { timeline = timelineName })!,
- posts: urlHelper.ActionLink(nameof(TimelinePostController.List), nameof(TimelinePostController)[0..^nameof(Controller).Length], new { timeline = timelineName })!
+ self: urlHelper.ActionLink("Get", "TimelineV2", new { owner = ownerUsername, timeline = nameV2 }) ?? throw Exception("Failed to generate link for timeline self."),
+ posts: urlHelper.ActionLink("List", "TimelinePostV2", new { owner = ownerUsername, timeline = nameV2 }) ?? throw Exception("Failed to generate link for timeline posts.")
)
);
+ }
+
+ private System.Exception Exception(string v)
+ {
+ throw new System.NotImplementedException();
}
-
public async Task<HttpTimelinePost> MapAsync(TimelinePostEntity entity, IUrlHelper urlHelper, ClaimsPrincipal? user)
{
var userId = user.GetOptionalUserId();
diff --git a/BackEnd/Timeline/Services/Mapper/UserMapper.cs b/BackEnd/Timeline/Services/Mapper/UserMapper.cs
index d8c9e294..8a41cd4b 100644
--- a/BackEnd/Timeline/Services/Mapper/UserMapper.cs
+++ b/BackEnd/Timeline/Services/Mapper/UserMapper.cs
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
+using System;
using System.Security.Claims;
using System.Threading.Tasks;
using Timeline.Controllers;
@@ -27,9 +28,8 @@ namespace Timeline.Services.Mapper
nickname: string.IsNullOrEmpty(entity.Nickname) ? entity.Username : entity.Nickname,
permissions: (await _userPermissionService.GetPermissionsOfUserAsync(entity.Id, false)).ToStringList(),
links: new HttpUserLinks(
- self: urlHelper.ActionLink(nameof(UserController.Get), nameof(UserController)[0..^nameof(Controller).Length], new { entity.Username })!,
- avatar: urlHelper.ActionLink(nameof(UserAvatarController.Get), nameof(UserAvatarController)[0..^nameof(Controller).Length], new { entity.Username })!,
- timeline: urlHelper.ActionLink(nameof(TimelineController.TimelineGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { timeline = "@" + entity.Username })!
+ self: urlHelper.ActionLink("Get", "UserV2", new { username = entity.Username }) ?? throw new Exception("Failed to generate link for user self."),
+ avatar: urlHelper.ActionLink("Get", "UserAvatarV2", new { username = entity.Username }) ?? throw new Exception("Failed to generate link for user avatar.")
)
);
}
diff --git a/BackEnd/Timeline/Services/Timeline/MarkdownProcessor.cs b/BackEnd/Timeline/Services/Timeline/MarkdownProcessor.cs
index 84b99915..5c8aabc0 100644
--- a/BackEnd/Timeline/Services/Timeline/MarkdownProcessor.cs
+++ b/BackEnd/Timeline/Services/Timeline/MarkdownProcessor.cs
@@ -31,8 +31,8 @@ namespace Timeline.Services.Timeline
return writer.ToString();
}
- [Obsolete("Use overload with 'owner'.")]
/// <summary>Convert data url to true url with post id.</summary>
+ [Obsolete("Use overload with 'owner'.")]
public string Process(string text, IUrlHelper url, string timeline, long post)
{
return Process(