diff options
Diffstat (limited to 'Timeline/Models')
-rw-r--r-- | Timeline/Models/ByteData.cs | 33 | ||||
-rw-r--r-- | Timeline/Models/Http/Common.cs | 11 | ||||
-rw-r--r-- | Timeline/Models/Http/ErrorResponse.cs | 50 | ||||
-rw-r--r-- | Timeline/Models/Http/Timeline.cs | 75 | ||||
-rw-r--r-- | Timeline/Models/Http/TimelineController.cs | 33 | ||||
-rw-r--r-- | Timeline/Models/Http/TokenController.cs | 38 | ||||
-rw-r--r-- | Timeline/Models/Http/UserController.cs | 41 | ||||
-rw-r--r-- | Timeline/Models/Http/UserInfo.cs | 31 | ||||
-rw-r--r-- | Timeline/Models/Validation/Validator.cs | 4 |
9 files changed, 259 insertions, 57 deletions
diff --git a/Timeline/Models/ByteData.cs b/Timeline/Models/ByteData.cs new file mode 100644 index 00000000..7b832eb5 --- /dev/null +++ b/Timeline/Models/ByteData.cs @@ -0,0 +1,33 @@ +using NSwag.Annotations;
+
+namespace Timeline.Models
+{
+ /// <summary>
+ /// Model for reading http body as bytes.
+ /// </summary>
+ [OpenApiFile]
+ public class ByteData
+ {
+ /// <summary>
+ /// </summary>
+ /// <param name="data">The data.</param>
+ /// <param name="contentType">The content type.</param>
+ public ByteData(byte[] data, string contentType)
+ {
+ Data = data;
+ ContentType = contentType;
+ }
+
+ /// <summary>
+ /// Data.
+ /// </summary>
+#pragma warning disable CA1819 // Properties should not return arrays
+ public byte[] Data { get; }
+#pragma warning restore CA1819 // Properties should not return arrays
+
+ /// <summary>
+ /// Content type.
+ /// </summary>
+ public string ContentType { get; }
+ }
+}
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 }
}
+ /// <summary>
+ /// Common response for delete method.
+ /// </summary>
public class CommonDeleteResponse : CommonDataResponse<CommonDeleteResponse.ResponseData>
{
+ /// <summary></summary>
public class ResponseData
{
+ /// <summary></summary>
public ResponseData() { }
+ /// <summary></summary>
public ResponseData(bool delete)
{
Delete = delete;
}
+ /// <summary>
+ /// True if the entry is deleted. False if the entry does not exist.
+ /// </summary>
public bool Delete { get; set; }
}
+ /// <summary></summary>
public CommonDeleteResponse()
{
}
+ /// <summary></summary>
public CommonDeleteResponse(int code, string message, bool delete)
: base(code, message, new ResponseData(delete))
{
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));
- }
-
}
}
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
{
+ /// <summary>
+ /// Info of post content.
+ /// </summary>
public class TimelinePostContentInfo
{
+ /// <summary>
+ /// Type of the post content.
+ /// </summary>
public string Type { get; set; } = default!;
+ /// <summary>
+ /// If post is of text type. This is the text.
+ /// </summary>
public string? Text { get; set; }
+ /// <summary>
+ /// If post is of image type. This is the image url.
+ /// </summary>
public string? Url { get; set; }
}
+ /// <summary>
+ /// Info of a post.
+ /// </summary>
public class TimelinePostInfo
{
+ /// <summary>
+ /// Post id.
+ /// </summary>
public long Id { get; set; }
+ /// <summary>
+ /// Content of the post. May be null if post is deleted.
+ /// </summary>
public TimelinePostContentInfo? Content { get; set; }
+ /// <summary>
+ /// True if post is deleted.
+ /// </summary>
public bool Deleted { get; set; }
+ /// <summary>
+ /// Post time.
+ /// </summary>
public DateTime Time { get; set; }
+ /// <summary>
+ /// The author. May be null if the user has been deleted.
+ /// </summary>
public UserInfo? Author { get; set; } = default!;
+ /// <summary>
+ /// Last updated time.
+ /// </summary>
public DateTime LastUpdated { get; set; } = default!;
}
+ /// <summary>
+ /// Info of a timeline.
+ /// </summary>
public class TimelineInfo
{
+ /// <summary>
+ /// Unique id.
+ /// </summary>
public string UniqueId { get; set; } = default!;
+ /// <summary>
+ /// Name of timeline.
+ /// </summary>
public string Name { get; set; } = default!;
+ /// <summary>
+ /// Last modified time of timeline name.
+ /// </summary>
public DateTime NameLastModifed { get; set; } = default!;
+ /// <summary>
+ /// Timeline description.
+ /// </summary>
public string Description { get; set; } = default!;
+ /// <summary>
+ /// Owner of the timeline.
+ /// </summary>
public UserInfo Owner { get; set; } = default!;
+ /// <summary>
+ /// Visibility of the timeline.
+ /// </summary>
public TimelineVisibility Visibility { get; set; }
#pragma warning disable CA2227 // Collection properties should be read only
+ /// <summary>
+ /// Members of timeline.
+ /// </summary>
public List<UserInfo> Members { get; set; } = default!;
#pragma warning restore CA2227 // Collection properties should be read only
+ /// <summary>
+ /// Create time of timeline.
+ /// </summary>
public DateTime CreateTime { get; set; } = default!;
+ /// <summary>
+ /// Last modified time of timeline.
+ /// </summary>
public DateTime LastModified { get; set; } = default!;
#pragma warning disable CA1707 // Identifiers should not contain underscores
+ /// <summary>
+ /// Related links.
+ /// </summary>
public TimelineInfoLinks _links { get; set; } = default!;
#pragma warning restore CA1707 // Identifiers should not contain underscores
}
+ /// <summary>
+ /// Related links for timeline.
+ /// </summary>
public class TimelineInfoLinks
{
+ /// <summary>
+ /// Self.
+ /// </summary>
public string Self { get; set; } = default!;
+ /// <summary>
+ /// Posts url.
+ /// </summary>
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
{
+ /// <summary>
+ /// Content of post create request.
+ /// </summary>
public class TimelinePostCreateRequestContent
{
+ /// <summary>
+ /// Type of post content.
+ /// </summary>
[Required]
public string Type { get; set; } = default!;
+ /// <summary>
+ /// If post is of text type, this is the text.
+ /// </summary>
public string? Text { get; set; }
+ /// <summary>
+ /// If post is of image type, this is base64 of image data.
+ /// </summary>
public string? Data { get; set; }
}
public class TimelinePostCreateRequest
{
+ /// <summary>
+ /// Content of the new post.
+ /// </summary>
[Required]
public TimelinePostCreateRequestContent Content { get; set; } = default!;
+ /// <summary>
+ /// Time of the post. If not set, current time will be used.
+ /// </summary>
public DateTime? Time { get; set; }
}
+ /// <summary>
+ /// Create timeline request model.
+ /// </summary>
public class TimelineCreateRequest
{
+ /// <summary>
+ /// Name of the new timeline. Must be a valid name.
+ /// </summary>
[Required]
[TimelineName]
public string Name { get; set; } = default!;
}
+ /// <summary>
+ /// Patch timeline request model.
+ /// </summary>
public class TimelinePatchRequest
{
+ /// <summary>
+ /// New description. Null for not change.
+ /// </summary>
public string? Description { get; set; }
+ /// <summary>
+ /// New visibility. Null for not change.
+ /// </summary>
public TimelineVisibility? Visibility { get; set; }
}
}
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
{
+ /// <summary>
+ /// Request model for <see cref="TokenController.Create(CreateTokenRequest)"/>.
+ /// </summary>
public class CreateTokenRequest
{
- [Required]
+ /// <summary>
+ /// The username.
+ /// </summary>
public string Username { get; set; } = default!;
- [Required]
+ /// <summary>
+ /// The password.
+ /// </summary>
public string Password { get; set; } = default!;
- // in days, optional
+ /// <summary>
+ /// Optional token validation period. In days. If not specified, server will use a default one.
+ /// </summary>
[Range(1, 365)]
public int? Expire { get; set; }
}
+ /// <summary>
+ /// Response model for <see cref="TokenController.Create(CreateTokenRequest)"/>.
+ /// </summary>
public class CreateTokenResponse
{
+ /// <summary>
+ /// The token created.
+ /// </summary>
public string Token { get; set; } = default!;
+ /// <summary>
+ /// The user owning the token.
+ /// </summary>
public UserInfo User { get; set; } = default!;
}
+ /// <summary>
+ /// Request model for <see cref="TokenController.Verify(VerifyTokenRequest)"/>.
+ /// </summary>
public class VerifyTokenRequest
{
- [Required]
+ /// <summary>
+ /// The token to verify.
+ /// </summary>
public string Token { get; set; } = default!;
}
+ /// <summary>
+ /// Response model for <see cref="TokenController.Verify(VerifyTokenRequest)"/>.
+ /// </summary>
public class VerifyTokenResponse
{
+ /// <summary>
+ /// The user owning the token.
+ /// </summary>
public UserInfo User { get; set; } = default!;
}
}
diff --git a/Timeline/Models/Http/UserController.cs b/Timeline/Models/Http/UserController.cs index 5ee02a95..6bc5a66e 100644 --- a/Timeline/Models/Http/UserController.cs +++ b/Timeline/Models/Http/UserController.cs @@ -1,42 +1,83 @@ using AutoMapper;
using System.ComponentModel.DataAnnotations;
+using Timeline.Controllers;
using Timeline.Models.Validation;
namespace Timeline.Models.Http
{
+ /// <summary>
+ /// Request model for <see cref="UserController.Patch(UserPatchRequest, string)"/>.
+ /// </summary>
public class UserPatchRequest
{
+ /// <summary>
+ /// New username. Null if not change. Need to be administrator.
+ /// </summary>
[Username]
public string? Username { get; set; }
+ /// <summary>
+ /// New password. Null if not change. Need to be administrator.
+ /// </summary>
[MinLength(1)]
public string? Password { get; set; }
+ /// <summary>
+ /// New nickname. Null if not change. Need to be administrator to change other's.
+ /// </summary>
[Nickname]
public string? Nickname { get; set; }
+ /// <summary>
+ /// Whether to be administrator. Null if not change. Need to be administrator.
+ /// </summary>
public bool? Administrator { get; set; }
}
+ /// <summary>
+ /// Request model for <see cref="UserController.CreateUser(CreateUserRequest)"/>.
+ /// </summary>
public class CreateUserRequest
{
+ /// <summary>
+ /// Username of the new user.
+ /// </summary>
[Required, Username]
public string Username { get; set; } = default!;
+ /// <summary>
+ /// Password of the new user.
+ /// </summary>
[Required, MinLength(1)]
public string Password { get; set; } = default!;
+ /// <summary>
+ /// Whether the new user is administrator.
+ /// </summary>
[Required]
public bool? Administrator { get; set; }
+ /// <summary>
+ /// Nickname of the new user.
+ /// </summary>
[Nickname]
public string? Nickname { get; set; }
}
+ /// <summary>
+ /// Request model for <see cref="UserController.ChangePassword(ChangePasswordRequest)"/>.
+ /// </summary>
public class ChangePasswordRequest
{
+ /// <summary>
+ /// Old password.
+ /// </summary>
[Required(AllowEmptyStrings = false)]
public string OldPassword { get; set; } = default!;
+
+ /// <summary>
+ /// New password.
+ /// </summary>
[Required(AllowEmptyStrings = false)]
public string NewPassword { get; set; } = default!;
}
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
{
+ /// <summary>
+ /// Info of a user.
+ /// </summary>
public class UserInfo
{
+ /// <summary>
+ /// Unique id.
+ /// </summary>
public string UniqueId { get; set; } = default!;
+ /// <summary>
+ /// Username.
+ /// </summary>
public string Username { get; set; } = default!;
+ /// <summary>
+ /// Nickname.
+ /// </summary>
public string Nickname { get; set; } = default!;
+ /// <summary>
+ /// True if the user is a administrator.
+ /// </summary>
public bool? Administrator { get; set; } = default!;
#pragma warning disable CA1707 // Identifiers should not contain underscores
+ /// <summary>
+ /// Related links.
+ /// </summary>
public UserInfoLinks _links { get; set; } = default!;
#pragma warning restore CA1707 // Identifiers should not contain underscores
}
+ /// <summary>
+ /// Related links for user.
+ /// </summary>
public class UserInfoLinks
{
+ /// <summary>
+ /// Self.
+ /// </summary>
public string Self { get; set; } = default!;
+ /// <summary>
+ /// Avatar url.
+ /// </summary>
public string Avatar { get; set; } = default!;
+ /// <summary>
+ /// Personal timeline url.
+ /// </summary>
public string Timeline { get; set; } = default!;
}
diff --git a/Timeline/Models/Validation/Validator.cs b/Timeline/Models/Validation/Validator.cs index db139448..aef7891c 100644 --- a/Timeline/Models/Validation/Validator.cs +++ b/Timeline/Models/Validation/Validator.cs @@ -35,11 +35,11 @@ namespace Timeline.Models.Validation /// </summary>
/// <typeparam name="T">The type of accepted value.</typeparam>
/// <remarks>
- /// Subclass should override <see cref="DoValidate(T, out string)"/> to do the real validation.
+ /// Subclass should override <see cref="DoValidate(T)"/> to do the real validation.
/// This class will check the nullity and type of value.
/// If value is null, it will pass or fail depending on <see cref="PermitNull"/>.
/// If value is not null and not of type <typeparamref name="T"/>
- /// it will fail and not call <see cref="DoValidate(T, out string)"/>.
+ /// it will fail and not call <see cref="DoValidate(T)"/>.
///
/// <see cref="PermitNull"/> is true by default.
///
|