aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Models
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-11-27 00:07:09 +0800
committercrupest <crupest@outlook.com>2020-11-27 00:07:09 +0800
commit7883590a7a0c5c5c4e5cff6290e26c64e1258a25 (patch)
tree28e1ad4d02c4054e13b6cf539c64aba8d00df3e5 /BackEnd/Timeline/Models
parentce85af942c64fc3bad4e4502d683f730c882de96 (diff)
downloadtimeline-7883590a7a0c5c5c4e5cff6290e26c64e1258a25.tar.gz
timeline-7883590a7a0c5c5c4e5cff6290e26c64e1258a25.tar.bz2
timeline-7883590a7a0c5c5c4e5cff6290e26c64e1258a25.zip
refactor: ...
Diffstat (limited to 'BackEnd/Timeline/Models')
-rw-r--r--BackEnd/Timeline/Models/Http/Timeline.cs45
-rw-r--r--BackEnd/Timeline/Models/Http/TimelineController.cs21
-rw-r--r--BackEnd/Timeline/Models/Http/TokenController.cs20
-rw-r--r--BackEnd/Timeline/Models/Http/User.cs (renamed from BackEnd/Timeline/Models/Http/UserInfo.cs)26
-rw-r--r--BackEnd/Timeline/Models/Http/UserController.cs18
-rw-r--r--BackEnd/Timeline/Models/TimelineInfo.cs (renamed from BackEnd/Timeline/Models/Timeline.cs)52
-rw-r--r--BackEnd/Timeline/Models/User.cs21
-rw-r--r--BackEnd/Timeline/Models/UserInfo.cs48
8 files changed, 159 insertions, 92 deletions
diff --git a/BackEnd/Timeline/Models/Http/Timeline.cs b/BackEnd/Timeline/Models/Http/Timeline.cs
index a81b33f5..8e3831e1 100644
--- a/BackEnd/Timeline/Models/Http/Timeline.cs
+++ b/BackEnd/Timeline/Models/Http/Timeline.cs
@@ -11,7 +11,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Info of post content.
/// </summary>
- public class TimelinePostContentInfo
+ public class HttpTimelinePostContent
{
/// <summary>
/// Type of the post content.
@@ -34,7 +34,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Info of a post.
/// </summary>
- public class TimelinePostInfo
+ public class HttpTimelinePost
{
/// <summary>
/// Post id.
@@ -43,7 +43,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Content of the post. May be null if post is deleted.
/// </summary>
- public TimelinePostContentInfo? Content { get; set; }
+ public HttpTimelinePostContent? Content { get; set; }
/// <summary>
/// True if post is deleted.
/// </summary>
@@ -55,7 +55,7 @@ namespace Timeline.Models.Http
/// <summary>
/// The author. May be null if the user has been deleted.
/// </summary>
- public UserInfo? Author { get; set; } = default!;
+ public HttpUser? Author { get; set; } = default!;
/// <summary>
/// Last updated time.
/// </summary>
@@ -65,7 +65,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Info of a timeline.
/// </summary>
- public class TimelineInfo
+ public class HttpTimeline
{
/// <summary>
/// Unique id.
@@ -90,7 +90,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Owner of the timeline.
/// </summary>
- public UserInfo Owner { get; set; } = default!;
+ public HttpUser Owner { get; set; } = default!;
/// <summary>
/// Visibility of the timeline.
/// </summary>
@@ -99,7 +99,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Members of timeline.
/// </summary>
- public List<UserInfo> Members { get; set; } = default!;
+ public List<HttpUser> Members { get; set; } = default!;
#pragma warning restore CA2227 // Collection properties should be read only
/// <summary>
/// Create time of timeline.
@@ -114,14 +114,14 @@ namespace Timeline.Models.Http
/// <summary>
/// Related links.
/// </summary>
- public TimelineInfoLinks _links { get; set; } = default!;
+ public HttpTimelineLinks _links { get; set; } = default!;
#pragma warning restore CA1707 // Identifiers should not contain underscores
}
/// <summary>
/// Related links for timeline.
/// </summary>
- public class TimelineInfoLinks
+ public class HttpTimelineLinks
{
/// <summary>
/// Self.
@@ -133,23 +133,23 @@ namespace Timeline.Models.Http
public string Posts { get; set; } = default!;
}
- public class TimelineInfoLinksValueResolver : IValueResolver<Timeline, TimelineInfo, TimelineInfoLinks>
+ public class HttpTimelineLinksValueResolver : IValueResolver<TimelineInfo, HttpTimeline, HttpTimelineLinks>
{
private readonly IActionContextAccessor _actionContextAccessor;
private readonly IUrlHelperFactory _urlHelperFactory;
- public TimelineInfoLinksValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
+ public HttpTimelineLinksValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
{
_actionContextAccessor = actionContextAccessor;
_urlHelperFactory = urlHelperFactory;
}
- public TimelineInfoLinks Resolve(Timeline source, TimelineInfo destination, TimelineInfoLinks destMember, ResolutionContext context)
+ public HttpTimelineLinks Resolve(TimelineInfo source, HttpTimeline destination, HttpTimelineLinks destMember, ResolutionContext context)
{
var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
- return new TimelineInfoLinks
+ return new HttpTimelineLinks
{
Self = urlHelper.ActionLink(nameof(TimelineController.TimelineGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { source.Name }),
Posts = urlHelper.ActionLink(nameof(TimelineController.PostListGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { source.Name })
@@ -157,18 +157,18 @@ namespace Timeline.Models.Http
}
}
- public class TimelinePostContentResolver : IValueResolver<TimelinePost, TimelinePostInfo, TimelinePostContentInfo?>
+ public class HttpTimelinePostContentResolver : IValueResolver<TimelinePostInfo, HttpTimelinePost, HttpTimelinePostContent?>
{
private readonly IActionContextAccessor _actionContextAccessor;
private readonly IUrlHelperFactory _urlHelperFactory;
- public TimelinePostContentResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
+ public HttpTimelinePostContentResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
{
_actionContextAccessor = actionContextAccessor;
_urlHelperFactory = urlHelperFactory;
}
- public TimelinePostContentInfo? Resolve(TimelinePost source, TimelinePostInfo destination, TimelinePostContentInfo? destMember, ResolutionContext context)
+ public HttpTimelinePostContent? Resolve(TimelinePostInfo source, HttpTimelinePost destination, HttpTimelinePostContent? destMember, ResolutionContext context)
{
var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
@@ -182,7 +182,7 @@ namespace Timeline.Models.Http
if (sourceContent is TextTimelinePostContent textContent)
{
- return new TimelinePostContentInfo
+ return new HttpTimelinePostContent
{
Type = TimelinePostContentTypes.Text,
Text = textContent.Text
@@ -190,7 +190,7 @@ namespace Timeline.Models.Http
}
else if (sourceContent is ImageTimelinePostContent imageContent)
{
- return new TimelinePostContentInfo
+ return new HttpTimelinePostContent
{
Type = TimelinePostContentTypes.Image,
Url = urlHelper.ActionLink(
@@ -207,13 +207,12 @@ namespace Timeline.Models.Http
}
}
- public class TimelineInfoAutoMapperProfile : Profile
+ public class HttpTimelineAutoMapperProfile : Profile
{
- public TimelineInfoAutoMapperProfile()
+ public HttpTimelineAutoMapperProfile()
{
- CreateMap<Timeline, TimelineInfo>().ForMember(u => u._links, opt => opt.MapFrom<TimelineInfoLinksValueResolver>());
- CreateMap<TimelinePost, TimelinePostInfo>().ForMember(p => p.Content, opt => opt.MapFrom<TimelinePostContentResolver>());
- CreateMap<TimelinePatchRequest, TimelineChangePropertyRequest>();
+ CreateMap<TimelineInfo, HttpTimeline>().ForMember(u => u._links, opt => opt.MapFrom<HttpTimelineLinksValueResolver>());
+ CreateMap<TimelinePostInfo, HttpTimelinePost>().ForMember(p => p.Content, opt => opt.MapFrom<HttpTimelinePostContentResolver>());
}
}
}
diff --git a/BackEnd/Timeline/Models/Http/TimelineController.cs b/BackEnd/Timeline/Models/Http/TimelineController.cs
index 7bd141ed..42a926fd 100644
--- a/BackEnd/Timeline/Models/Http/TimelineController.cs
+++ b/BackEnd/Timeline/Models/Http/TimelineController.cs
@@ -1,4 +1,5 @@
-using System;
+using AutoMapper;
+using System;
using System.ComponentModel.DataAnnotations;
using Timeline.Models.Validation;
@@ -7,7 +8,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Content of post create request.
/// </summary>
- public class TimelinePostCreateRequestContent
+ public class HttpTimelinePostCreateRequestContent
{
/// <summary>
/// Type of post content.
@@ -24,13 +25,13 @@ namespace Timeline.Models.Http
public string? Data { get; set; }
}
- public class TimelinePostCreateRequest
+ public class HttpTimelinePostCreateRequest
{
/// <summary>
/// Content of the new post.
/// </summary>
[Required]
- public TimelinePostCreateRequestContent Content { get; set; } = default!;
+ public HttpTimelinePostCreateRequestContent Content { get; set; } = default!;
/// <summary>
/// Time of the post. If not set, current time will be used.
@@ -54,7 +55,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Patch timeline request model.
/// </summary>
- public class TimelinePatchRequest
+ public class HttpTimelinePatchRequest
{
/// <summary>
/// New title. Null for not change.
@@ -75,7 +76,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Change timeline name request model.
/// </summary>
- public class TimelineChangeNameRequest
+ public class HttpTimelineChangeNameRequest
{
/// <summary>
/// Old name of timeline.
@@ -90,4 +91,12 @@ namespace Timeline.Models.Http
[TimelineName]
public string NewName { get; set; } = default!;
}
+
+ public class HttpTimelineControllerAutoMapperProfile : Profile
+ {
+ public HttpTimelineControllerAutoMapperProfile()
+ {
+ CreateMap<HttpTimelinePatchRequest, TimelineChangePropertyRequest>();
+ }
+ }
}
diff --git a/BackEnd/Timeline/Models/Http/TokenController.cs b/BackEnd/Timeline/Models/Http/TokenController.cs
index a42c44e5..a5cbba14 100644
--- a/BackEnd/Timeline/Models/Http/TokenController.cs
+++ b/BackEnd/Timeline/Models/Http/TokenController.cs
@@ -4,9 +4,9 @@ using Timeline.Controllers;
namespace Timeline.Models.Http
{
/// <summary>
- /// Request model for <see cref="TokenController.Create(CreateTokenRequest)"/>.
+ /// Request model for <see cref="TokenController.Create(HttpCreateTokenRequest)"/>.
/// </summary>
- public class CreateTokenRequest
+ public class HttpCreateTokenRequest
{
/// <summary>
/// The username.
@@ -24,9 +24,9 @@ namespace Timeline.Models.Http
}
/// <summary>
- /// Response model for <see cref="TokenController.Create(CreateTokenRequest)"/>.
+ /// Response model for <see cref="TokenController.Create(HttpCreateTokenRequest)"/>.
/// </summary>
- public class CreateTokenResponse
+ public class HttpCreateTokenResponse
{
/// <summary>
/// The token created.
@@ -35,13 +35,13 @@ namespace Timeline.Models.Http
/// <summary>
/// The user owning the token.
/// </summary>
- public UserInfo User { get; set; } = default!;
+ public HttpUser User { get; set; } = default!;
}
/// <summary>
- /// Request model for <see cref="TokenController.Verify(VerifyTokenRequest)"/>.
+ /// Request model for <see cref="TokenController.Verify(HttpVerifyTokenRequest)"/>.
/// </summary>
- public class VerifyTokenRequest
+ public class HttpVerifyTokenRequest
{
/// <summary>
/// The token to verify.
@@ -50,13 +50,13 @@ namespace Timeline.Models.Http
}
/// <summary>
- /// Response model for <see cref="TokenController.Verify(VerifyTokenRequest)"/>.
+ /// Response model for <see cref="TokenController.Verify(HttpVerifyTokenRequest)"/>.
/// </summary>
- public class VerifyTokenResponse
+ public class HttpVerifyTokenResponse
{
/// <summary>
/// The user owning the token.
/// </summary>
- public UserInfo User { get; set; } = default!;
+ public HttpUser User { get; set; } = default!;
}
}
diff --git a/BackEnd/Timeline/Models/Http/UserInfo.cs b/BackEnd/Timeline/Models/Http/User.cs
index 0f865172..bdb40b9f 100644
--- a/BackEnd/Timeline/Models/Http/UserInfo.cs
+++ b/BackEnd/Timeline/Models/Http/User.cs
@@ -11,7 +11,7 @@ namespace Timeline.Models.Http
/// <summary>
/// Info of a user.
/// </summary>
- public class UserInfo
+ public class HttpUser
{
/// <summary>
/// Unique id.
@@ -35,14 +35,14 @@ namespace Timeline.Models.Http
/// <summary>
/// Related links.
/// </summary>
- public UserInfoLinks _links { get; set; } = default!;
+ public HttpUserLinks _links { get; set; } = default!;
#pragma warning restore CA1707 // Identifiers should not contain underscores
}
/// <summary>
/// Related links for user.
/// </summary>
- public class UserInfoLinks
+ public class HttpUserLinks
{
/// <summary>
/// Self.
@@ -58,7 +58,7 @@ namespace Timeline.Models.Http
public string Timeline { get; set; } = default!;
}
- public class UserPermissionsValueConverter : ITypeConverter<UserPermissions, List<string>>
+ public class HttpUserPermissionsValueConverter : ITypeConverter<UserPermissions, List<string>>
{
public List<string> Convert(UserPermissions source, List<string> destination, ResolutionContext context)
{
@@ -66,23 +66,23 @@ namespace Timeline.Models.Http
}
}
- public class UserInfoLinksValueResolver : IValueResolver<User, UserInfo, UserInfoLinks>
+ public class HttpUserLinksValueResolver : IValueResolver<UserInfo, HttpUser, HttpUserLinks>
{
private readonly IActionContextAccessor _actionContextAccessor;
private readonly IUrlHelperFactory _urlHelperFactory;
- public UserInfoLinksValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
+ public HttpUserLinksValueResolver(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
{
_actionContextAccessor = actionContextAccessor;
_urlHelperFactory = urlHelperFactory;
}
- public UserInfoLinks Resolve(User source, UserInfo destination, UserInfoLinks destMember, ResolutionContext context)
+ public HttpUserLinks Resolve(UserInfo source, HttpUser destination, HttpUserLinks destMember, ResolutionContext context)
{
var actionContext = _actionContextAccessor.AssertActionContextForUrlFill();
var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);
- var result = new UserInfoLinks
+ var result = new HttpUserLinks
{
Self = urlHelper.ActionLink(nameof(UserController.Get), nameof(UserController)[0..^nameof(Controller).Length], new { destination.Username }),
Avatar = urlHelper.ActionLink(nameof(UserAvatarController.Get), nameof(UserAvatarController)[0..^nameof(Controller).Length], new { destination.Username }),
@@ -92,14 +92,14 @@ namespace Timeline.Models.Http
}
}
- public class UserInfoAutoMapperProfile : Profile
+ public class HttpUserAutoMapperProfile : Profile
{
- public UserInfoAutoMapperProfile()
+ public HttpUserAutoMapperProfile()
{
CreateMap<UserPermissions, List<string>>()
- .ConvertUsing<UserPermissionsValueConverter>();
- CreateMap<User, UserInfo>()
- .ForMember(u => u._links, opt => opt.MapFrom<UserInfoLinksValueResolver>());
+ .ConvertUsing<HttpUserPermissionsValueConverter>();
+ CreateMap<UserInfo, HttpUser>()
+ .ForMember(u => u._links, opt => opt.MapFrom<HttpUserLinksValueResolver>());
}
}
}
diff --git a/BackEnd/Timeline/Models/Http/UserController.cs b/BackEnd/Timeline/Models/Http/UserController.cs
index 92a63874..1b4d09ec 100644
--- a/BackEnd/Timeline/Models/Http/UserController.cs
+++ b/BackEnd/Timeline/Models/Http/UserController.cs
@@ -7,9 +7,9 @@ using Timeline.Services;
namespace Timeline.Models.Http
{
/// <summary>
- /// Request model for <see cref="UserController.Patch(UserPatchRequest, string)"/>.
+ /// Request model for <see cref="UserController.Patch(HttpUserPatchRequest, string)"/>.
/// </summary>
- public class UserPatchRequest
+ public class HttpUserPatchRequest
{
/// <summary>
/// New username. Null if not change. Need to be administrator.
@@ -31,9 +31,9 @@ namespace Timeline.Models.Http
}
/// <summary>
- /// Request model for <see cref="UserController.CreateUser(CreateUserRequest)"/>.
+ /// Request model for <see cref="UserController.CreateUser(HttpCreateUserRequest)"/>.
/// </summary>
- public class CreateUserRequest
+ public class HttpCreateUserRequest
{
/// <summary>
/// Username of the new user.
@@ -49,9 +49,9 @@ namespace Timeline.Models.Http
}
/// <summary>
- /// Request model for <see cref="UserController.ChangePassword(ChangePasswordRequest)"/>.
+ /// Request model for <see cref="UserController.ChangePassword(HttpChangePasswordRequest)"/>.
/// </summary>
- public class ChangePasswordRequest
+ public class HttpChangePasswordRequest
{
/// <summary>
/// Old password.
@@ -66,11 +66,11 @@ namespace Timeline.Models.Http
public string NewPassword { get; set; } = default!;
}
- public class UserControllerAutoMapperProfile : Profile
+ public class HttpUserControllerModelAutoMapperProfile : Profile
{
- public UserControllerAutoMapperProfile()
+ public HttpUserControllerModelAutoMapperProfile()
{
- CreateMap<UserPatchRequest, ModifyUserParams>();
+ CreateMap<HttpUserPatchRequest, ModifyUserParams>();
}
}
}
diff --git a/BackEnd/Timeline/Models/Timeline.cs b/BackEnd/Timeline/Models/TimelineInfo.cs
index a5987577..440f6b81 100644
--- a/BackEnd/Timeline/Models/Timeline.cs
+++ b/BackEnd/Timeline/Models/TimelineInfo.cs
@@ -50,9 +50,14 @@ namespace Timeline.Models
public string DataTag { get; set; }
}
- public class TimelinePost
+ public record TimelinePostInfo
{
- public TimelinePost(long id, ITimelinePostContent? content, DateTime time, User? author, DateTime lastUpdated, string timelineName)
+ public TimelinePostInfo()
+ {
+
+ }
+
+ public TimelinePostInfo(long id, ITimelinePostContent? content, DateTime time, UserInfo? author, DateTime lastUpdated, string timelineName)
{
Id = id;
Content = content;
@@ -66,24 +71,51 @@ namespace Timeline.Models
public ITimelinePostContent? Content { get; set; }
public bool Deleted => Content == null;
public DateTime Time { get; set; }
- public User? Author { get; set; }
+ public UserInfo? Author { get; set; }
public DateTime LastUpdated { get; set; }
- public string TimelineName { get; set; }
+ public string TimelineName { get; set; } = default!;
}
-#pragma warning disable CA1724 // Type names should not match namespaces
- public class Timeline
-#pragma warning restore CA1724 // Type names should not match namespaces
+ public record TimelineInfo
{
- public string UniqueID { get; set; } = default!;
+ public TimelineInfo()
+ {
+
+ }
+
+ public TimelineInfo(
+ string uniqueId,
+ string name,
+ DateTime nameLastModified,
+ string title,
+ string description,
+ UserInfo owner,
+ TimelineVisibility visibility,
+ List<UserInfo> members,
+ DateTime createTime,
+ DateTime lastModified)
+ {
+ UniqueId = uniqueId;
+ Name = name;
+ NameLastModified = nameLastModified;
+ Title = title;
+ Description = description;
+ Owner = owner;
+ Visibility = visibility;
+ Members = members;
+ CreateTime = createTime;
+ LastModified = lastModified;
+ }
+
+ 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 UserInfo Owner { get; set; } = default!;
public TimelineVisibility Visibility { get; set; }
#pragma warning disable CA2227 // Collection properties should be read only
- public List<User> Members { get; set; } = default!;
+ public List<UserInfo> Members { get; set; } = default!;
#pragma warning restore CA2227 // Collection properties should be read only
public DateTime CreateTime { get; set; } = default!;
public DateTime LastModified { get; set; } = default!;
diff --git a/BackEnd/Timeline/Models/User.cs b/BackEnd/Timeline/Models/User.cs
deleted file mode 100644
index ae2afe85..00000000
--- a/BackEnd/Timeline/Models/User.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System;
-using Timeline.Services;
-
-namespace Timeline.Models
-{
- public record User
- {
- public long Id { get; set; }
- public string UniqueId { get; set; } = default!;
-
- public string Username { get; set; } = default!;
- public string Nickname { get; set; } = default!;
-
- public UserPermissions Permissions { get; set; } = default!;
-
- public DateTime UsernameChangeTime { get; set; }
- public DateTime CreateTime { get; set; }
- public DateTime LastModified { get; set; }
- public long Version { get; set; }
- }
-}
diff --git a/BackEnd/Timeline/Models/UserInfo.cs b/BackEnd/Timeline/Models/UserInfo.cs
new file mode 100644
index 00000000..058cc590
--- /dev/null
+++ b/BackEnd/Timeline/Models/UserInfo.cs
@@ -0,0 +1,48 @@
+using System;
+using Timeline.Services;
+
+namespace Timeline.Models
+{
+ public record UserInfo
+ {
+ public UserInfo()
+ {
+
+ }
+
+ public UserInfo(
+ long id,
+ string uniqueId,
+ string username,
+ string nickname,
+ UserPermissions permissions,
+ DateTime usernameChangeTime,
+ DateTime createTime,
+ DateTime lastModified,
+ long version)
+ {
+ Id = id;
+ UniqueId = uniqueId;
+ Username = username;
+ Nickname = nickname;
+ Permissions = permissions;
+ UsernameChangeTime = usernameChangeTime;
+ CreateTime = createTime;
+ LastModified = lastModified;
+ Version = version;
+ }
+
+ public long Id { get; set; }
+ public string UniqueId { get; set; } = default!;
+
+ public string Username { get; set; } = default!;
+ public string Nickname { get; set; } = default!;
+
+ public UserPermissions Permissions { get; set; } = default!;
+
+ public DateTime UsernameChangeTime { get; set; }
+ public DateTime CreateTime { get; set; }
+ public DateTime LastModified { get; set; }
+ public long Version { get; set; }
+ }
+}