From c2750f3e8eda23a9666f4a47fb7a926352866464 Mon Sep 17 00:00:00 2001 From: wuweilai <30889371+15168440402@users.noreply.github.com> Date: Fri, 24 Feb 2023 14:05:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:add=20FindListByAccountsAsync=E3=80=81GetU?= =?UTF-8?q?serSystemDataAsync=20(#469)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/IUserService.cs | 4 +++ .../Service/UserService.cs | 20 +++++++++-- .../UserServiceTest.cs | 34 +++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) 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 bd800d60c..cec0635d6 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 @@ -31,6 +31,8 @@ public interface IUserService Task FindByAccountAsync(string account); + Task> FindListByAccountsAsync(IEnumerable account); + Task FindByPhoneNumberAsync(string phoneNumber); Task FindByEmailAsync(string email); @@ -71,6 +73,8 @@ public interface IUserService Task GetUserSystemDataAsync(Guid userId, string systemId); + Task> GetUserSystemDataAsync(IEnumerable userIds, string systemId); + Task DisableUserAsync(DisableUserModel user); Task> GetListByAccountAsync(IEnumerable accounts); 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 6f6950ac0..51bef2ef9 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/UserService.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/UserService.cs @@ -82,6 +82,12 @@ public async Task GetTotalByTeamAsync(Guid teamId) return await _caller.GetAsync(requestUri, new { account }); } + public async Task> FindListByAccountsAsync(IEnumerable accounts) + { + var requestUri = $"api/user/byAccounts"; + return await _caller.GetAsync>(requestUri, new { accounts = string.Join(',', accounts) }) ?? new(); + } + public async Task FindByPhoneNumberAsync(string phoneNumber) { var requestUri = $"api/user/byPhoneNumber"; @@ -202,17 +208,24 @@ public async Task SaveUserSystemDataAsync(string systemId, T data) { var userId = _userContext.GetUserId(); var requestUri = $"api/user/systemData"; - var data = await _caller.GetAsync(requestUri, new { userId = userId, systemId = systemId }); + var data = await _caller.GetAsync(requestUri, new { userId, systemId }); return data is null ? default : JsonSerializer.Deserialize(data); } public async Task GetUserSystemDataAsync(Guid userId, string systemId) { var requestUri = $"api/user/systemData"; - var data = await _caller.GetAsync(requestUri, new { userId = userId, systemId = systemId }); + var data = await _caller.GetAsync(requestUri, new { userId, systemId }); return data is null ? default : JsonSerializer.Deserialize(data); } + public async Task> GetUserSystemDataAsync(IEnumerable userIds, string systemId) + { + var requestUri = $"api/user/systemData/byIds"; + var data = await _caller.GetAsync(requestUri, new { userIds = string.Join(',', userIds), systemId }); + return data is null ? new() : JsonSerializer.Deserialize>(data) ?? new(); + } + public async Task DisableUserAsync(DisableUserModel user) { var requestUri = $"api/user/disable"; @@ -346,7 +359,8 @@ public async Task ResetPasswordByPhoneAsync(ResetPasswordByPhoneModel rese public async Task RemoveAsync(Guid id) { - await _caller.DeleteAsync("api/user", new RemoveUserModel(id)); + var requestUri = "api/user"; + await _caller.DeleteAsync(requestUri, new RemoveUserModel(id)); } } 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 fba99a89d..c026fb84e 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 @@ -198,6 +198,20 @@ public async Task TestFindByAccountAsync(string account) Assert.IsTrue(result is not null); } + [TestMethod] + public async Task TestFindListByAccountsAsync() + { + var accounts = new List { "account" }; + var data = new List(); + var requestUri = $"api/user/byAccounts"; + var caller = new Mock(); + caller.Setup(provider => provider.GetAsync>(requestUri, It.IsAny(), default)).ReturnsAsync(data).Verifiable(); + var userService = GetUserService(caller); + var result = await userService.FindListByAccountsAsync(accounts); + caller.Verify(provider => provider.GetAsync>(requestUri, It.IsAny(), default), Times.Once); + Assert.IsTrue(result is not null); + } + [TestMethod] [DataRow("15168440403")] public async Task TestFindByPhoneNumberAsync(string phoneNumber) @@ -510,6 +524,26 @@ public async Task TestObjectGetUserSystemDataAsync(string systemId) Assert.IsTrue(result is not null); } + [TestMethod] + [DataRow("masa-auth")] + public async Task TestGetUserSystemDataAsync(string systemId) + { + var userIds = new List { Guid.NewGuid() }; + var data = new SystemData + { + Name = "name", + Value = "value" + }; + var requestUri = $"api/user/systemData/byIds"; + var caller = new Mock(); + caller.Setup(provider => provider.GetAsync(requestUri, new { userIds = string.Join(',', userIds), systemId }, default)) + .ReturnsAsync(JsonSerializer.Serialize(data)).Verifiable(); + var userContext = new Mock(); + var userService = GetUserService(caller, userContext); + var result = await userService.GetUserSystemDataAsync(userIds, systemId); + Assert.IsTrue(result is not null); + } + [TestMethod] [DataRow("masa-auth")] public async Task TestIntSaveUserSystemDataAsync(string systemId)