From 5f53d2312f028b029df806ff1d68d3503720f746 Mon Sep 17 00:00:00 2001 From: wuweilai <30889371+15168440402@users.noreply.github.com> Date: Mon, 29 Aug 2022 16:08:34 +0800 Subject: [PATCH] feat(user): add updateUseremailModel (#220) * feat(user): add updateUseremailModel * refactor:refactor code * feat(user):upsertUserModel add roleNames * refactor:refactor code --- .../Enum/SendMsgCodeTypes.cs | 10 +++++++ .../SendMsgCodeForUpdatePhoneNumberModel.cs | 17 ------------ .../Model/SendMsgCodeForVerificationModel.cs | 14 ---------- .../Model/SendMsgCodeModel.cs | 24 +++++++++++++++++ .../Model/UpdateStaffAvatarModel.cs | 6 ++++- .../Model/UpdateUserAvatarModel.cs | 6 ++++- .../Model/UpdateUserEmailModel.cs | 22 +++++++++++++++ .../Model/UpdateUserPhoneNumberModel.cs | 8 ++++-- .../Model/UpsertUserModel.cs | 2 ++ .../Service/IUserService.cs | 6 ++--- .../Service/UserService.cs | 20 ++++---------- .../UserServiceTest.cs | 27 +++++-------------- 12 files changed, 88 insertions(+), 74 deletions(-) create mode 100644 src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/SendMsgCodeTypes.cs delete mode 100644 src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendMsgCodeForUpdatePhoneNumberModel.cs delete mode 100644 src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendMsgCodeForVerificationModel.cs create mode 100644 src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendMsgCodeModel.cs create mode 100644 src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateUserEmailModel.cs diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/SendMsgCodeTypes.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/SendMsgCodeTypes.cs new file mode 100644 index 000000000..d1784e747 --- /dev/null +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Enum/SendMsgCodeTypes.cs @@ -0,0 +1,10 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Enum; + +public enum SendMsgCodeTypes +{ + VerifiyPhoneNumber = 1, + UpdatePhoneNumber +} diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendMsgCodeForUpdatePhoneNumberModel.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendMsgCodeForUpdatePhoneNumberModel.cs deleted file mode 100644 index 02552ea94..000000000 --- a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendMsgCodeForUpdatePhoneNumberModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the MIT License. See LICENSE.txt in the project root for license information. - -namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model; - -public class SendMsgCodeForUpdatePhoneNumberModel -{ - public Guid UserId { get; set; } - - public string PhoneNumber { get; set; } - - public SendMsgCodeForUpdatePhoneNumberModel(Guid userId, string phoneNumber) - { - UserId = userId; - PhoneNumber = phoneNumber; - } -} diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendMsgCodeForVerificationModel.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendMsgCodeForVerificationModel.cs deleted file mode 100644 index 05ca73d20..000000000 --- a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendMsgCodeForVerificationModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) MASA Stack All rights reserved. -// Licensed under the MIT License. See LICENSE.txt in the project root for license information. - -namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model; - -public class SendMsgCodeForVerificationModel -{ - public Guid UserId { get; set; } - - public SendMsgCodeForVerificationModel(Guid userId) - { - UserId = userId; - } -} diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendMsgCodeModel.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendMsgCodeModel.cs new file mode 100644 index 000000000..751da080c --- /dev/null +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/SendMsgCodeModel.cs @@ -0,0 +1,24 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model; + +public class SendMsgCodeModel +{ + public Guid UserId { get; set; } + + public string PhoneNumber { get; set; } = ""; + + public SendMsgCodeTypes SendMsgCodeType { get; set; } = SendMsgCodeTypes.VerifiyPhoneNumber; + + public SendMsgCodeModel() + { + } + + public SendMsgCodeModel(Guid userId, string phoneNumber, SendMsgCodeTypes sendMsgCodeType) + { + UserId = userId; + PhoneNumber = phoneNumber; + SendMsgCodeType = sendMsgCodeType; + } +} diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateStaffAvatarModel.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateStaffAvatarModel.cs index afa9ca6ce..f280d0fbe 100644 --- a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateStaffAvatarModel.cs +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateStaffAvatarModel.cs @@ -7,7 +7,11 @@ public class UpdateStaffAvatarModel { public Guid UserId { get; set; } - public string Avatar { get; set; } + public string Avatar { get; set; } = ""; + + public UpdateStaffAvatarModel() + { + } public UpdateStaffAvatarModel(Guid userId, string avatar) { diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateUserAvatarModel.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateUserAvatarModel.cs index d2e01b9ac..84c375889 100644 --- a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateUserAvatarModel.cs +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateUserAvatarModel.cs @@ -7,7 +7,11 @@ public class UpdateUserAvatarModel { public Guid Id { get; set; } - public string Avatar { get; set; } + public string Avatar { get; set; } = ""; + + public UpdateUserAvatarModel() + { + } public UpdateUserAvatarModel(Guid id, string avatar) { diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateUserEmailModel.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateUserEmailModel.cs new file mode 100644 index 000000000..11fa19223 --- /dev/null +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateUserEmailModel.cs @@ -0,0 +1,22 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model; + +public class UpdateUserEmailModel +{ + public Guid Id { get; set; } + + public string Email { get; set; } = ""; + + public UpdateUserEmailModel() + { + + } + + public UpdateUserEmailModel(Guid id, string email) + { + Id = id; + Email = email; + } +} diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateUserPhoneNumberModel.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateUserPhoneNumberModel.cs index abf54a4fa..0fe942e53 100644 --- a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateUserPhoneNumberModel.cs +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpdateUserPhoneNumberModel.cs @@ -7,9 +7,13 @@ public class UpdateUserPhoneNumberModel { public Guid Id { get; set; } - public string PhoneNumber { get; set; } + public string PhoneNumber { get; set; } = ""; - public string VerificationCode { get; set; } + public string VerificationCode { get; set; } = ""; + + public UpdateUserPhoneNumberModel() + { + } public UpdateUserPhoneNumberModel(Guid id, string phoneNumber, string verificationCode) { diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpsertUserModel.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpsertUserModel.cs index 21c83eb5d..23ba2cdee 100644 --- a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpsertUserModel.cs +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/UpsertUserModel.cs @@ -6,5 +6,7 @@ namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model; public class UpsertUserModel : AddUserModel { public Guid Id { get; set; } + + public List RoleNames { get; set; } = new(); } diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IUserService.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IUserService.cs index e799f4a5b..d8364ff39 100644 --- a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IUserService.cs +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IUserService.cs @@ -45,13 +45,11 @@ public interface IUserService Task UpdateStaffAvatarAsync(UpdateStaffAvatarModel staff); - Task SendMsgCodeForVerificationAsync(SendMsgCodeForVerificationModel model); + Task SendMsgCodeAsync(SendMsgCodeModel model); Task VerifyMsgCodeAsync(VerifyMsgCodeModel model); - Task SendMsgCodeForUpdatePhoneNumberAsync(SendMsgCodeForUpdatePhoneNumberModel model); - - Task UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user); + Task UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user); Task UpdateBasicInfoAsync(UpdateUserBasicInfoModel user); diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/UserService.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/UserService.cs index 05c98f103..ed5c59541 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/UserService.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/UserService.cs @@ -205,13 +205,13 @@ public async Task> GetListByAccountAsync(IEnumerable>(requestUri, new { accounts = string.Join(',', accounts) }) ?? new(); } - public async Task SendMsgCodeForVerificationAsync(SendMsgCodeForVerificationModel model) + public async Task SendMsgCodeAsync(SendMsgCodeModel model) { if (model.UserId == Guid.Empty) { model.UserId = _userContext.GetUserId(); } - var requestUri = $"api/user/sendMsgCodeForVerification"; + var requestUri = $"api/user/sendMsgCode"; await _caller.PostAsync(requestUri, model); } @@ -225,24 +225,14 @@ public async Task VerifyMsgCodeAsync(VerifyMsgCodeModel model) return await _caller.PostAsync(requestUri, model); } - public async Task SendMsgCodeForUpdatePhoneNumberAsync(SendMsgCodeForUpdatePhoneNumberModel model) - { - if (model.UserId == Guid.Empty) - { - model.UserId = _userContext.GetUserId(); - } - var requestUri = $"api/user/sendMsgCodeForUpdatePhoneNumber"; - await _caller.PostAsync(requestUri, model); - } - - public async Task UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user) + public async Task UpdatePhoneNumberAsync(UpdateUserPhoneNumberModel user) { if (user.Id == Guid.Empty) { user.Id = _userContext.GetUserId(); } - var requestUri = $"api/user/updateUserPhoneNumber"; - await _caller.PutAsync(requestUri, user); + var requestUri = $"api/user/updatePhoneNumber"; + return await _caller.PutAsync(requestUri, user); } } diff --git a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Auth.Tests/UserServiceTest.cs b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Auth.Tests/UserServiceTest.cs index 35ca9f0ee..c7286047e 100644 --- a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Auth.Tests/UserServiceTest.cs +++ b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Auth.Tests/UserServiceTest.cs @@ -329,15 +329,15 @@ public async Task TestUpdateStaffAvatarAsync() } [TestMethod] - public async Task TestSendMsgCodeForVerificationAsync() + public async Task SendMsgCodeAsync() { - var code = new SendMsgCodeForVerificationModel(default); - var requestUri = $"api/user/sendMsgCodeForVerification"; + var code = new SendMsgCodeModel(); + var requestUri = $"api/user/sendMsgCode"; var caller = new Mock(); caller.Setup(provider => provider.PostAsync(requestUri, code, true, default)).Verifiable(); var userContext = new Mock(); var userService = new UserService(caller.Object, userContext.Object); - await userService.SendMsgCodeForVerificationAsync(code); + await userService.SendMsgCodeAsync(code); caller.Verify(provider => provider.PostAsync(requestUri, code, true, default), Times.Once); } @@ -354,30 +354,17 @@ public async Task TestVerifyMsgCodeAsync() caller.Verify(provider => provider.PostAsync(requestUri, code, default), Times.Once); } - [TestMethod] - public async Task TestSendMsgCodeForUpdatePhoneNumberAsync() - { - var code = new SendMsgCodeForUpdatePhoneNumberModel(default, "283417"); - var requestUri = $"api/user/sendMsgCodeForUpdatePhoneNumber"; - var caller = new Mock(); - caller.Setup(provider => provider.PostAsync(requestUri, code, true, default)).Verifiable(); - var userContext = new Mock(); - var userService = new UserService(caller.Object, userContext.Object); - await userService.SendMsgCodeForUpdatePhoneNumberAsync(code); - caller.Verify(provider => provider.PostAsync(requestUri, code, true, default), Times.Once); - } - [TestMethod] public async Task TestUpdateUserPhoneNumberAsync() { var user = new UpdateUserPhoneNumberModel(Guid.NewGuid(), "15168440403", "123453"); - var requestUri = $"api/user/updateUserPhoneNumber"; + var requestUri = $"api/user/updatePhoneNumber"; var caller = new Mock(); - caller.Setup(provider => provider.PutAsync(requestUri, user, true, default)).Verifiable(); + caller.Setup(provider => provider.PutAsync(requestUri, user, default)).Verifiable(); var userContext = new Mock(); var userService = new UserService(caller.Object, userContext.Object); await userService.UpdatePhoneNumberAsync(user); - caller.Verify(provider => provider.PutAsync(requestUri, user, true, default), Times.Once); + caller.Verify(provider => provider.PutAsync(requestUri, user, default), Times.Once); }