aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Services/Mapper
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 /BackEnd/Timeline/Services/Mapper
parent3bc8ee1de171f0bd8e226542d75c842c5b2e7175 (diff)
downloadtimeline-69c760dbbbdb774957316a98bc135e69d8328dd8.tar.gz
timeline-69c760dbbbdb774957316a98bc135e69d8328dd8.tar.bz2
timeline-69c760dbbbdb774957316a98bc135e69d8328dd8.zip
...
Diffstat (limited to 'BackEnd/Timeline/Services/Mapper')
-rw-r--r--BackEnd/Timeline/Services/Mapper/TimelineMapper.cs15
-rw-r--r--BackEnd/Timeline/Services/Mapper/UserMapper.cs6
2 files changed, 14 insertions, 7 deletions
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.")
)
);
}