From 32fdf425e6b4f4edfb727fb3c0cbebe2c87fd663 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 20 Aug 2020 00:39:09 +0800 Subject: ... --- Timeline/Models/Http/Common.cs | 11 ++++++++ Timeline/Models/Http/TokenController.cs | 38 +++++++++++++++++++++++--- Timeline/Models/Http/UserController.cs | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 4 deletions(-) (limited to 'Timeline/Models/Http') diff --git a/Timeline/Models/Http/Common.cs b/Timeline/Models/Http/Common.cs index a9fc8a79..5fa22c9e 100644 --- a/Timeline/Models/Http/Common.cs +++ b/Timeline/Models/Http/Common.cs @@ -71,25 +71,36 @@ namespace Timeline.Models.Http } } + /// + /// Common response for delete method. + /// public class CommonDeleteResponse : CommonDataResponse { + /// public class ResponseData { + /// public ResponseData() { } + /// public ResponseData(bool delete) { Delete = delete; } + /// + /// True if the entry is deleted. False if the entry does not exist. + /// public bool Delete { get; set; } } + /// public CommonDeleteResponse() { } + /// public CommonDeleteResponse(int code, string message, bool delete) : base(code, message, new ResponseData(delete)) { diff --git a/Timeline/Models/Http/TokenController.cs b/Timeline/Models/Http/TokenController.cs index ea8b59ed..a42c44e5 100644 --- a/Timeline/Models/Http/TokenController.cs +++ b/Timeline/Models/Http/TokenController.cs @@ -1,32 +1,62 @@ using System.ComponentModel.DataAnnotations; +using Timeline.Controllers; namespace Timeline.Models.Http { + /// + /// Request model for . + /// public class CreateTokenRequest { - [Required] + /// + /// The username. + /// public string Username { get; set; } = default!; - [Required] + /// + /// The password. + /// public string Password { get; set; } = default!; - // in days, optional + /// + /// 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 CreateTokenResponse { + /// + /// The token created. + /// public string Token { get; set; } = default!; + /// + /// The user owning the token. + /// public UserInfo User { get; set; } = default!; } + /// + /// Request model for . + /// public class VerifyTokenRequest { - [Required] + /// + /// The token to verify. + /// public string Token { get; set; } = default!; } + /// + /// Response model for . + /// public class VerifyTokenResponse { + /// + /// The user owning the token. + /// public UserInfo User { get; set; } = default!; } } diff --git a/Timeline/Models/Http/UserController.cs b/Timeline/Models/Http/UserController.cs index 5ee02a95..ea30a0ea 100644 --- a/Timeline/Models/Http/UserController.cs +++ b/Timeline/Models/Http/UserController.cs @@ -1,48 +1,95 @@ using AutoMapper; using System.ComponentModel.DataAnnotations; +using Timeline.Controllers; using Timeline.Models.Validation; namespace Timeline.Models.Http { + /// + /// Request model for . + /// public class UserPatchRequest { + /// + /// 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; } + /// + /// Whether to be administrator. Null if not change. Need to be administrator. + /// public bool? Administrator { get; set; } } + /// + /// Request model for . + /// public class CreateUserRequest { + /// + /// 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!; + /// + /// Whether the new user is administrator. + /// [Required] public bool? Administrator { get; set; } + /// + /// Nickname of the new user. + /// [Nickname] public string? Nickname { get; set; } } + /// + /// Request model for . + /// public class ChangePasswordRequest { + /// + /// Old password. + /// [Required(AllowEmptyStrings = false)] public string OldPassword { get; set; } = default!; + + /// + /// New password. + /// [Required(AllowEmptyStrings = false)] public string NewPassword { get; set; } = default!; } + /// + /// + /// public class UserControllerAutoMapperProfile : Profile { + /// + /// + /// public UserControllerAutoMapperProfile() { CreateMap(MemberList.Source); -- cgit v1.2.3 From a8ca52b2ec6009c1be036e74edb76161447371b8 Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 21 Aug 2020 22:52:20 +0800 Subject: ... --- Timeline.ErrorCodes/ErrorCodes.cs | 5 ---- Timeline/Models/Http/ErrorResponse.cs | 50 ----------------------------------- 2 files changed, 55 deletions(-) (limited to 'Timeline/Models/Http') diff --git a/Timeline.ErrorCodes/ErrorCodes.cs b/Timeline.ErrorCodes/ErrorCodes.cs index 4637242a..91e0c1fd 100644 --- a/Timeline.ErrorCodes/ErrorCodes.cs +++ b/Timeline.ErrorCodes/ErrorCodes.cs @@ -17,16 +17,11 @@ public static class Header { public const int IfNonMatch_BadFormat = 1_000_01_01; - public const int ContentType_Missing = 1_000_02_01; - public const int ContentLength_Missing = 1_000_03_01; - public const int ContentLength_Zero = 1_000_03_02; } public static class Content { public const int TooBig = 1_000_11_01; - public const int UnmatchedLength_Smaller = 1_000_11_02; - public const int UnmatchedLength_Bigger = 1_000_11_03; } } diff --git a/Timeline/Models/Http/ErrorResponse.cs b/Timeline/Models/Http/ErrorResponse.cs index 9a4d190a..7ba536f9 100644 --- a/Timeline/Models/Http/ErrorResponse.cs +++ b/Timeline/Models/Http/ErrorResponse.cs @@ -53,36 +53,6 @@ namespace Timeline.Models.Http return new CommonResponse(ErrorCodes.Common.Header.IfNonMatch_BadFormat, string.Format(message, formatArgs)); } - public static CommonResponse ContentType_Missing(params object?[] formatArgs) - { - return new CommonResponse(ErrorCodes.Common.Header.ContentType_Missing, string.Format(Common_Header_ContentType_Missing, formatArgs)); - } - - public static CommonResponse CustomMessage_ContentType_Missing(string message, params object?[] formatArgs) - { - return new CommonResponse(ErrorCodes.Common.Header.ContentType_Missing, string.Format(message, formatArgs)); - } - - public static CommonResponse ContentLength_Missing(params object?[] formatArgs) - { - return new CommonResponse(ErrorCodes.Common.Header.ContentLength_Missing, string.Format(Common_Header_ContentLength_Missing, formatArgs)); - } - - public static CommonResponse CustomMessage_ContentLength_Missing(string message, params object?[] formatArgs) - { - return new CommonResponse(ErrorCodes.Common.Header.ContentLength_Missing, string.Format(message, formatArgs)); - } - - public static CommonResponse ContentLength_Zero(params object?[] formatArgs) - { - return new CommonResponse(ErrorCodes.Common.Header.ContentLength_Zero, string.Format(Common_Header_ContentLength_Zero, formatArgs)); - } - - public static CommonResponse CustomMessage_ContentLength_Zero(string message, params object?[] formatArgs) - { - return new CommonResponse(ErrorCodes.Common.Header.ContentLength_Zero, string.Format(message, formatArgs)); - } - } public static class Content @@ -98,26 +68,6 @@ namespace Timeline.Models.Http return new CommonResponse(ErrorCodes.Common.Content.TooBig, string.Format(message, formatArgs)); } - public static CommonResponse UnmatchedLength_Smaller(params object?[] formatArgs) - { - return new CommonResponse(ErrorCodes.Common.Content.UnmatchedLength_Smaller, string.Format(Common_Content_UnmatchedLength_Smaller, formatArgs)); - } - - public static CommonResponse CustomMessage_UnmatchedLength_Smaller(string message, params object?[] formatArgs) - { - return new CommonResponse(ErrorCodes.Common.Content.UnmatchedLength_Smaller, string.Format(message, formatArgs)); - } - - public static CommonResponse UnmatchedLength_Bigger(params object?[] formatArgs) - { - return new CommonResponse(ErrorCodes.Common.Content.UnmatchedLength_Bigger, string.Format(Common_Content_UnmatchedLength_Bigger, formatArgs)); - } - - public static CommonResponse CustomMessage_UnmatchedLength_Bigger(string message, params object?[] formatArgs) - { - return new CommonResponse(ErrorCodes.Common.Content.UnmatchedLength_Bigger, string.Format(message, formatArgs)); - } - } } -- cgit v1.2.3 From f1c70edd559c72dcb47ff647f3f03ba5ae9a56cc Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 21 Aug 2020 23:44:53 +0800 Subject: ... --- Timeline/Models/Http/Timeline.cs | 75 ++++++++++++++++++++++++++++++ Timeline/Models/Http/TimelineController.cs | 33 +++++++++++++ Timeline/Models/Http/UserController.cs | 6 --- Timeline/Models/Http/UserInfo.cs | 31 +++++++++++- 4 files changed, 138 insertions(+), 7 deletions(-) (limited to 'Timeline/Models/Http') diff --git a/Timeline/Models/Http/Timeline.cs b/Timeline/Models/Http/Timeline.cs index 52e26190..6498fa74 100644 --- a/Timeline/Models/Http/Timeline.cs +++ b/Timeline/Models/Http/Timeline.cs @@ -8,45 +8,120 @@ using Timeline.Controllers; namespace Timeline.Models.Http { + /// + /// Info of post content. + /// public class TimelinePostContentInfo { + /// + /// 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; } } + /// + /// Info of a post. + /// public class TimelinePostInfo { + /// + /// Post id. + /// public long Id { get; set; } + /// + /// Content of the post. May be null if post is deleted. + /// public TimelinePostContentInfo? 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 UserInfo? Author { get; set; } = default!; + /// + /// Last updated time. + /// public DateTime LastUpdated { get; set; } = default!; } + /// + /// Info of a timeline. + /// public class TimelineInfo { + /// + /// Unique id. + /// public string UniqueId { 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 UserInfo 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!; #pragma warning disable CA1707 // Identifiers should not contain underscores + /// + /// Related links. + /// public TimelineInfoLinks _links { get; set; } = default!; #pragma warning restore CA1707 // Identifiers should not contain underscores } + /// + /// Related links for timeline. + /// public class TimelineInfoLinks { + /// + /// Self. + /// public string Self { get; set; } = default!; + /// + /// Posts url. + /// public string Posts { get; set; } = default!; } diff --git a/Timeline/Models/Http/TimelineController.cs b/Timeline/Models/Http/TimelineController.cs index 3e2e6b58..aad361ee 100644 --- a/Timeline/Models/Http/TimelineController.cs +++ b/Timeline/Models/Http/TimelineController.cs @@ -4,33 +4,66 @@ using Timeline.Models.Validation; namespace Timeline.Models.Http { + /// + /// Content of post create request. + /// public class TimelinePostCreateRequestContent { + /// + /// 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 TimelinePostCreateRequest { + /// + /// Content of the new post. + /// [Required] public TimelinePostCreateRequestContent 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 TimelineCreateRequest { + /// + /// Name of the new timeline. Must be a valid name. + /// [Required] [TimelineName] public string Name { get; set; } = default!; } + /// + /// Patch timeline request model. + /// public class TimelinePatchRequest { + /// + /// New description. Null for not change. + /// public string? Description { get; set; } + /// + /// New visibility. Null for not change. + /// public TimelineVisibility? Visibility { get; set; } } } diff --git a/Timeline/Models/Http/UserController.cs b/Timeline/Models/Http/UserController.cs index ea30a0ea..6bc5a66e 100644 --- a/Timeline/Models/Http/UserController.cs +++ b/Timeline/Models/Http/UserController.cs @@ -82,14 +82,8 @@ namespace Timeline.Models.Http public string NewPassword { get; set; } = default!; } - /// - /// - /// public class UserControllerAutoMapperProfile : Profile { - /// - /// - /// public UserControllerAutoMapperProfile() { CreateMap(MemberList.Source); diff --git a/Timeline/Models/Http/UserInfo.cs b/Timeline/Models/Http/UserInfo.cs index c9a26072..d92a12c4 100644 --- a/Timeline/Models/Http/UserInfo.cs +++ b/Timeline/Models/Http/UserInfo.cs @@ -2,26 +2,55 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Routing; -using System; using Timeline.Controllers; namespace Timeline.Models.Http { + /// + /// Info of a user. + /// public class UserInfo { + /// + /// Unique id. + /// public string UniqueId { get; set; } = default!; + /// + /// Username. + /// public string Username { get; set; } = default!; + /// + /// Nickname. + /// public string Nickname { get; set; } = default!; + /// + /// True if the user is a administrator. + /// public bool? Administrator { get; set; } = default!; #pragma warning disable CA1707 // Identifiers should not contain underscores + /// + /// Related links. + /// public UserInfoLinks _links { get; set; } = default!; #pragma warning restore CA1707 // Identifiers should not contain underscores } + /// + /// Related links for user. + /// public class UserInfoLinks { + /// + /// Self. + /// public string Self { get; set; } = default!; + /// + /// Avatar url. + /// public string Avatar { get; set; } = default!; + /// + /// Personal timeline url. + /// public string Timeline { get; set; } = default!; } -- cgit v1.2.3