From b87abbb8ed0aa86a808b2f97e4d22b0ee1addd9f Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 29 Apr 2021 19:29:35 +0800 Subject: ... --- .../Timeline.Tests/Services/SearchServiceTest.cs | 4 +- .../Controllers/BookmarkTimelineController.cs | 8 +- .../Controllers/HighlightTimelineController.cs | 8 +- BackEnd/Timeline/Controllers/SearchController.cs | 4 +- BackEnd/Timeline/Controllers/TimelineController.cs | 3 - .../Timeline/Controllers/TimelinePostController.cs | 3 - BackEnd/Timeline/Controllers/TokenController.cs | 52 +------ .../Timeline/Controllers/UserAvatarController.cs | 36 +---- BackEnd/Timeline/Controllers/UserController.cs | 24 +--- BackEnd/Timeline/Helpers/Log.cs | 22 --- .../ControllerAuthExtensions.Designer.cs | 81 ----------- .../Controllers/ControllerAuthExtensions.resx | 126 ----------------- .../Controllers/TimelineController.Designer.cs | 81 ----------- .../Resources/Controllers/TimelineController.resx | 126 ----------------- .../Controllers/TokenController.Designer.cs | 153 --------------------- .../Resources/Controllers/TokenController.resx | 150 -------------------- .../Controllers/UserAvatarController.Designer.cs | 144 ------------------- .../Controllers/UserAvatarController.resx | 147 -------------------- .../Controllers/UserController.Designer.cs | 117 ---------------- .../Resources/Controllers/UserController.resx | 138 ------------------- .../Services/Api/BookmarkTimelineService.cs | 79 +---------- .../Services/Api/HighlightTimelineService.cs | 77 +---------- .../Services/Api/IBookmarkTimelineService.cs | 64 +++++++++ .../Services/Api/IHighlightTimelineService.cs | 61 ++++++++ BackEnd/Timeline/Services/Api/ISearchService.cs | 33 +++++ .../Services/Api/InvalidBookmarkException.cs | 15 ++ .../Api/InvalidHighlightTimelineException.cs | 15 ++ BackEnd/Timeline/Services/Api/SearchResult.cs | 11 ++ BackEnd/Timeline/Services/Api/SearchResultItem.cs | 18 +++ BackEnd/Timeline/Services/Api/SearchService.cs | 55 +------- BackEnd/Timeline/Services/Mapper/TimelineMapper.cs | 4 +- BackEnd/Timeline/Timeline.csproj | 48 +------ 32 files changed, 265 insertions(+), 1642 deletions(-) delete mode 100644 BackEnd/Timeline/Helpers/Log.cs delete mode 100644 BackEnd/Timeline/Resources/Controllers/ControllerAuthExtensions.Designer.cs delete mode 100644 BackEnd/Timeline/Resources/Controllers/ControllerAuthExtensions.resx delete mode 100644 BackEnd/Timeline/Resources/Controllers/TimelineController.Designer.cs delete mode 100644 BackEnd/Timeline/Resources/Controllers/TimelineController.resx delete mode 100644 BackEnd/Timeline/Resources/Controllers/TokenController.Designer.cs delete mode 100644 BackEnd/Timeline/Resources/Controllers/TokenController.resx delete mode 100644 BackEnd/Timeline/Resources/Controllers/UserAvatarController.Designer.cs delete mode 100644 BackEnd/Timeline/Resources/Controllers/UserAvatarController.resx delete mode 100644 BackEnd/Timeline/Resources/Controllers/UserController.Designer.cs delete mode 100644 BackEnd/Timeline/Resources/Controllers/UserController.resx create mode 100644 BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs create mode 100644 BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs create mode 100644 BackEnd/Timeline/Services/Api/ISearchService.cs create mode 100644 BackEnd/Timeline/Services/Api/InvalidBookmarkException.cs create mode 100644 BackEnd/Timeline/Services/Api/InvalidHighlightTimelineException.cs create mode 100644 BackEnd/Timeline/Services/Api/SearchResult.cs create mode 100644 BackEnd/Timeline/Services/Api/SearchResultItem.cs diff --git a/BackEnd/Timeline.Tests/Services/SearchServiceTest.cs b/BackEnd/Timeline.Tests/Services/SearchServiceTest.cs index 1c96eb34..6e3c0f40 100644 --- a/BackEnd/Timeline.Tests/Services/SearchServiceTest.cs +++ b/BackEnd/Timeline.Tests/Services/SearchServiceTest.cs @@ -24,7 +24,7 @@ namespace Timeline.Tests.Services await TimelineService.ChangePropertyAsync(t2.Id, new TimelineChangePropertyParams { Title = "hahaha" }); await TimelineService.CreateTimelineAsync("bbbbbb", UserId); - var searchResult = await _service.SearchTimeline("hah"); + var searchResult = await _service.SearchTimelineAsync("hah"); searchResult.Items.Should().HaveCount(2); searchResult.Items[0].Item.Name.Should().Be("hahaha"); searchResult.Items[0].Score.Should().Be(2); @@ -40,7 +40,7 @@ namespace Timeline.Tests.Services await UserService.ModifyUserAsync(u2.Id, new ModifyUserParams { Nickname = "hahaha" }); await UserService.CreateUserAsync(new CreateUserParams("bbbbbb", "p")); - var searchResult = await _service.SearchUser("hah"); + var searchResult = await _service.SearchUserAsync("hah"); searchResult.Items.Should().HaveCount(2); searchResult.Items[0].Item.Username.Should().Be("hahaha"); searchResult.Items[0].Score.Should().Be(2); diff --git a/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs b/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs index e7ffa5c5..cbc96fc6 100644 --- a/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs +++ b/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs @@ -44,7 +44,7 @@ namespace Timeline.Controllers [ProducesResponseType(401)] public async Task>> List() { - var ids = await _service.GetBookmarks(this.GetUserId()); + var ids = await _service.GetBookmarksAsync(this.GetUserId()); var timelines = await _timelineService.GetTimelineList(ids); return await Map(timelines); } @@ -63,7 +63,7 @@ namespace Timeline.Controllers try { var timelineId = await _timelineService.GetTimelineIdByNameAsync(timeline); - var create = await _service.AddBookmark(this.GetUserId(), timelineId); + var create = await _service.AddBookmarkAsync(this.GetUserId(), timelineId); return CommonPutResponse.Create(create); } catch (TimelineNotExistException) @@ -86,7 +86,7 @@ namespace Timeline.Controllers try { var timelineId = await _timelineService.GetTimelineIdByNameAsync(timeline); - var delete = await _service.RemoveBookmark(this.GetUserId(), timelineId); + var delete = await _service.RemoveBookmarkAsync(this.GetUserId(), timelineId); return CommonDeleteResponse.Create(delete); } catch (TimelineNotExistException) @@ -109,7 +109,7 @@ namespace Timeline.Controllers try { var timelineId = await _timelineService.GetTimelineIdByNameAsync(request.Timeline); - await _service.MoveBookmark(this.GetUserId(), timelineId, request.NewPosition!.Value); + await _service.MoveBookmarkAsync(this.GetUserId(), timelineId, request.NewPosition!.Value); return Ok(); } catch (TimelineNotExistException) diff --git a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs index 4e739056..ffaa50c1 100644 --- a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs +++ b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs @@ -43,7 +43,7 @@ namespace Timeline.Controllers [ProducesResponseType(200)] public async Task>> List() { - var ids = await _service.GetHighlightTimelines(); + var ids = await _service.GetHighlightTimelinesAsync(); var timelines = await _timelineService.GetTimelineList(ids); return await Map(timelines); } @@ -63,7 +63,7 @@ namespace Timeline.Controllers try { var timelineId = await _timelineService.GetTimelineIdByNameAsync(timeline); - var create = await _service.AddHighlightTimeline(timelineId, this.GetUserId()); + var create = await _service.AddHighlightTimelineAsync(timelineId, this.GetUserId()); return CommonPutResponse.Create(create); } catch (TimelineNotExistException) @@ -87,7 +87,7 @@ namespace Timeline.Controllers try { var timelineId = await _timelineService.GetTimelineIdByNameAsync(timeline); - var delete = await _service.RemoveHighlightTimeline(timelineId, this.GetUserId()); + var delete = await _service.RemoveHighlightTimelineAsync(timelineId, this.GetUserId()); return CommonDeleteResponse.Create(delete); } catch (TimelineNotExistException) @@ -110,7 +110,7 @@ namespace Timeline.Controllers try { var timelineId = await _timelineService.GetTimelineIdByNameAsync(body.Timeline); - await _service.MoveHighlightTimeline(timelineId, body.NewPosition!.Value); + await _service.MoveHighlightTimelineAsync(timelineId, body.NewPosition!.Value); return Ok(); } catch (TimelineNotExistException) diff --git a/BackEnd/Timeline/Controllers/SearchController.cs b/BackEnd/Timeline/Controllers/SearchController.cs index 76f3d8f2..cd085e5b 100644 --- a/BackEnd/Timeline/Controllers/SearchController.cs +++ b/BackEnd/Timeline/Controllers/SearchController.cs @@ -42,7 +42,7 @@ namespace Timeline.Controllers [ProducesResponseType(400)] public async Task>> TimelineSearch([FromQuery(Name = "q"), Required(AllowEmptyStrings = false)] string query) { - var searchResult = await _service.SearchTimeline(query); + var searchResult = await _service.SearchTimelineAsync(query); var timelines = searchResult.Items.Select(i => i.Item).ToList(); return await Map(timelines); } @@ -57,7 +57,7 @@ namespace Timeline.Controllers [ProducesResponseType(400)] public async Task>> UserSearch([FromQuery(Name = "q"), Required(AllowEmptyStrings = false)] string query) { - var searchResult = await _service.SearchUser(query); + var searchResult = await _service.SearchUserAsync(query); var users = searchResult.Items.Select(i => i.Item).ToList(); return await _mapper.MapListAsync(users, Url, User); } diff --git a/BackEnd/Timeline/Controllers/TimelineController.cs b/BackEnd/Timeline/Controllers/TimelineController.cs index 497d7893..3fd0f2ac 100644 --- a/BackEnd/Timeline/Controllers/TimelineController.cs +++ b/BackEnd/Timeline/Controllers/TimelineController.cs @@ -29,9 +29,6 @@ namespace Timeline.Controllers private readonly ITimelineService _service; private readonly IGenericMapper _mapper; - /// - /// - /// public TimelineController(IUserService userService, ITimelineService service, IGenericMapper mapper) { _userService = userService; diff --git a/BackEnd/Timeline/Controllers/TimelinePostController.cs b/BackEnd/Timeline/Controllers/TimelinePostController.cs index 2e1ed3a9..2d3e5423 100644 --- a/BackEnd/Timeline/Controllers/TimelinePostController.cs +++ b/BackEnd/Timeline/Controllers/TimelinePostController.cs @@ -35,9 +35,6 @@ namespace Timeline.Controllers private readonly MarkdownProcessor _markdownProcessor; - /// - /// - /// public TimelinePostController(ITimelineService timelineService, ITimelinePostService timelinePostService, IGenericMapper mapper, MarkdownProcessor markdownProcessor) { _timelineService = timelineService; diff --git a/BackEnd/Timeline/Controllers/TokenController.cs b/BackEnd/Timeline/Controllers/TokenController.cs index e728ae6d..3d4e9444 100644 --- a/BackEnd/Timeline/Controllers/TokenController.cs +++ b/BackEnd/Timeline/Controllers/TokenController.cs @@ -1,17 +1,13 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; using System; -using System.Globalization; using System.Threading.Tasks; -using Timeline.Helpers; using Timeline.Models.Http; using Timeline.Services; using Timeline.Services.Mapper; using Timeline.Services.Token; using Timeline.Services.User; -using static Timeline.Resources.Controllers.TokenController; namespace Timeline.Controllers { @@ -24,15 +20,12 @@ namespace Timeline.Controllers public class TokenController : Controller { private readonly IUserTokenManager _userTokenManager; - private readonly ILogger _logger; private readonly IGenericMapper _mapper; private readonly IClock _clock; - /// - public TokenController(IUserTokenManager userTokenManager, ILogger logger, IGenericMapper mapper, IClock clock) + public TokenController(IUserTokenManager userTokenManager, IGenericMapper mapper, IClock clock) { _userTokenManager = userTokenManager; - _logger = logger; _mapper = mapper; _clock = clock; } @@ -47,15 +40,6 @@ namespace Timeline.Controllers [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task> Create([FromBody] HttpCreateTokenRequest request) { - void LogFailure(string reason, Exception? e = null) - { - _logger.LogInformation(e, Log.Format(LogCreateFailure, - ("Reason", reason), - ("Username", request.Username), - ("Password", request.Password), - ("Expire (in days)", request.Expire) - )); - } try { @@ -65,24 +49,18 @@ namespace Timeline.Controllers var result = await _userTokenManager.CreateTokenAsync(request.Username, request.Password, expireTime); - _logger.LogInformation(Log.Format(LogCreateSuccess, - ("Username", request.Username), - ("Expire At", expireTime?.ToString(CultureInfo.CurrentCulture.DateTimeFormat) ?? "default") - )); return new HttpCreateTokenResponse { Token = result.Token, User = await _mapper.MapAsync(result.User, Url, User) }; } - catch (UserNotExistException e) + catch (UserNotExistException) { - LogFailure(LogUserNotExist, e); return BadRequest(ErrorResponse.TokenController.Create_BadCredential()); } - catch (BadPasswordException e) + catch (BadPasswordException) { - LogFailure(LogBadPassword, e); return BadRequest(ErrorResponse.TokenController.Create_BadCredential()); } } @@ -97,44 +75,28 @@ namespace Timeline.Controllers [ProducesResponseType(StatusCodes.Status400BadRequest)] public async Task> Verify([FromBody] HttpVerifyTokenRequest request) { - void LogFailure(string reason, Exception? e = null, params (string, object?)[] otherProperties) - { - var properties = new (string, object?)[2 + otherProperties.Length]; - properties[0] = ("Reason", reason); - properties[1] = ("Token", request.Token); - otherProperties.CopyTo(properties, 2); - _logger.LogInformation(e, Log.Format(LogVerifyFailure, properties)); - } - try { var result = await _userTokenManager.VerifyTokenAsync(request.Token); - _logger.LogInformation(Log.Format(LogVerifySuccess, - ("Username", result.Username), ("Token", request.Token))); return new HttpVerifyTokenResponse { User = await _mapper.MapAsync(result, Url, User) }; } - catch (UserTokenTimeExpiredException e) + catch (UserTokenTimeExpiredException) { - LogFailure(LogVerifyExpire, e, ("Expire Time", e.ExpireTime), ("Verify Time", e.VerifyTime)); return BadRequest(ErrorResponse.TokenController.Verify_TimeExpired()); } - catch (UserTokenVersionExpiredException e) + catch (UserTokenVersionExpiredException) { - LogFailure(LogVerifyOldVersion, e, ("Token Version", e.TokenVersion), ("Required Version", e.RequiredVersion)); return BadRequest(ErrorResponse.TokenController.Verify_OldVersion()); - } - catch (UserTokenBadFormatException e) + catch (UserTokenBadFormatException) { - LogFailure(LogVerifyBadFormat, e); return BadRequest(ErrorResponse.TokenController.Verify_BadFormat()); } - catch (UserTokenUserNotExistException e) + catch (UserTokenUserNotExistException) { - LogFailure(LogVerifyUserNotExist, e); return BadRequest(ErrorResponse.TokenController.Verify_UserNotExist()); } } diff --git a/BackEnd/Timeline/Controllers/UserAvatarController.cs b/BackEnd/Timeline/Controllers/UserAvatarController.cs index c280f033..b1129329 100644 --- a/BackEnd/Timeline/Controllers/UserAvatarController.cs +++ b/BackEnd/Timeline/Controllers/UserAvatarController.cs @@ -1,11 +1,9 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; using System; using System.Threading.Tasks; using Timeline.Filters; -using Timeline.Helpers; using Timeline.Helpers.Cache; using Timeline.Models; using Timeline.Models.Http; @@ -13,7 +11,6 @@ using Timeline.Models.Validation; using Timeline.Services.Imaging; using Timeline.Services.User; using Timeline.Services.User.Avatar; -using static Timeline.Resources.Controllers.UserAvatarController; namespace Timeline.Controllers { @@ -24,17 +21,11 @@ namespace Timeline.Controllers [ProducesErrorResponseType(typeof(CommonResponse))] public class UserAvatarController : Controller { - private readonly ILogger _logger; - private readonly IUserService _userService; private readonly IUserAvatarService _service; - /// - /// - /// - public UserAvatarController(ILogger logger, IUserService userService, IUserAvatarService service) + public UserAvatarController(IUserService userService, IUserAvatarService service) { - _logger = logger; _userService = userService; _service = service; } @@ -53,18 +44,16 @@ namespace Timeline.Controllers public async Task Get([FromRoute][Username] string username, [FromHeader(Name = "If-None-Match")] string? ifNoneMatch) { _ = ifNoneMatch; - long id; try { - id = await _userService.GetUserIdByUsernameAsync(username); + long userId = await _userService.GetUserIdByUsernameAsync(username); + return await DataCacheHelper.GenerateActionResult(this, () => _service.GetAvatarDigestAsync(userId), () => _service.GetAvatarAsync(userId)); } - catch (UserNotExistException e) + catch (UserNotExistException) { - _logger.LogInformation(e, Log.Format(LogGetUserNotExist, ("Username", username))); return NotFound(ErrorResponse.UserCommon.NotExist()); } - return await DataCacheHelper.GenerateActionResult(this, () => _service.GetAvatarDigestAsync(id), () => _service.GetAvatarAsync(id)); } /// @@ -84,8 +73,6 @@ namespace Timeline.Controllers { if (!this.UserHasPermission(UserPermission.UserManagement) && User.Identity!.Name != username) { - _logger.LogInformation(Log.Format(LogPutForbid, - ("Operator Username", User.Identity.Name), ("Username To Put Avatar", username))); return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid()); } @@ -94,9 +81,8 @@ namespace Timeline.Controllers { id = await _userService.GetUserIdByUsernameAsync(username); } - catch (UserNotExistException e) + catch (UserNotExistException) { - _logger.LogInformation(e, Log.Format(LogPutUserNotExist, ("Username", username))); return BadRequest(ErrorResponse.UserCommon.NotExist()); } @@ -104,23 +90,18 @@ namespace Timeline.Controllers { var digest = await _service.SetAvatarAsync(id, body); - _logger.LogInformation(Log.Format(LogPutSuccess, - ("Username", username), ("Mime Type", Request.ContentType))); - Response.Headers.Append("ETag", $"\"{digest.ETag}\""); return Ok(); } catch (ImageException e) { - _logger.LogInformation(e, Log.Format(LogPutUserBadFormat, ("Username", username))); return BadRequest(e.Error switch { ImageException.ErrorReason.CantDecode => ErrorResponse.UserAvatar.BadFormat_CantDecode(), ImageException.ErrorReason.UnmatchedFormat => ErrorResponse.UserAvatar.BadFormat_UnmatchedFormat(), ImageException.ErrorReason.BadSize => ErrorResponse.UserAvatar.BadFormat_BadSize(), - _ => - throw new Exception(ExceptionUnknownAvatarFormatError) + _ => throw new Exception() }); } } @@ -143,8 +124,6 @@ namespace Timeline.Controllers { if (!this.UserHasPermission(UserPermission.UserManagement) && User.Identity!.Name != username) { - _logger.LogInformation(Log.Format(LogDeleteForbid, - ("Operator Username", User.Identity!.Name), ("Username To Delete Avatar", username))); return StatusCode(StatusCodes.Status403Forbidden, ErrorResponse.Common.Forbid()); } @@ -153,9 +132,8 @@ namespace Timeline.Controllers { id = await _userService.GetUserIdByUsernameAsync(username); } - catch (UserNotExistException e) + catch (UserNotExistException) { - _logger.LogInformation(e, Log.Format(LogDeleteNotExist, ("Username", username))); return BadRequest(ErrorResponse.UserCommon.NotExist()); } diff --git a/BackEnd/Timeline/Controllers/UserController.cs b/BackEnd/Timeline/Controllers/UserController.cs index 615eac2d..c0ae6a09 100644 --- a/BackEnd/Timeline/Controllers/UserController.cs +++ b/BackEnd/Timeline/Controllers/UserController.cs @@ -1,18 +1,14 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; using System.Collections.Generic; using System.Threading.Tasks; using Timeline.Auth; -using Timeline.Helpers; using Timeline.Models.Http; using Timeline.Models.Validation; using Timeline.Services; using Timeline.Services.Mapper; using Timeline.Services.User; -using static Timeline.Resources.Controllers.UserController; -using static Timeline.Resources.Messages; namespace Timeline.Controllers { @@ -23,16 +19,14 @@ namespace Timeline.Controllers [ProducesErrorResponseType(typeof(CommonResponse))] public class UserController : Controller { - private readonly ILogger _logger; private readonly IUserService _userService; private readonly IUserPermissionService _userPermissionService; private readonly IUserDeleteService _userDeleteService; private readonly IGenericMapper _mapper; /// - public UserController(ILogger logger, IUserService userService, IUserPermissionService userPermissionService, IUserDeleteService userDeleteService, IGenericMapper mapper) + public UserController(IUserService userService, IUserPermissionService userPermissionService, IUserDeleteService userDeleteService, IGenericMapper mapper) { - _logger = logger; _userService = userService; _userPermissionService = userPermissionService; _userDeleteService = userDeleteService; @@ -93,9 +87,8 @@ namespace Timeline.Controllers var user = await _userService.GetUserAsync(id); return await _mapper.MapAsync(user, Url, User); } - catch (UserNotExistException e) + catch (UserNotExistException) { - _logger.LogInformation(e, Log.Format(LogGetUserNotExist, ("Username", username))); return NotFound(ErrorResponse.UserCommon.NotExist()); } } @@ -122,9 +115,8 @@ namespace Timeline.Controllers var user = await _userService.ModifyUserAsync(id, _mapper.AutoMapperMap(body)); return await _mapper.MapAsync(user, Url, User); } - catch (UserNotExistException e) + catch (UserNotExistException) { - _logger.LogInformation(e, Log.Format(LogPatchUserNotExist, ("Username", username))); return NotFound(ErrorResponse.UserCommon.NotExist()); } catch (EntityAlreadyExistException e) when (e.EntityName == EntityNames.User) @@ -136,15 +128,15 @@ namespace Timeline.Controllers { if (User.Identity!.Name != username) return StatusCode(StatusCodes.Status403Forbidden, - ErrorResponse.Common.CustomMessage_Forbid(Common_Forbid_NotSelf)); + ErrorResponse.Common.CustomMessage_Forbid(Resources.Messages.Common_Forbid_NotSelf)); if (body.Username != null) return StatusCode(StatusCodes.Status403Forbidden, - ErrorResponse.Common.CustomMessage_Forbid(UserController_Patch_Forbid_Username)); + ErrorResponse.Common.CustomMessage_Forbid(Resources.Messages.UserController_Patch_Forbid_Username)); if (body.Password != null) return StatusCode(StatusCodes.Status403Forbidden, - ErrorResponse.Common.CustomMessage_Forbid(UserController_Patch_Forbid_Password)); + ErrorResponse.Common.CustomMessage_Forbid(Resources.Messages.UserController_Patch_Forbid_Password)); var user = await _userService.ModifyUserAsync(this.GetUserId(), _mapper.AutoMapperMap(body)); return await _mapper.MapAsync(user, Url, User); @@ -191,10 +183,8 @@ namespace Timeline.Controllers await _userService.ChangePassword(this.GetUserId(), request.OldPassword, request.NewPassword); return Ok(); } - catch (BadPasswordException e) + catch (BadPasswordException) { - _logger.LogInformation(e, Log.Format(LogChangePasswordBadPassword, - ("Username", User.Identity!.Name), ("Old Password", request.OldPassword))); return BadRequest(ErrorResponse.UserController.ChangePassword_BadOldPassword()); } // User can't be non-existent or the token is bad. diff --git a/BackEnd/Timeline/Helpers/Log.cs b/BackEnd/Timeline/Helpers/Log.cs deleted file mode 100644 index af0b7e13..00000000 --- a/BackEnd/Timeline/Helpers/Log.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Text; - -namespace Timeline.Helpers -{ - public static class Log - { - public static string Format(string summary, params (string, object?)[] properties) - { - var builder = new StringBuilder(); - builder.Append(summary); - foreach (var property in properties) - { - var (key, value) = property; - builder.AppendLine(); - builder.Append(key); - builder.Append(" : "); - builder.Append(value); - } - return builder.ToString(); - } - } -} diff --git a/BackEnd/Timeline/Resources/Controllers/ControllerAuthExtensions.Designer.cs b/BackEnd/Timeline/Resources/Controllers/ControllerAuthExtensions.Designer.cs deleted file mode 100644 index 70a1d605..00000000 --- a/BackEnd/Timeline/Resources/Controllers/ControllerAuthExtensions.Designer.cs +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Timeline.Resources.Controllers { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class ControllerAuthExtensions { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal ControllerAuthExtensions() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Controllers.ControllerAuthExtensions", typeof(ControllerAuthExtensions).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to Failed to get user id because User has no NameIdentifier claim.. - /// - internal static string ExceptionNoUserIdentifierClaim { - get { - return ResourceManager.GetString("ExceptionNoUserIdentifierClaim", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Failed to get user id because NameIdentifier claim is not a number.. - /// - internal static string ExceptionUserIdentifierClaimBadFormat { - get { - return ResourceManager.GetString("ExceptionUserIdentifierClaimBadFormat", resourceCulture); - } - } - } -} diff --git a/BackEnd/Timeline/Resources/Controllers/ControllerAuthExtensions.resx b/BackEnd/Timeline/Resources/Controllers/ControllerAuthExtensions.resx deleted file mode 100644 index 03e6d95a..00000000 --- a/BackEnd/Timeline/Resources/Controllers/ControllerAuthExtensions.resx +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Failed to get user id because User has no NameIdentifier claim. - - - Failed to get user id because NameIdentifier claim is not a number. - - \ No newline at end of file diff --git a/BackEnd/Timeline/Resources/Controllers/TimelineController.Designer.cs b/BackEnd/Timeline/Resources/Controllers/TimelineController.Designer.cs deleted file mode 100644 index ae6414e6..00000000 --- a/BackEnd/Timeline/Resources/Controllers/TimelineController.Designer.cs +++ /dev/null @@ -1,81 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Timeline.Resources.Controllers { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class TimelineController { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal TimelineController() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Controllers.TimelineController", typeof(TimelineController).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to An unknown timeline visibility value. Can't convert it.. - /// - internal static string ExceptionStringToVisibility { - get { - return ResourceManager.GetString("ExceptionStringToVisibility", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to An unknown TimelineMemberOperationUserException is thrown. Can't recognize its inner exception. It is rethrown.. - /// - internal static string LogUnknownTimelineMemberOperationUserException { - get { - return ResourceManager.GetString("LogUnknownTimelineMemberOperationUserException", resourceCulture); - } - } - } -} diff --git a/BackEnd/Timeline/Resources/Controllers/TimelineController.resx b/BackEnd/Timeline/Resources/Controllers/TimelineController.resx deleted file mode 100644 index 4cf3d6fb..00000000 --- a/BackEnd/Timeline/Resources/Controllers/TimelineController.resx +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - An unknown timeline visibility value. Can't convert it. - - - An unknown TimelineMemberOperationUserException is thrown. Can't recognize its inner exception. It is rethrown. - - \ No newline at end of file diff --git a/BackEnd/Timeline/Resources/Controllers/TokenController.Designer.cs b/BackEnd/Timeline/Resources/Controllers/TokenController.Designer.cs deleted file mode 100644 index a7c2864b..00000000 --- a/BackEnd/Timeline/Resources/Controllers/TokenController.Designer.cs +++ /dev/null @@ -1,153 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Timeline.Resources.Controllers { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class TokenController { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal TokenController() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Controllers.TokenController", typeof(TokenController).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to The password is wrong.. - /// - internal static string LogBadPassword { - get { - return ResourceManager.GetString("LogBadPassword", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to A user failed to create a token.. - /// - internal static string LogCreateFailure { - get { - return ResourceManager.GetString("LogCreateFailure", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to A user succeeded to create a token.. - /// - internal static string LogCreateSuccess { - get { - return ResourceManager.GetString("LogCreateSuccess", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The user does not exist.. - /// - internal static string LogUserNotExist { - get { - return ResourceManager.GetString("LogUserNotExist", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The token is of bad format. It might not be created by the server.. - /// - internal static string LogVerifyBadFormat { - get { - return ResourceManager.GetString("LogVerifyBadFormat", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The token is expired.. - /// - internal static string LogVerifyExpire { - get { - return ResourceManager.GetString("LogVerifyExpire", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to A token failed to be verified.. - /// - internal static string LogVerifyFailure { - get { - return ResourceManager.GetString("LogVerifyFailure", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Token has an old version. User might have update some info.. - /// - internal static string LogVerifyOldVersion { - get { - return ResourceManager.GetString("LogVerifyOldVersion", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to A token succeeded to be verified.. - /// - internal static string LogVerifySuccess { - get { - return ResourceManager.GetString("LogVerifySuccess", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to User does not exist. Administrator might have deleted this user.. - /// - internal static string LogVerifyUserNotExist { - get { - return ResourceManager.GetString("LogVerifyUserNotExist", resourceCulture); - } - } - } -} diff --git a/BackEnd/Timeline/Resources/Controllers/TokenController.resx b/BackEnd/Timeline/Resources/Controllers/TokenController.resx deleted file mode 100644 index 683d6cc9..00000000 --- a/BackEnd/Timeline/Resources/Controllers/TokenController.resx +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - The password is wrong. - - - A user failed to create a token. - - - A user succeeded to create a token. - - - The user does not exist. - - - The token is of bad format. It might not be created by the server. - - - The token is expired. - - - A token failed to be verified. - - - Token has an old version. User might have update some info. - - - A token succeeded to be verified. - - - User does not exist. Administrator might have deleted this user. - - \ No newline at end of file diff --git a/BackEnd/Timeline/Resources/Controllers/UserAvatarController.Designer.cs b/BackEnd/Timeline/Resources/Controllers/UserAvatarController.Designer.cs deleted file mode 100644 index b0c35ff9..00000000 --- a/BackEnd/Timeline/Resources/Controllers/UserAvatarController.Designer.cs +++ /dev/null @@ -1,144 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Timeline.Resources.Controllers { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class UserAvatarController { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal UserAvatarController() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Controllers.UserAvatarController", typeof(UserAvatarController).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to Unknown AvatarDataException.ErrorReason value.. - /// - internal static string ExceptionUnknownAvatarFormatError { - get { - return ResourceManager.GetString("ExceptionUnknownAvatarFormatError", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Attempt to delete a avatar of other user as a non-admin failed.. - /// - internal static string LogDeleteForbid { - get { - return ResourceManager.GetString("LogDeleteForbid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Attempt to delete a avatar of a non-existent user failed.. - /// - internal static string LogDeleteNotExist { - get { - return ResourceManager.GetString("LogDeleteNotExist", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Succeed to delete a avatar of a user.. - /// - internal static string LogDeleteSuccess { - get { - return ResourceManager.GetString("LogDeleteSuccess", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Attempt to get a avatar of a non-existent user failed.. - /// - internal static string LogGetUserNotExist { - get { - return ResourceManager.GetString("LogGetUserNotExist", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Attempt to put a avatar of other user as a non-admin failed.. - /// - internal static string LogPutForbid { - get { - return ResourceManager.GetString("LogPutForbid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Succeed to put a avatar of a user.. - /// - internal static string LogPutSuccess { - get { - return ResourceManager.GetString("LogPutSuccess", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Attempt to put a avatar of a bad format failed.. - /// - internal static string LogPutUserBadFormat { - get { - return ResourceManager.GetString("LogPutUserBadFormat", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Attempt to put a avatar of a non-existent user failed.. - /// - internal static string LogPutUserNotExist { - get { - return ResourceManager.GetString("LogPutUserNotExist", resourceCulture); - } - } - } -} diff --git a/BackEnd/Timeline/Resources/Controllers/UserAvatarController.resx b/BackEnd/Timeline/Resources/Controllers/UserAvatarController.resx deleted file mode 100644 index 864d96c0..00000000 --- a/BackEnd/Timeline/Resources/Controllers/UserAvatarController.resx +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Unknown AvatarDataException.ErrorReason value. - - - Attempt to delete a avatar of other user as a non-admin failed. - - - Attempt to delete a avatar of a non-existent user failed. - - - Succeed to delete a avatar of a user. - - - Attempt to get a avatar of a non-existent user failed. - - - Attempt to put a avatar of other user as a non-admin failed. - - - Succeed to put a avatar of a user. - - - Attempt to put a avatar of a bad format failed. - - - Attempt to put a avatar of a non-existent user failed. - - \ No newline at end of file diff --git a/BackEnd/Timeline/Resources/Controllers/UserController.Designer.cs b/BackEnd/Timeline/Resources/Controllers/UserController.Designer.cs deleted file mode 100644 index c8067614..00000000 --- a/BackEnd/Timeline/Resources/Controllers/UserController.Designer.cs +++ /dev/null @@ -1,117 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Timeline.Resources.Controllers { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class UserController { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal UserController() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Controllers.UserController", typeof(UserController).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to Unknown PutResult.. - /// - internal static string ExceptionUnknownPutResult { - get { - return ResourceManager.GetString("ExceptionUnknownPutResult", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Attempt to change password with wrong old password failed.. - /// - internal static string LogChangePasswordBadPassword { - get { - return ResourceManager.GetString("LogChangePasswordBadPassword", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Attempt to change a user's username to a existent one failed.. - /// - internal static string LogChangeUsernameConflict { - get { - return ResourceManager.GetString("LogChangeUsernameConflict", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Attempt to change a username of a user that does not exist failed.. - /// - internal static string LogChangeUsernameNotExist { - get { - return ResourceManager.GetString("LogChangeUsernameNotExist", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Attempt to retrieve info of a user that does not exist failed.. - /// - internal static string LogGetUserNotExist { - get { - return ResourceManager.GetString("LogGetUserNotExist", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Attempt to patch a user that does not exist failed.. - /// - internal static string LogPatchUserNotExist { - get { - return ResourceManager.GetString("LogPatchUserNotExist", resourceCulture); - } - } - } -} diff --git a/BackEnd/Timeline/Resources/Controllers/UserController.resx b/BackEnd/Timeline/Resources/Controllers/UserController.resx deleted file mode 100644 index 0bdf4845..00000000 --- a/BackEnd/Timeline/Resources/Controllers/UserController.resx +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Unknown PutResult. - - - Attempt to change password with wrong old password failed. - - - Attempt to change a user's username to a existent one failed. - - - Attempt to change a username of a user that does not exist failed. - - - Attempt to retrieve info of a user that does not exist failed. - - - Attempt to patch a user that does not exist failed. - - \ No newline at end of file diff --git a/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs b/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs index 37b55199..4fc20ecb 100644 --- a/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs +++ b/BackEnd/Timeline/Services/Api/BookmarkTimelineService.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore; -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -10,74 +9,6 @@ using Timeline.Services.User; namespace Timeline.Services.Api { - [Serializable] - public class InvalidBookmarkException : Exception - { - public InvalidBookmarkException() { } - public InvalidBookmarkException(string message) : base(message) { } - public InvalidBookmarkException(string message, Exception inner) : base(message, inner) { } - protected InvalidBookmarkException( - System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) : base(info, context) { } - } - - /// - /// Service interface that manages timeline bookmarks. - /// - public interface IBookmarkTimelineService - { - /// - /// Get bookmarks of a user. - /// - /// User id of bookmark owner. - /// Id of Bookmark timelines in order. - /// Thrown when user does not exist. - Task> GetBookmarks(long userId); - - /// - /// Check if a timeline is a bookmark. - /// - /// The user id. - /// Timeline id. - /// If true it will throw when user does not exist. - /// If true it will throw when timeline does not exist. - /// True if timeline is a bookmark. Otherwise false. - /// Throw if user does not exist and is true. - /// Thrown if timeline does not exist and is true. - Task IsBookmark(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true); - - /// - /// Add a bookmark to tail to a user. - /// - /// User id of bookmark owner. - /// Timeline id. - /// True if timeline is added to bookmark. False if it already is. - /// Thrown when user does not exist. - /// Thrown when timeline does not exist. - Task AddBookmark(long userId, long timelineId); - - /// - /// Remove a bookmark from a user. - /// - /// User id of bookmark owner. - /// Timeline id. - /// True if deletion is performed. False if bookmark does not exist. - /// Thrown when user does not exist. - /// Thrown when timeline does not exist. - Task RemoveBookmark(long userId, long timelineId); - - /// - /// Move bookmark to a new position. - /// - /// User id of bookmark owner. - /// Timeline name. - /// New position. Starts at 1. - /// Thrown when user does not exist. - /// Thrown when timeline does not exist. - /// Thrown when the timeline is not a bookmark. - Task MoveBookmark(long userId, long timelineId, long newPosition); - } - public class BookmarkTimelineService : IBookmarkTimelineService { private readonly DatabaseContext _database; @@ -91,7 +22,7 @@ namespace Timeline.Services.Api _timelineService = timelineService; } - public async Task AddBookmark(long userId, long timelineId) + public async Task AddBookmarkAsync(long userId, long timelineId) { if (!await _userService.CheckUserExistenceAsync(userId)) throw new UserNotExistException(userId); @@ -113,7 +44,7 @@ namespace Timeline.Services.Api return true; } - public async Task> GetBookmarks(long userId) + public async Task> GetBookmarksAsync(long userId) { if (!await _userService.CheckUserExistenceAsync(userId)) throw new UserNotExistException(userId); @@ -123,7 +54,7 @@ namespace Timeline.Services.Api return entities.Select(e => e.TimelineId).ToList(); } - public async Task IsBookmark(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true) + public async Task IsBookmarkAsync(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true) { if (checkUserExistence && !await _userService.CheckUserExistenceAsync(userId)) throw new UserNotExistException(userId); @@ -134,7 +65,7 @@ namespace Timeline.Services.Api return await _database.BookmarkTimelines.AnyAsync(b => b.TimelineId == timelineId && b.UserId == userId); } - public async Task MoveBookmark(long userId, long timelineId, long newPosition) + public async Task MoveBookmarkAsync(long userId, long timelineId, long newPosition) { if (!await _userService.CheckUserExistenceAsync(userId)) throw new UserNotExistException(userId); @@ -176,7 +107,7 @@ namespace Timeline.Services.Api await transaction.CommitAsync(); } - public async Task RemoveBookmark(long userId, long timelineId) + public async Task RemoveBookmarkAsync(long userId, long timelineId) { if (!await _userService.CheckUserExistenceAsync(userId)) throw new UserNotExistException(userId); diff --git a/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs b/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs index 8224f1fe..a9d831ab 100644 --- a/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs +++ b/BackEnd/Timeline/Services/Api/HighlightTimelineService.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore; -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -9,72 +8,6 @@ using Timeline.Services.User; namespace Timeline.Services.Api { - - [Serializable] - public class InvalidHighlightTimelineException : Exception - { - public InvalidHighlightTimelineException() { } - public InvalidHighlightTimelineException(string message) : base(message) { } - public InvalidHighlightTimelineException(string message, Exception inner) : base(message, inner) { } - protected InvalidHighlightTimelineException( - System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) : base(info, context) { } - } - - /// - /// Service that controls highlight timeline. - /// - public interface IHighlightTimelineService - { - /// - /// Get all highlight timelines in order. - /// - /// Id list of all highlight timelines. - Task> GetHighlightTimelines(); - - /// - /// Check if a timeline is highlight timeline. - /// - /// Timeline id. - /// If true it will throw if timeline does not exist. - /// True if timeline is highlight. Otherwise false. - /// Thrown when timeline does not exist and is true. - Task IsHighlightTimeline(long timelineId, bool checkTimelineExistence = true); - - /// - /// Add a timeline to highlight list. - /// - /// The timeline id. - /// The user id of operator. - /// True if timeline is actually added to highligh. False if it already is. - /// Thrown when timeline with given id does not exist. - /// Thrown when user with given operator id does not exist. - Task AddHighlightTimeline(long timelineId, long? operatorId); - - /// - /// Remove a timeline from highlight list. - /// - /// The timeline id. - /// The user id of operator. - /// True if deletion is actually performed. Otherwise false (timeline was not in the list). - /// Thrown when timeline with given id does not exist. - /// Thrown when user with given operator id does not exist. - Task RemoveHighlightTimeline(long timelineId, long? operatorId); - - /// - /// Move a highlight timeline to a new position. - /// - /// The timeline name. - /// The new position. Starts at 1. - /// Thrown when timeline with given id does not exist. - /// Thrown when given timeline is not a highlight timeline. - /// - /// If is smaller than 1. Then move the timeline to head. - /// If is bigger than total count. Then move the timeline to tail. - /// - Task MoveHighlightTimeline(long timelineId, long newPosition); - } - public class HighlightTimelineService : IHighlightTimelineService { private readonly DatabaseContext _database; @@ -90,7 +23,7 @@ namespace Timeline.Services.Api _clock = clock; } - public async Task AddHighlightTimeline(long timelineId, long? operatorId) + public async Task AddHighlightTimelineAsync(long timelineId, long? operatorId) { if (!await _timelineService.CheckTimelineExistenceAsync(timelineId)) throw new TimelineNotExistException(timelineId); @@ -109,14 +42,14 @@ namespace Timeline.Services.Api return true; } - public async Task> GetHighlightTimelines() + public async Task> GetHighlightTimelinesAsync() { var entities = await _database.HighlightTimelines.OrderBy(t => t.Order).Select(t => new { t.TimelineId }).ToListAsync(); return entities.Select(e => e.TimelineId).ToList(); } - public async Task RemoveHighlightTimeline(long timelineId, long? operatorId) + public async Task RemoveHighlightTimelineAsync(long timelineId, long? operatorId) { if (!await _timelineService.CheckTimelineExistenceAsync(timelineId)) throw new TimelineNotExistException(timelineId); @@ -144,7 +77,7 @@ namespace Timeline.Services.Api return true; } - public async Task MoveHighlightTimeline(long timelineId, long newPosition) + public async Task MoveHighlightTimelineAsync(long timelineId, long newPosition) { if (!await _timelineService.CheckTimelineExistenceAsync(timelineId)) throw new TimelineNotExistException(timelineId); @@ -183,7 +116,7 @@ namespace Timeline.Services.Api await transaction.CommitAsync(); } - public async Task IsHighlightTimeline(long timelineId, bool checkTimelineExistence = true) + public async Task IsHighlightTimelineAsync(long timelineId, bool checkTimelineExistence = true) { if (checkTimelineExistence && !await _timelineService.CheckTimelineExistenceAsync(timelineId)) throw new TimelineNotExistException(timelineId); diff --git a/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs b/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs new file mode 100644 index 00000000..18feee54 --- /dev/null +++ b/BackEnd/Timeline/Services/Api/IBookmarkTimelineService.cs @@ -0,0 +1,64 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Timeline.Services.Timeline; +using Timeline.Services.User; + +namespace Timeline.Services.Api +{ + /// + /// Service interface that manages timeline bookmarks. + /// + public interface IBookmarkTimelineService + { + /// + /// Get bookmarks of a user. + /// + /// User id of bookmark owner. + /// Id of Bookmark timelines in order. + /// Thrown when user does not exist. + Task> GetBookmarksAsync(long userId); + + /// + /// Check if a timeline is a bookmark. + /// + /// The user id. + /// Timeline id. + /// If true it will throw when user does not exist. + /// If true it will throw when timeline does not exist. + /// True if timeline is a bookmark. Otherwise false. + /// Throw if user does not exist and is true. + /// Thrown if timeline does not exist and is true. + Task IsBookmarkAsync(long userId, long timelineId, bool checkUserExistence = true, bool checkTimelineExistence = true); + + /// + /// Add a bookmark to tail to a user. + /// + /// User id of bookmark owner. + /// Timeline id. + /// True if timeline is added to bookmark. False if it already is. + /// Thrown when user does not exist. + /// Thrown when timeline does not exist. + Task AddBookmarkAsync(long userId, long timelineId); + + /// + /// Remove a bookmark from a user. + /// + /// User id of bookmark owner. + /// Timeline id. + /// True if deletion is performed. False if bookmark does not exist. + /// Thrown when user does not exist. + /// Thrown when timeline does not exist. + Task RemoveBookmarkAsync(long userId, long timelineId); + + /// + /// Move bookmark to a new position. + /// + /// User id of bookmark owner. + /// Timeline name. + /// New position. Starts at 1. + /// Thrown when user does not exist. + /// Thrown when timeline does not exist. + /// Thrown when the timeline is not a bookmark. + Task MoveBookmarkAsync(long userId, long timelineId, long newPosition); + } +} diff --git a/BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs b/BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs new file mode 100644 index 00000000..4f14d19b --- /dev/null +++ b/BackEnd/Timeline/Services/Api/IHighlightTimelineService.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Timeline.Services.Timeline; +using Timeline.Services.User; + +namespace Timeline.Services.Api +{ + /// + /// Service that controls highlight timeline. + /// + public interface IHighlightTimelineService + { + /// + /// Get all highlight timelines in order. + /// + /// Id list of all highlight timelines. + Task> GetHighlightTimelinesAsync(); + + /// + /// Check if a timeline is highlight timeline. + /// + /// Timeline id. + /// If true it will throw if timeline does not exist. + /// True if timeline is highlight. Otherwise false. + /// Thrown when timeline does not exist and is true. + Task IsHighlightTimelineAsync(long timelineId, bool checkTimelineExistence = true); + + /// + /// Add a timeline to highlight list. + /// + /// The timeline id. + /// The user id of operator. + /// True if timeline is actually added to highligh. False if it already is. + /// Thrown when timeline with given id does not exist. + /// Thrown when user with given operator id does not exist. + Task AddHighlightTimelineAsync(long timelineId, long? operatorId); + + /// + /// Remove a timeline from highlight list. + /// + /// The timeline id. + /// The user id of operator. + /// True if deletion is actually performed. Otherwise false (timeline was not in the list). + /// Thrown when timeline with given id does not exist. + /// Thrown when user with given operator id does not exist. + Task RemoveHighlightTimelineAsync(long timelineId, long? operatorId); + + /// + /// Move a highlight timeline to a new position. + /// + /// The timeline name. + /// The new position. Starts at 1. + /// Thrown when timeline with given id does not exist. + /// Thrown when given timeline is not a highlight timeline. + /// + /// If is smaller than 1. Then move the timeline to head. + /// If is bigger than total count. Then move the timeline to tail. + /// + Task MoveHighlightTimelineAsync(long timelineId, long newPosition); + } +} diff --git a/BackEnd/Timeline/Services/Api/ISearchService.cs b/BackEnd/Timeline/Services/Api/ISearchService.cs new file mode 100644 index 00000000..d8b4bb44 --- /dev/null +++ b/BackEnd/Timeline/Services/Api/ISearchService.cs @@ -0,0 +1,33 @@ +using System; +using System.Threading.Tasks; +using Timeline.Entities; + +namespace Timeline.Services.Api +{ + public interface ISearchService + { + /// + /// Search timelines whose name or title contains query string. + /// + /// String to contain. + /// Search results. + /// Thrown when is null. + /// Thrown when is empty. + /// + /// Implementation should promise high score is at first. + /// + Task> SearchTimelineAsync(string query); + + /// + /// Search users whose username or nickname contains query string. + /// + /// String to contain. + /// Search results. + /// Thrown when is null. + /// Thrown when is empty. + /// + /// Implementation should promise high score is at first. + /// + Task> SearchUserAsync(string query); + } +} diff --git a/BackEnd/Timeline/Services/Api/InvalidBookmarkException.cs b/BackEnd/Timeline/Services/Api/InvalidBookmarkException.cs new file mode 100644 index 00000000..39572b38 --- /dev/null +++ b/BackEnd/Timeline/Services/Api/InvalidBookmarkException.cs @@ -0,0 +1,15 @@ +using System; + +namespace Timeline.Services.Api +{ + [Serializable] + public class InvalidBookmarkException : Exception + { + public InvalidBookmarkException() { } + public InvalidBookmarkException(string message) : base(message) { } + public InvalidBookmarkException(string message, Exception inner) : base(message, inner) { } + protected InvalidBookmarkException( + System.Runtime.Serialization.SerializationInfo info, + System.Runtime.Serialization.StreamingContext context) : base(info, context) { } + } +} diff --git a/BackEnd/Timeline/Services/Api/InvalidHighlightTimelineException.cs b/BackEnd/Timeline/Services/Api/InvalidHighlightTimelineException.cs new file mode 100644 index 00000000..13b04a6b --- /dev/null +++ b/BackEnd/Timeline/Services/Api/InvalidHighlightTimelineException.cs @@ -0,0 +1,15 @@ +using System; + +namespace Timeline.Services.Api +{ + [Serializable] + public class InvalidHighlightTimelineException : Exception + { + public InvalidHighlightTimelineException() { } + public InvalidHighlightTimelineException(string message) : base(message) { } + public InvalidHighlightTimelineException(string message, Exception inner) : base(message, inner) { } + protected InvalidHighlightTimelineException( + System.Runtime.Serialization.SerializationInfo info, + System.Runtime.Serialization.StreamingContext context) : base(info, context) { } + } +} diff --git a/BackEnd/Timeline/Services/Api/SearchResult.cs b/BackEnd/Timeline/Services/Api/SearchResult.cs new file mode 100644 index 00000000..7c95ae5d --- /dev/null +++ b/BackEnd/Timeline/Services/Api/SearchResult.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace Timeline.Services.Api +{ + public class SearchResult + { +#pragma warning disable CA2227 // Collection properties should be read only + public List> Items { get; set; } = new(); +#pragma warning restore CA2227 // Collection properties should be read only + } +} diff --git a/BackEnd/Timeline/Services/Api/SearchResultItem.cs b/BackEnd/Timeline/Services/Api/SearchResultItem.cs new file mode 100644 index 00000000..ac40281f --- /dev/null +++ b/BackEnd/Timeline/Services/Api/SearchResultItem.cs @@ -0,0 +1,18 @@ +namespace Timeline.Services.Api +{ + public class SearchResultItem + { + public SearchResultItem(TItem item, int score) + { + Item = item; + Score = score; + } + + public TItem Item { get; set; } = default!; + + /// + /// Bigger is better. + /// + public int Score { get; set; } + } +} diff --git a/BackEnd/Timeline/Services/Api/SearchService.cs b/BackEnd/Timeline/Services/Api/SearchService.cs index eec5001f..037f0490 100644 --- a/BackEnd/Timeline/Services/Api/SearchService.cs +++ b/BackEnd/Timeline/Services/Api/SearchService.cs @@ -1,62 +1,11 @@ using Microsoft.EntityFrameworkCore; using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Timeline.Entities; namespace Timeline.Services.Api { - public class SearchResultItem - { - public SearchResultItem(TItem item, int score) - { - Item = item; - Score = score; - } - - public TItem Item { get; set; } = default!; - - /// - /// Bigger is better. - /// - public int Score { get; set; } - } - - public class SearchResult - { -#pragma warning disable CA2227 // Collection properties should be read only - public List> Items { get; set; } = new(); -#pragma warning restore CA2227 // Collection properties should be read only - } - - public interface ISearchService - { - /// - /// Search timelines whose name or title contains query string. - /// - /// String to contain. - /// Search results. - /// Thrown when is null. - /// Thrown when is empty. - /// - /// Implementation should promise high score is at first. - /// - Task> SearchTimeline(string query); - - /// - /// Search users whose username or nickname contains query string. - /// - /// String to contain. - /// Search results. - /// Thrown when is null. - /// Thrown when is empty. - /// - /// Implementation should promise high score is at first. - /// - Task> SearchUser(string query); - } - public class SearchService : ISearchService { private readonly DatabaseContext _database; @@ -66,7 +15,7 @@ namespace Timeline.Services.Api _database = database; } - public async Task> SearchTimeline(string query) + public async Task> SearchTimelineAsync(string query) { if (query is null) throw new ArgumentNullException(nameof(query)); @@ -83,7 +32,7 @@ namespace Timeline.Services.Api return searchResult; } - public async Task> SearchUser(string query) + public async Task> SearchUserAsync(string query) { if (query is null) throw new ArgumentNullException(nameof(query)); diff --git a/BackEnd/Timeline/Services/Mapper/TimelineMapper.cs b/BackEnd/Timeline/Services/Mapper/TimelineMapper.cs index 5ee90a8f..d3159423 100644 --- a/BackEnd/Timeline/Services/Mapper/TimelineMapper.cs +++ b/BackEnd/Timeline/Services/Mapper/TimelineMapper.cs @@ -85,8 +85,8 @@ namespace Timeline.Services.Mapper color: entity.Color, createTime: entity.CreateTime, lastModified: entity.LastModified, - isHighlight: await _highlightTimelineService.IsHighlightTimeline(entity.Id), - isBookmark: userId is not null && await _bookmarkTimelineService.IsBookmark(userId.Value, entity.Id, false, false), + isHighlight: await _highlightTimelineService.IsHighlightTimelineAsync(entity.Id), + isBookmark: userId is not null && await _bookmarkTimelineService.IsBookmarkAsync(userId.Value, entity.Id, false, false), manageable: manageable, postable: postable, links: new HttpTimelineLinks( diff --git a/BackEnd/Timeline/Timeline.csproj b/BackEnd/Timeline/Timeline.csproj index f77631c2..ace1aab5 100644 --- a/BackEnd/Timeline/Timeline.csproj +++ b/BackEnd/Timeline/Timeline.csproj @@ -15,7 +15,7 @@ true true - 1701;1702;1591 + 1591 @@ -58,31 +58,6 @@ True Resource.resx - - True - True - ControllerAuthExtensions.resx - - - True - True - TimelineController.resx - - - True - True - TokenController.resx - - - True - True - UserAvatarController.resx - - - True - True - UserController.resx - True True @@ -184,27 +159,6 @@ ResXFileCodeGenerator Resource.Designer.cs - - ResXFileCodeGenerator - ControllerAuthExtensions.Designer.cs - - - ResXFileCodeGenerator - TimelineController.Designer.cs - - - Designer - ResXFileCodeGenerator - TokenController.Designer.cs - - - ResXFileCodeGenerator - UserAvatarController.Designer.cs - - - ResXFileCodeGenerator - UserController.Designer.cs - ResXFileCodeGenerator Entities.Designer.cs -- cgit v1.2.3