From 0a0a61b60544a135a61394953bb5bb9dbbfeb241 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 2 Feb 2021 18:59:41 +0800 Subject: ... --- BackEnd/Timeline/Models/Http/BookmarkTimeline.cs | 23 --- BackEnd/Timeline/Models/Http/HighlightTimeline.cs | 23 --- .../Timeline/Models/Http/HttpAutoMapperProfile.cs | 15 ++ .../Models/Http/HttpBookmarkTimelineMoveRequest.cs | 23 +++ .../Models/Http/HttpChangePasswordRequest.cs | 23 +++ .../Timeline/Models/Http/HttpCreateTokenRequest.cs | 25 +++ .../Models/Http/HttpCreateTokenResponse.cs | 19 +++ .../Timeline/Models/Http/HttpCreateUserRequest.cs | 24 +++ .../Http/HttpHighlightTimelineMoveRequest.cs | 23 +++ BackEnd/Timeline/Models/Http/HttpTimeline.cs | 89 ++++++++++ .../Models/Http/HttpTimelineCreateRequest.cs | 18 ++ BackEnd/Timeline/Models/Http/HttpTimelineLinks.cs | 26 +++ .../Models/Http/HttpTimelinePatchRequest.cs | 37 +++++ BackEnd/Timeline/Models/Http/HttpTimelinePost.cs | 47 ++++++ .../Models/Http/HttpTimelinePostContent.cs | 35 ++++ .../Models/Http/HttpTimelinePostCreateRequest.cs | 19 +++ .../Http/HttpTimelinePostCreateRequestContent.cs | 24 +++ BackEnd/Timeline/Models/Http/HttpUser.cs | 46 ++++++ BackEnd/Timeline/Models/Http/HttpUserLinks.cs | 31 ++++ .../Timeline/Models/Http/HttpUserPatchRequest.cs | 30 ++++ .../Timeline/Models/Http/HttpVerifyTokenRequest.cs | 15 ++ .../Models/Http/HttpVerifyTokenResponse.cs | 16 ++ BackEnd/Timeline/Models/Http/Timeline.cs | 183 --------------------- BackEnd/Timeline/Models/Http/TimelineController.cs | 90 ---------- BackEnd/Timeline/Models/Http/TokenController.cs | 62 ------- BackEnd/Timeline/Models/Http/User.cs | 74 --------- BackEnd/Timeline/Models/Http/UserController.cs | 76 --------- BackEnd/Timeline/Models/Mapper/TimelineMapper.cs | 1 + .../Timeline/Models/Validation/ColorValidator.cs | 40 +++++ 29 files changed, 626 insertions(+), 531 deletions(-) delete mode 100644 BackEnd/Timeline/Models/Http/BookmarkTimeline.cs delete mode 100644 BackEnd/Timeline/Models/Http/HighlightTimeline.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpAutoMapperProfile.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpBookmarkTimelineMoveRequest.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpChangePasswordRequest.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpCreateTokenRequest.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpCreateTokenResponse.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpCreateUserRequest.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpHighlightTimelineMoveRequest.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpTimeline.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpTimelineCreateRequest.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpTimelineLinks.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpTimelinePatchRequest.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpTimelinePost.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpTimelinePostContent.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequestContent.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpUser.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpUserLinks.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpUserPatchRequest.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpVerifyTokenRequest.cs create mode 100644 BackEnd/Timeline/Models/Http/HttpVerifyTokenResponse.cs delete mode 100644 BackEnd/Timeline/Models/Http/Timeline.cs delete mode 100644 BackEnd/Timeline/Models/Http/TimelineController.cs delete mode 100644 BackEnd/Timeline/Models/Http/TokenController.cs delete mode 100644 BackEnd/Timeline/Models/Http/User.cs delete mode 100644 BackEnd/Timeline/Models/Http/UserController.cs create mode 100644 BackEnd/Timeline/Models/Validation/ColorValidator.cs (limited to 'BackEnd/Timeline/Models') diff --git a/BackEnd/Timeline/Models/Http/BookmarkTimeline.cs b/BackEnd/Timeline/Models/Http/BookmarkTimeline.cs deleted file mode 100644 index 14be1112..00000000 --- a/BackEnd/Timeline/Models/Http/BookmarkTimeline.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using Timeline.Models.Validation; - -namespace Timeline.Models.Http -{ - /// - /// Move bookmark timeline request body model. - /// - public class HttpBookmarkTimelineMoveRequest - { - /// - /// Timeline name. - /// - [GeneralTimelineName] - public string Timeline { get; set; } = default!; - - /// - /// New position, starting at 1. - /// - [Required] - public long? NewPosition { get; set; } - } -} diff --git a/BackEnd/Timeline/Models/Http/HighlightTimeline.cs b/BackEnd/Timeline/Models/Http/HighlightTimeline.cs deleted file mode 100644 index 5af0e528..00000000 --- a/BackEnd/Timeline/Models/Http/HighlightTimeline.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using Timeline.Models.Validation; - -namespace Timeline.Models.Http -{ - /// - /// Move highlight timeline request body model. - /// - public class HttpHighlightTimelineMoveRequest - { - /// - /// Timeline name. - /// - [GeneralTimelineName] - public string Timeline { get; set; } = default!; - - /// - /// New position, starting at 1. - /// - [Required] - public long? NewPosition { get; set; } - } -} diff --git a/BackEnd/Timeline/Models/Http/HttpAutoMapperProfile.cs b/BackEnd/Timeline/Models/Http/HttpAutoMapperProfile.cs new file mode 100644 index 00000000..426379b8 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpAutoMapperProfile.cs @@ -0,0 +1,15 @@ +using AutoMapper; +using Timeline.Services; + +namespace Timeline.Models.Http +{ + + public class HttpAutoMapperProfile : Profile + { + public HttpAutoMapperProfile() + { + CreateMap(); + CreateMap(); + } + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpBookmarkTimelineMoveRequest.cs b/BackEnd/Timeline/Models/Http/HttpBookmarkTimelineMoveRequest.cs new file mode 100644 index 00000000..14be1112 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpBookmarkTimelineMoveRequest.cs @@ -0,0 +1,23 @@ +using System.ComponentModel.DataAnnotations; +using Timeline.Models.Validation; + +namespace Timeline.Models.Http +{ + /// + /// Move bookmark timeline request body model. + /// + public class HttpBookmarkTimelineMoveRequest + { + /// + /// Timeline name. + /// + [GeneralTimelineName] + public string Timeline { get; set; } = default!; + + /// + /// New position, starting at 1. + /// + [Required] + public long? NewPosition { get; set; } + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpChangePasswordRequest.cs b/BackEnd/Timeline/Models/Http/HttpChangePasswordRequest.cs new file mode 100644 index 00000000..0397d7ce --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpChangePasswordRequest.cs @@ -0,0 +1,23 @@ +using System.ComponentModel.DataAnnotations; +using Timeline.Controllers; + +namespace Timeline.Models.Http +{ + /// + /// Request model for . + /// + public class HttpChangePasswordRequest + { + /// + /// Old password. + /// + [Required(AllowEmptyStrings = false)] + public string OldPassword { get; set; } = default!; + + /// + /// New password. + /// + [Required(AllowEmptyStrings = false)] + public string NewPassword { get; set; } = default!; + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpCreateTokenRequest.cs b/BackEnd/Timeline/Models/Http/HttpCreateTokenRequest.cs new file mode 100644 index 00000000..2a20d490 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpCreateTokenRequest.cs @@ -0,0 +1,25 @@ +using System.ComponentModel.DataAnnotations; +using Timeline.Controllers; + +namespace Timeline.Models.Http +{ + /// + /// Request model for . + /// + public class HttpCreateTokenRequest + { + /// + /// The username. + /// + public string Username { get; set; } = default!; + /// + /// The password. + /// + public string Password { get; set; } = default!; + /// + /// Optional token validation period. In days. If not specified, server will use a default one. + /// + [Range(1, 365)] + public int? Expire { get; set; } + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpCreateTokenResponse.cs b/BackEnd/Timeline/Models/Http/HttpCreateTokenResponse.cs new file mode 100644 index 00000000..78dd43c5 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpCreateTokenResponse.cs @@ -0,0 +1,19 @@ +using Timeline.Controllers; + +namespace Timeline.Models.Http +{ + /// + /// Response model for . + /// + public class HttpCreateTokenResponse + { + /// + /// The token created. + /// + public string Token { get; set; } = default!; + /// + /// The user owning the token. + /// + public HttpUser User { get; set; } = default!; + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpCreateUserRequest.cs b/BackEnd/Timeline/Models/Http/HttpCreateUserRequest.cs new file mode 100644 index 00000000..7b221f73 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpCreateUserRequest.cs @@ -0,0 +1,24 @@ +using System.ComponentModel.DataAnnotations; +using Timeline.Controllers; +using Timeline.Models.Validation; + +namespace Timeline.Models.Http +{ + /// + /// Request model for . + /// + public class HttpCreateUserRequest + { + /// + /// Username of the new user. + /// + [Required, Username] + public string Username { get; set; } = default!; + + /// + /// Password of the new user. + /// + [Required, MinLength(1)] + public string Password { get; set; } = default!; + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpHighlightTimelineMoveRequest.cs b/BackEnd/Timeline/Models/Http/HttpHighlightTimelineMoveRequest.cs new file mode 100644 index 00000000..5af0e528 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpHighlightTimelineMoveRequest.cs @@ -0,0 +1,23 @@ +using System.ComponentModel.DataAnnotations; +using Timeline.Models.Validation; + +namespace Timeline.Models.Http +{ + /// + /// Move highlight timeline request body model. + /// + public class HttpHighlightTimelineMoveRequest + { + /// + /// Timeline name. + /// + [GeneralTimelineName] + public string Timeline { get; set; } = default!; + + /// + /// New position, starting at 1. + /// + [Required] + public long? NewPosition { get; set; } + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpTimeline.cs b/BackEnd/Timeline/Models/Http/HttpTimeline.cs new file mode 100644 index 00000000..87ebf0bb --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpTimeline.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; + +namespace Timeline.Models.Http +{ + /// + /// Info of a timeline. + /// + public class HttpTimeline + { + public HttpTimeline() { } + + public HttpTimeline(string uniqueId, string title, string name, DateTime nameLastModifed, string description, HttpUser owner, TimelineVisibility visibility, List members, string? color, DateTime createTime, DateTime lastModified, bool isHighlight, bool isBookmark, HttpTimelineLinks links) + { + UniqueId = uniqueId; + Title = title; + Name = name; + NameLastModifed = nameLastModifed; + Description = description; + Owner = owner; + Visibility = visibility; + Members = members; + Color = color; + CreateTime = createTime; + LastModified = lastModified; + IsHighlight = isHighlight; + IsBookmark = isBookmark; + _links = links; + } + + /// + /// Unique id. + /// + public string UniqueId { get; set; } = default!; + /// + /// Title. + /// + public string Title { get; set; } = default!; + /// + /// Name of timeline. + /// + public string Name { get; set; } = default!; + /// + /// Last modified time of timeline name. + /// + public DateTime NameLastModifed { get; set; } = default!; + /// + /// Timeline description. + /// + public string Description { get; set; } = default!; + /// + /// Owner of the timeline. + /// + public HttpUser Owner { get; set; } = default!; + /// + /// Visibility of the timeline. + /// + public TimelineVisibility Visibility { get; set; } +#pragma warning disable CA2227 // Collection properties should be read only + /// + /// Members of timeline. + /// + public List Members { get; set; } = default!; +#pragma warning restore CA2227 // Collection properties should be read only + /// + /// Color of timeline. + /// + public string? Color { get; set; } + /// + /// Create time of timeline. + /// + public DateTime CreateTime { get; set; } = default!; + /// + /// Last modified time of timeline. + /// + public DateTime LastModified { get; set; } = default!; + + public bool IsHighlight { get; set; } + + public bool IsBookmark { get; set; } + +#pragma warning disable CA1707 // Identifiers should not contain underscores + /// + /// Related links. + /// + public HttpTimelineLinks _links { get; set; } = default!; +#pragma warning restore CA1707 // Identifiers should not contain underscores + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpTimelineCreateRequest.cs b/BackEnd/Timeline/Models/Http/HttpTimelineCreateRequest.cs new file mode 100644 index 00000000..e9f57e46 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpTimelineCreateRequest.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; +using Timeline.Models.Validation; + +namespace Timeline.Models.Http +{ + /// + /// Create timeline request model. + /// + public class HttpTimelineCreateRequest + { + /// + /// Name of the new timeline. Must be a valid name. + /// + [Required] + [TimelineName] + public string Name { get; set; } = default!; + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpTimelineLinks.cs b/BackEnd/Timeline/Models/Http/HttpTimelineLinks.cs new file mode 100644 index 00000000..722c1338 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpTimelineLinks.cs @@ -0,0 +1,26 @@ +namespace Timeline.Models.Http +{ + + /// + /// Related links for timeline. + /// + public class HttpTimelineLinks + { + public HttpTimelineLinks() { } + + public HttpTimelineLinks(string self, string posts) + { + Self = self; + Posts = posts; + } + + /// + /// Self. + /// + public string Self { get; set; } = default!; + /// + /// Posts url. + /// + public string Posts { get; set; } = default!; + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePatchRequest.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePatchRequest.cs new file mode 100644 index 00000000..9accb6fc --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpTimelinePatchRequest.cs @@ -0,0 +1,37 @@ +using Timeline.Models.Validation; + +namespace Timeline.Models.Http +{ + /// + /// Patch timeline request model. + /// + public class HttpTimelinePatchRequest + { + /// + /// New name. Null for not change. + /// + [TimelineName] + public string? Name { get; set; } + + /// + /// New title. Null for not change. + /// + public string? Title { get; set; } + + /// + /// New description. Null for not change. + /// + public string? Description { get; set; } + + /// + /// New visibility. Null for not change. + /// + public TimelineVisibility? Visibility { get; set; } + + /// + /// New color. Null for not change. + /// + [Color] + public string? Color { get; set; } + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs new file mode 100644 index 00000000..a563bea0 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpTimelinePost.cs @@ -0,0 +1,47 @@ +using System; + +namespace Timeline.Models.Http +{ + /// + /// Info of a post. + /// + public class HttpTimelinePost + { + public HttpTimelinePost() { } + + public HttpTimelinePost(long id, HttpTimelinePostContent? content, bool deleted, DateTime time, HttpUser? author, DateTime lastUpdated) + { + Id = id; + Content = content; + Deleted = deleted; + Time = time; + Author = author; + LastUpdated = lastUpdated; + } + + /// + /// Post id. + /// + public long Id { get; set; } + /// + /// Content of the post. May be null if post is deleted. + /// + public HttpTimelinePostContent? Content { get; set; } + /// + /// True if post is deleted. + /// + public bool Deleted { get; set; } + /// + /// Post time. + /// + public DateTime Time { get; set; } + /// + /// The author. May be null if the user has been deleted. + /// + public HttpUser? Author { get; set; } = default!; + /// + /// Last updated time. + /// + public DateTime LastUpdated { get; set; } = default!; + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePostContent.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePostContent.cs new file mode 100644 index 00000000..55ff1ac2 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpTimelinePostContent.cs @@ -0,0 +1,35 @@ +namespace Timeline.Models.Http +{ + /// + /// Info of post content. + /// + public class HttpTimelinePostContent + { + public HttpTimelinePostContent() { } + + public HttpTimelinePostContent(string type, string? text, string? url, string? eTag) + { + Type = type; + Text = text; + Url = url; + ETag = eTag; + } + + /// + /// Type of the post content. + /// + public string Type { get; set; } = default!; + /// + /// If post is of text type. This is the text. + /// + public string? Text { get; set; } + /// + /// If post is of image type. This is the image url. + /// + public string? Url { get; set; } + /// + /// If post has data (currently it means it's a image post), this is the data etag. + /// + public string? ETag { get; set; } + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs new file mode 100644 index 00000000..cfbec029 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequest.cs @@ -0,0 +1,19 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace Timeline.Models.Http +{ + public class HttpTimelinePostCreateRequest + { + /// + /// Content of the new post. + /// + [Required] + public HttpTimelinePostCreateRequestContent Content { get; set; } = default!; + + /// + /// Time of the post. If not set, current time will be used. + /// + public DateTime? Time { get; set; } + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequestContent.cs b/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequestContent.cs new file mode 100644 index 00000000..f4b300a9 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpTimelinePostCreateRequestContent.cs @@ -0,0 +1,24 @@ +using System.ComponentModel.DataAnnotations; + +namespace Timeline.Models.Http +{ + /// + /// Content of post create request. + /// + public class HttpTimelinePostCreateRequestContent + { + /// + /// Type of post content. + /// + [Required] + public string Type { get; set; } = default!; + /// + /// If post is of text type, this is the text. + /// + public string? Text { get; set; } + /// + /// If post is of image type, this is base64 of image data. + /// + public string? Data { get; set; } + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpUser.cs b/BackEnd/Timeline/Models/Http/HttpUser.cs new file mode 100644 index 00000000..4b82264c --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpUser.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; + +namespace Timeline.Models.Http +{ + /// + /// Info of a user. + /// + public class HttpUser + { + public HttpUser() { } + + public HttpUser(string uniqueId, string username, string nickname, List permissions, HttpUserLinks links) + { + UniqueId = uniqueId; + Username = username; + Nickname = nickname; + Permissions = permissions; + _links = links; + } + + /// + /// Unique id. + /// + public string UniqueId { get; set; } = default!; + /// + /// Username. + /// + public string Username { get; set; } = default!; + /// + /// Nickname. + /// + public string Nickname { get; set; } = default!; +#pragma warning disable CA2227 // Collection properties should be read only + /// + /// The permissions of the user. + /// + public List Permissions { get; set; } = default!; +#pragma warning restore CA2227 // Collection properties should be read only +#pragma warning disable CA1707 // Identifiers should not contain underscores + /// + /// Related links. + /// + public HttpUserLinks _links { get; set; } = default!; +#pragma warning restore CA1707 // Identifiers should not contain underscores + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpUserLinks.cs b/BackEnd/Timeline/Models/Http/HttpUserLinks.cs new file mode 100644 index 00000000..d5f909c2 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpUserLinks.cs @@ -0,0 +1,31 @@ +namespace Timeline.Models.Http +{ + + /// + /// Related links for user. + /// + public class HttpUserLinks + { + public HttpUserLinks() { } + + public HttpUserLinks(string self, string avatar, string timeline) + { + Self = self; + Avatar = avatar; + Timeline = timeline; + } + + /// + /// Self. + /// + public string Self { get; set; } = default!; + /// + /// Avatar url. + /// + public string Avatar { get; set; } = default!; + /// + /// Personal timeline url. + /// + public string Timeline { get; set; } = default!; + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpUserPatchRequest.cs b/BackEnd/Timeline/Models/Http/HttpUserPatchRequest.cs new file mode 100644 index 00000000..e7a3d8e3 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpUserPatchRequest.cs @@ -0,0 +1,30 @@ +using System.ComponentModel.DataAnnotations; +using Timeline.Controllers; +using Timeline.Models.Validation; + +namespace Timeline.Models.Http +{ + /// + /// Request model for . + /// + public class HttpUserPatchRequest + { + /// + /// New username. Null if not change. Need to be administrator. + /// + [Username] + public string? Username { get; set; } + + /// + /// New password. Null if not change. Need to be administrator. + /// + [MinLength(1)] + public string? Password { get; set; } + + /// + /// New nickname. Null if not change. Need to be administrator to change other's. + /// + [Nickname] + public string? Nickname { get; set; } + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpVerifyTokenRequest.cs b/BackEnd/Timeline/Models/Http/HttpVerifyTokenRequest.cs new file mode 100644 index 00000000..98f86455 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpVerifyTokenRequest.cs @@ -0,0 +1,15 @@ +using Timeline.Controllers; + +namespace Timeline.Models.Http +{ + /// + /// Request model for . + /// + public class HttpVerifyTokenRequest + { + /// + /// The token to verify. + /// + public string Token { get; set; } = default!; + } +} diff --git a/BackEnd/Timeline/Models/Http/HttpVerifyTokenResponse.cs b/BackEnd/Timeline/Models/Http/HttpVerifyTokenResponse.cs new file mode 100644 index 00000000..ae8eb018 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/HttpVerifyTokenResponse.cs @@ -0,0 +1,16 @@ +using Timeline.Controllers; + +namespace Timeline.Models.Http +{ + + /// + /// Response model for . + /// + public class HttpVerifyTokenResponse + { + /// + /// The user owning the token. + /// + public HttpUser User { get; set; } = default!; + } +} diff --git a/BackEnd/Timeline/Models/Http/Timeline.cs b/BackEnd/Timeline/Models/Http/Timeline.cs deleted file mode 100644 index 5e5889f6..00000000 --- a/BackEnd/Timeline/Models/Http/Timeline.cs +++ /dev/null @@ -1,183 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Timeline.Models.Http -{ - /// - /// Info of post content. - /// - public class HttpTimelinePostContent - { - public HttpTimelinePostContent() { } - - public HttpTimelinePostContent(string type, string? text, string? url, string? eTag) - { - Type = type; - Text = text; - Url = url; - ETag = eTag; - } - - /// - /// Type of the post content. - /// - public string Type { get; set; } = default!; - /// - /// If post is of text type. This is the text. - /// - public string? Text { get; set; } - /// - /// If post is of image type. This is the image url. - /// - public string? Url { get; set; } - /// - /// If post has data (currently it means it's a image post), this is the data etag. - /// - public string? ETag { get; set; } - } - - /// - /// Info of a post. - /// - public class HttpTimelinePost - { - public HttpTimelinePost() { } - - public HttpTimelinePost(long id, HttpTimelinePostContent? content, bool deleted, DateTime time, HttpUser? author, DateTime lastUpdated) - { - Id = id; - Content = content; - Deleted = deleted; - Time = time; - Author = author; - LastUpdated = lastUpdated; - } - - /// - /// Post id. - /// - public long Id { get; set; } - /// - /// Content of the post. May be null if post is deleted. - /// - public HttpTimelinePostContent? Content { get; set; } - /// - /// True if post is deleted. - /// - public bool Deleted { get; set; } - /// - /// Post time. - /// - public DateTime Time { get; set; } - /// - /// The author. May be null if the user has been deleted. - /// - public HttpUser? Author { get; set; } = default!; - /// - /// Last updated time. - /// - public DateTime LastUpdated { get; set; } = default!; - } - - /// - /// Info of a timeline. - /// - public class HttpTimeline - { - public HttpTimeline() { } - - public HttpTimeline(string uniqueId, string title, string name, DateTime nameLastModifed, string description, HttpUser owner, TimelineVisibility visibility, List members, DateTime createTime, DateTime lastModified, bool isHighlight, bool isBookmark, HttpTimelineLinks links) - { - UniqueId = uniqueId; - Title = title; - Name = name; - NameLastModifed = nameLastModifed; - Description = description; - Owner = owner; - Visibility = visibility; - Members = members; - CreateTime = createTime; - LastModified = lastModified; - IsHighlight = isHighlight; - IsBookmark = isBookmark; - _links = links; - } - - /// - /// Unique id. - /// - public string UniqueId { get; set; } = default!; - /// - /// Title. - /// - public string Title { get; set; } = default!; - /// - /// Name of timeline. - /// - public string Name { get; set; } = default!; - /// - /// Last modified time of timeline name. - /// - public DateTime NameLastModifed { get; set; } = default!; - /// - /// Timeline description. - /// - public string Description { get; set; } = default!; - /// - /// Owner of the timeline. - /// - public HttpUser Owner { get; set; } = default!; - /// - /// Visibility of the timeline. - /// - public TimelineVisibility Visibility { get; set; } -#pragma warning disable CA2227 // Collection properties should be read only - /// - /// Members of timeline. - /// - public List Members { get; set; } = default!; -#pragma warning restore CA2227 // Collection properties should be read only - /// - /// Create time of timeline. - /// - public DateTime CreateTime { get; set; } = default!; - /// - /// Last modified time of timeline. - /// - public DateTime LastModified { get; set; } = default!; - - public bool IsHighlight { get; set; } - - public bool IsBookmark { get; set; } - -#pragma warning disable CA1707 // Identifiers should not contain underscores - /// - /// Related links. - /// - public HttpTimelineLinks _links { get; set; } = default!; -#pragma warning restore CA1707 // Identifiers should not contain underscores - } - - /// - /// Related links for timeline. - /// - public class HttpTimelineLinks - { - public HttpTimelineLinks() { } - - public HttpTimelineLinks(string self, string posts) - { - Self = self; - Posts = posts; - } - - /// - /// Self. - /// - public string Self { get; set; } = default!; - /// - /// Posts url. - /// - public string Posts { get; set; } = default!; - } -} diff --git a/BackEnd/Timeline/Models/Http/TimelineController.cs b/BackEnd/Timeline/Models/Http/TimelineController.cs deleted file mode 100644 index 79be1826..00000000 --- a/BackEnd/Timeline/Models/Http/TimelineController.cs +++ /dev/null @@ -1,90 +0,0 @@ -using AutoMapper; -using System; -using System.ComponentModel.DataAnnotations; -using Timeline.Models.Validation; -using Timeline.Services; - -namespace Timeline.Models.Http -{ - /// - /// Content of post create request. - /// - public class HttpTimelinePostCreateRequestContent - { - /// - /// Type of post content. - /// - [Required] - public string Type { get; set; } = default!; - /// - /// If post is of text type, this is the text. - /// - public string? Text { get; set; } - /// - /// If post is of image type, this is base64 of image data. - /// - public string? Data { get; set; } - } - - public class HttpTimelinePostCreateRequest - { - /// - /// Content of the new post. - /// - [Required] - public HttpTimelinePostCreateRequestContent Content { get; set; } = default!; - - /// - /// Time of the post. If not set, current time will be used. - /// - public DateTime? Time { get; set; } - } - - /// - /// Create timeline request model. - /// - public class HttpTimelineCreateRequest - { - /// - /// Name of the new timeline. Must be a valid name. - /// - [Required] - [TimelineName] - public string Name { get; set; } = default!; - } - - /// - /// Patch timeline request model. - /// - public class HttpTimelinePatchRequest - { - /// - /// New name. Null for not change. - /// - [TimelineName] - public string? Name { get; set; } - - /// - /// New title. Null for not change. - /// - public string? Title { get; set; } - - /// - /// New description. Null for not change. - /// - public string? Description { get; set; } - - /// - /// New visibility. Null for not change. - /// - public TimelineVisibility? Visibility { get; set; } - } - - public class HttpTimelineControllerAutoMapperProfile : Profile - { - public HttpTimelineControllerAutoMapperProfile() - { - CreateMap(); - } - } -} diff --git a/BackEnd/Timeline/Models/Http/TokenController.cs b/BackEnd/Timeline/Models/Http/TokenController.cs deleted file mode 100644 index a5cbba14..00000000 --- a/BackEnd/Timeline/Models/Http/TokenController.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using Timeline.Controllers; - -namespace Timeline.Models.Http -{ - /// - /// Request model for . - /// - public class HttpCreateTokenRequest - { - /// - /// The username. - /// - public string Username { get; set; } = default!; - /// - /// The password. - /// - public string Password { get; set; } = default!; - /// - /// Optional token validation period. In days. If not specified, server will use a default one. - /// - [Range(1, 365)] - public int? Expire { get; set; } - } - - /// - /// Response model for . - /// - public class HttpCreateTokenResponse - { - /// - /// The token created. - /// - public string Token { get; set; } = default!; - /// - /// The user owning the token. - /// - public HttpUser User { get; set; } = default!; - } - - /// - /// Request model for . - /// - public class HttpVerifyTokenRequest - { - /// - /// The token to verify. - /// - public string Token { get; set; } = default!; - } - - /// - /// Response model for . - /// - public class HttpVerifyTokenResponse - { - /// - /// The user owning the token. - /// - public HttpUser User { get; set; } = default!; - } -} diff --git a/BackEnd/Timeline/Models/Http/User.cs b/BackEnd/Timeline/Models/Http/User.cs deleted file mode 100644 index 994c08bf..00000000 --- a/BackEnd/Timeline/Models/Http/User.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Collections.Generic; - -namespace Timeline.Models.Http -{ - /// - /// Info of a user. - /// - public class HttpUser - { - public HttpUser() { } - - public HttpUser(string uniqueId, string username, string nickname, List permissions, HttpUserLinks links) - { - UniqueId = uniqueId; - Username = username; - Nickname = nickname; - Permissions = permissions; - _links = links; - } - - /// - /// Unique id. - /// - public string UniqueId { get; set; } = default!; - /// - /// Username. - /// - public string Username { get; set; } = default!; - /// - /// Nickname. - /// - public string Nickname { get; set; } = default!; -#pragma warning disable CA2227 // Collection properties should be read only - /// - /// The permissions of the user. - /// - public List Permissions { get; set; } = default!; -#pragma warning restore CA2227 // Collection properties should be read only -#pragma warning disable CA1707 // Identifiers should not contain underscores - /// - /// Related links. - /// - public HttpUserLinks _links { get; set; } = default!; -#pragma warning restore CA1707 // Identifiers should not contain underscores - } - - /// - /// Related links for user. - /// - public class HttpUserLinks - { - public HttpUserLinks() { } - - public HttpUserLinks(string self, string avatar, string timeline) - { - Self = self; - Avatar = avatar; - Timeline = timeline; - } - - /// - /// Self. - /// - public string Self { get; set; } = default!; - /// - /// Avatar url. - /// - public string Avatar { get; set; } = default!; - /// - /// Personal timeline url. - /// - public string Timeline { get; set; } = default!; - } -} diff --git a/BackEnd/Timeline/Models/Http/UserController.cs b/BackEnd/Timeline/Models/Http/UserController.cs deleted file mode 100644 index 1b4d09ec..00000000 --- a/BackEnd/Timeline/Models/Http/UserController.cs +++ /dev/null @@ -1,76 +0,0 @@ -using AutoMapper; -using System.ComponentModel.DataAnnotations; -using Timeline.Controllers; -using Timeline.Models.Validation; -using Timeline.Services; - -namespace Timeline.Models.Http -{ - /// - /// Request model for . - /// - public class HttpUserPatchRequest - { - /// - /// New username. Null if not change. Need to be administrator. - /// - [Username] - public string? Username { get; set; } - - /// - /// New password. Null if not change. Need to be administrator. - /// - [MinLength(1)] - public string? Password { get; set; } - - /// - /// New nickname. Null if not change. Need to be administrator to change other's. - /// - [Nickname] - public string? Nickname { get; set; } - } - - /// - /// Request model for . - /// - public class HttpCreateUserRequest - { - /// - /// Username of the new user. - /// - [Required, Username] - public string Username { get; set; } = default!; - - /// - /// Password of the new user. - /// - [Required, MinLength(1)] - public string Password { get; set; } = default!; - } - - /// - /// Request model for . - /// - public class HttpChangePasswordRequest - { - /// - /// Old password. - /// - [Required(AllowEmptyStrings = false)] - public string OldPassword { get; set; } = default!; - - /// - /// New password. - /// - [Required(AllowEmptyStrings = false)] - public string NewPassword { get; set; } = default!; - } - - public class HttpUserControllerModelAutoMapperProfile : Profile - { - public HttpUserControllerModelAutoMapperProfile() - { - CreateMap(); - } - } -} diff --git a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs index 79a6fa1d..25abf0ba 100644 --- a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs +++ b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs @@ -42,6 +42,7 @@ namespace Timeline.Models.Mapper owner: await _userMapper.MapToHttp(entity.Owner, urlHelper), visibility: entity.Visibility, members: await _userMapper.MapToHttp(entity.Members.Select(m => m.User).ToList(), urlHelper), + color: entity.Color, createTime: entity.CreateTime, lastModified: entity.LastModified, isHighlight: await _highlightTimelineService.IsHighlightTimeline(entity.Id), diff --git a/BackEnd/Timeline/Models/Validation/ColorValidator.cs b/BackEnd/Timeline/Models/Validation/ColorValidator.cs new file mode 100644 index 00000000..c5ad833d --- /dev/null +++ b/BackEnd/Timeline/Models/Validation/ColorValidator.cs @@ -0,0 +1,40 @@ +using System; + +namespace Timeline.Models.Validation +{ + public class ColorValidator : Validator + { + protected override (bool, string) DoValidate(string value) + { + if (!value.StartsWith('#')) + { + return (false, "Color must starts with '#'."); + } + + if (value.Length != 7) + { + return (false, "A color string must have 7 chars."); + } + + for (int i = 1; i < 7; i++) + { + var c = value[i]; + if (!((c >= '0' && c <= '9') || (c >= 'a' || c <= 'f') || (c >= 'A' | c <= 'F'))) + { + return (false, $"Char at index {i} is not a hex character."); + } + } + + return (true, GetSuccessMessage()); + } + } + + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)] + public class ColorAttribute : ValidateWithAttribute + { + public ColorAttribute() : base(typeof(ColorValidator)) + { + + } + } +} -- cgit v1.2.3