From 3fb134b1d27a0c1069f14dc2608f25295e85eaa9 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