diff options
Diffstat (limited to 'Timeline/Models/Http')
-rw-r--r-- | Timeline/Models/Http/ErrorResponse.cs | 18 | ||||
-rw-r--r-- | Timeline/Models/Http/Timeline.cs | 42 | ||||
-rw-r--r-- | Timeline/Models/Http/TimelineCommon.cs | 44 | ||||
-rw-r--r-- | Timeline/Models/Http/TimelineController.cs | 20 | ||||
-rw-r--r-- | Timeline/Models/Http/TokenController.cs (renamed from Timeline/Models/Http/Token.cs) | 4 | ||||
-rw-r--r-- | Timeline/Models/Http/UserController.cs | 26 | ||||
-rw-r--r-- | Timeline/Models/Http/UserInfo.cs | 58 |
7 files changed, 159 insertions, 53 deletions
diff --git a/Timeline/Models/Http/ErrorResponse.cs b/Timeline/Models/Http/ErrorResponse.cs index 6a53e0c3..87516638 100644 --- a/Timeline/Models/Http/ErrorResponse.cs +++ b/Timeline/Models/Http/ErrorResponse.cs @@ -184,14 +184,14 @@ namespace Timeline.Models.Http public static class UserController
{
- public static CommonResponse ChangeUsername_Conflict(params object?[] formatArgs)
+ public static CommonResponse UsernameConflict(params object?[] formatArgs)
{
- return new CommonResponse(ErrorCodes.UserController.ChangeUsername_Conflict, string.Format(UserController_ChangeUsername_Conflict, formatArgs));
+ return new CommonResponse(ErrorCodes.UserController.UsernameConflict, string.Format(UserController_UsernameConflict, formatArgs));
}
- public static CommonResponse CustomMessage_ChangeUsername_Conflict(string message, params object?[] formatArgs)
+ public static CommonResponse CustomMessage_UsernameConflict(string message, params object?[] formatArgs)
{
- return new CommonResponse(ErrorCodes.UserController.ChangeUsername_Conflict, string.Format(message, formatArgs));
+ return new CommonResponse(ErrorCodes.UserController.UsernameConflict, string.Format(message, formatArgs));
}
public static CommonResponse ChangePassword_BadOldPassword(params object?[] formatArgs)
@@ -244,18 +244,18 @@ namespace Timeline.Models.Http public static class TimelineController
{
- public static CommonResponse PostOperationDelete_NotExist(params object?[] formatArgs)
+ public static CommonResponse MemberPut_NotExist(params object?[] formatArgs)
{
- return new CommonResponse(ErrorCodes.TimelineController.PostOperationDelete_NotExist, string.Format(TimelineController_PostOperationDelete_NotExist, formatArgs));
+ return new CommonResponse(ErrorCodes.TimelineController.MemberPut_NotExist, string.Format(TimelineController_MemberPut_NotExist, formatArgs));
}
- public static CommonResponse CustomMessage_PostOperationDelete_NotExist(string message, params object?[] formatArgs)
+ public static CommonResponse CustomMessage_MemberPut_NotExist(string message, params object?[] formatArgs)
{
- return new CommonResponse(ErrorCodes.TimelineController.PostOperationDelete_NotExist, string.Format(message, formatArgs));
+ return new CommonResponse(ErrorCodes.TimelineController.MemberPut_NotExist, string.Format(message, formatArgs));
}
}
}
-}
+}
\ No newline at end of file diff --git a/Timeline/Models/Http/Timeline.cs b/Timeline/Models/Http/Timeline.cs deleted file mode 100644 index 3029434e..00000000 --- a/Timeline/Models/Http/Timeline.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System;
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-
-namespace Timeline.Models.Http
-{
- public class TimelinePostCreateRequest
- {
- [Required(AllowEmptyStrings = true)]
- public string Content { get; set; } = default!;
-
- public DateTime? Time { get; set; }
- }
-
- public class TimelinePostCreateResponse
- {
- public long Id { get; set; }
-
- public DateTime Time { get; set; }
- }
-
- public class TimelinePostDeleteRequest
- {
- [Required]
- public long? Id { get; set; }
- }
-
- public class TimelinePropertyChangeRequest
- {
- public string? Description { get; set; }
-
- public TimelineVisibility? Visibility { get; set; }
- }
-
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "This is a DTO class.")]
- public class TimelineMemberChangeRequest
- {
- public List<string>? Add { get; set; }
-
- public List<string>? Remove { get; set; }
- }
-}
diff --git a/Timeline/Models/Http/TimelineCommon.cs b/Timeline/Models/Http/TimelineCommon.cs new file mode 100644 index 00000000..febb8186 --- /dev/null +++ b/Timeline/Models/Http/TimelineCommon.cs @@ -0,0 +1,44 @@ +using System;
+using System.Collections.Generic;
+
+namespace Timeline.Models.Http
+{
+ public enum TimelineVisibility
+ {
+ /// <summary>
+ /// All people including those without accounts.
+ /// </summary>
+ Public,
+ /// <summary>
+ /// Only people signed in.
+ /// </summary>
+ Register,
+ /// <summary>
+ /// Only member.
+ /// </summary>
+ Private
+ }
+
+ public class TimelinePostInfo
+ {
+ public long Id { get; set; }
+ public string Content { get; set; } = default!;
+ public DateTime Time { get; set; }
+ public UserInfo Author { get; set; } = default!;
+ public DateTime LastUpdated { get; set; } = default!;
+ }
+
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "This is a DTO class.")]
+ public class BaseTimelineInfo
+ {
+ public string Description { get; set; } = default!;
+ public UserInfo Owner { get; set; } = default!;
+ public TimelineVisibility Visibility { get; set; }
+ public List<UserInfo> Members { get; set; } = default!;
+ }
+
+ public class TimelineInfo : BaseTimelineInfo
+ {
+ public string Name { get; set; } = default!;
+ }
+}
diff --git a/Timeline/Models/Http/TimelineController.cs b/Timeline/Models/Http/TimelineController.cs new file mode 100644 index 00000000..f9a4d3e5 --- /dev/null +++ b/Timeline/Models/Http/TimelineController.cs @@ -0,0 +1,20 @@ +using System;
+using System.ComponentModel.DataAnnotations;
+
+namespace Timeline.Models.Http
+{
+ public class TimelinePostCreateRequest
+ {
+ [Required(AllowEmptyStrings = true)]
+ public string Content { get; set; } = default!;
+
+ public DateTime? Time { get; set; }
+ }
+
+ public class TimelinePatchRequest
+ {
+ public string? Description { get; set; }
+
+ public TimelineVisibility? Visibility { get; set; }
+ }
+}
diff --git a/Timeline/Models/Http/Token.cs b/Timeline/Models/Http/TokenController.cs index 0649f1d1..383b2965 100644 --- a/Timeline/Models/Http/Token.cs +++ b/Timeline/Models/Http/TokenController.cs @@ -16,7 +16,7 @@ namespace Timeline.Models.Http public class CreateTokenResponse
{
public string Token { get; set; } = default!;
- public User User { get; set; } = default!;
+ public UserInfoForAdmin User { get; set; } = default!;
}
public class VerifyTokenRequest
@@ -27,6 +27,6 @@ namespace Timeline.Models.Http public class VerifyTokenResponse
{
- public User User { get; set; } = default!;
+ public UserInfoForAdmin User { get; set; } = default!;
}
}
diff --git a/Timeline/Models/Http/UserController.cs b/Timeline/Models/Http/UserController.cs index 229ca1e5..e4c95cbd 100644 --- a/Timeline/Models/Http/UserController.cs +++ b/Timeline/Models/Http/UserController.cs @@ -1,5 +1,7 @@ +using AutoMapper;
using System.ComponentModel.DataAnnotations;
using Timeline.Models.Validation;
+using Timeline.Services;
namespace Timeline.Models.Http
{
@@ -17,6 +19,21 @@ namespace Timeline.Models.Http public bool? Administrator { get; set; }
}
+ public class CreateUserRequest
+ {
+ [Required, Username]
+ public string Username { get; set; } = default!;
+
+ [Required, MinLength(1)]
+ public string Password { get; set; } = default!;
+
+ [Required]
+ public bool? Administrator { get; set; }
+
+ [Nickname]
+ public string? Nickname { get; set; }
+ }
+
public class ChangePasswordRequest
{
[Required(AllowEmptyStrings = false)]
@@ -24,4 +41,13 @@ namespace Timeline.Models.Http [Required(AllowEmptyStrings = false)]
public string NewPassword { get; set; } = default!;
}
+
+ public class UserControllerAutoMapperProfile : Profile
+ {
+ public UserControllerAutoMapperProfile()
+ {
+ CreateMap<UserPatchRequest, User>(MemberList.Source);
+ CreateMap<CreateUserRequest, User>(MemberList.Source);
+ }
+ }
}
diff --git a/Timeline/Models/Http/UserInfo.cs b/Timeline/Models/Http/UserInfo.cs new file mode 100644 index 00000000..6029b8aa --- /dev/null +++ b/Timeline/Models/Http/UserInfo.cs @@ -0,0 +1,58 @@ +using AutoMapper;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Infrastructure;
+using Microsoft.AspNetCore.Mvc.Routing;
+using Timeline.Controllers;
+using Timeline.Services;
+
+namespace Timeline.Models.Http
+{
+ public interface IUserInfo
+ {
+ string Username { get; set; }
+ string Nickname { get; set; }
+ string AvatarUrl { get; set; }
+ }
+
+ public class UserInfo : IUserInfo
+ {
+ public string Username { get; set; } = default!;
+ public string Nickname { get; set; } = default!;
+ public string AvatarUrl { get; set; } = default!;
+ }
+
+ public class UserInfoForAdmin : IUserInfo
+ {
+ public string Username { get; set; } = default!;
+ public string Nickname { get; set; } = default!;
+ public string AvatarUrl { get; set; } = default!;
+ public bool Administrator { get; set; }
+ }
+
+ public class UserInfoSetAvatarUrlAction : IMappingAction<object, IUserInfo>
+ {
+ private readonly IActionContextAccessor _actionContextAccessor;
+ private readonly IUrlHelperFactory _urlHelperFactory;
+
+ public UserInfoSetAvatarUrlAction(IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory)
+ {
+ _actionContextAccessor = actionContextAccessor;
+ _urlHelperFactory = urlHelperFactory;
+ }
+
+ public void Process(object source, IUserInfo destination, ResolutionContext context)
+ {
+ var urlHelper = _urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext);
+ destination.AvatarUrl = urlHelper.ActionLink(nameof(UserAvatarController.Get), nameof(UserAvatarController), new { destination.Username });
+ }
+ }
+
+ public class UserInfoAutoMapperProfile : Profile
+ {
+ public UserInfoAutoMapperProfile()
+ {
+ CreateMap<User, UserInfo>().AfterMap<UserInfoSetAvatarUrlAction>();
+ CreateMap<User, UserInfoForAdmin>().AfterMap<UserInfoSetAvatarUrlAction>();
+ }
+ }
+}
|