Skip to content

Commit

Permalink
feat:add FindListByAccountsAsync、GetUserSystemDataAsync (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuweilaiya authored Feb 24, 2023
1 parent f8c7d58 commit c2750f3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public interface IUserService

Task<UserModel?> FindByAccountAsync(string account);

Task<List<UserModel>> FindListByAccountsAsync(IEnumerable<string> account);

Task<UserModel?> FindByPhoneNumberAsync(string phoneNumber);

Task<UserModel?> FindByEmailAsync(string email);
Expand Down Expand Up @@ -71,6 +73,8 @@ public interface IUserService

Task<T?> GetUserSystemDataAsync<T>(Guid userId, string systemId);

Task<List<T>> GetUserSystemDataAsync<T>(IEnumerable<Guid> userIds, string systemId);

Task<bool> DisableUserAsync(DisableUserModel user);

Task<List<UserSimpleModel>> GetListByAccountAsync(IEnumerable<string> accounts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public async Task<long> GetTotalByTeamAsync(Guid teamId)
return await _caller.GetAsync<object, UserModel>(requestUri, new { account });
}

public async Task<List<UserModel>> FindListByAccountsAsync(IEnumerable<string> accounts)
{
var requestUri = $"api/user/byAccounts";
return await _caller.GetAsync<List<UserModel>>(requestUri, new { accounts = string.Join(',', accounts) }) ?? new();
}

public async Task<UserModel?> FindByPhoneNumberAsync(string phoneNumber)
{
var requestUri = $"api/user/byPhoneNumber";
Expand Down Expand Up @@ -202,17 +208,24 @@ public async Task SaveUserSystemDataAsync<T>(string systemId, T data)
{
var userId = _userContext.GetUserId<Guid>();
var requestUri = $"api/user/systemData";
var data = await _caller.GetAsync<object, string>(requestUri, new { userId = userId, systemId = systemId });
var data = await _caller.GetAsync<object, string>(requestUri, new { userId, systemId });
return data is null ? default : JsonSerializer.Deserialize<T>(data);
}

public async Task<T?> GetUserSystemDataAsync<T>(Guid userId, string systemId)
{
var requestUri = $"api/user/systemData";
var data = await _caller.GetAsync<object, string>(requestUri, new { userId = userId, systemId = systemId });
var data = await _caller.GetAsync<object, string>(requestUri, new { userId, systemId });
return data is null ? default : JsonSerializer.Deserialize<T>(data);
}

public async Task<List<T>> GetUserSystemDataAsync<T>(IEnumerable<Guid> userIds, string systemId)
{
var requestUri = $"api/user/systemData/byIds";
var data = await _caller.GetAsync<object, string>(requestUri, new { userIds = string.Join(',', userIds), systemId });
return data is null ? new() : JsonSerializer.Deserialize<List<T>>(data) ?? new();
}

public async Task<bool> DisableUserAsync(DisableUserModel user)
{
var requestUri = $"api/user/disable";
Expand Down Expand Up @@ -346,7 +359,8 @@ public async Task<bool> 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));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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<string> { "account" };
var data = new List<UserModel>();
var requestUri = $"api/user/byAccounts";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.GetAsync<List<UserModel>>(requestUri, It.IsAny<object>(), default)).ReturnsAsync(data).Verifiable();
var userService = GetUserService(caller);
var result = await userService.FindListByAccountsAsync(accounts);
caller.Verify(provider => provider.GetAsync<List<UserModel>>(requestUri, It.IsAny<object>(), default), Times.Once);
Assert.IsTrue(result is not null);
}

[TestMethod]
[DataRow("15168440403")]
public async Task TestFindByPhoneNumberAsync(string phoneNumber)
Expand Down Expand Up @@ -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> { Guid.NewGuid() };
var data = new SystemData
{
Name = "name",
Value = "value"
};
var requestUri = $"api/user/systemData/byIds";
var caller = new Mock<ICaller>();
caller.Setup(provider => provider.GetAsync<object, string>(requestUri, new { userIds = string.Join(',', userIds), systemId }, default))
.ReturnsAsync(JsonSerializer.Serialize(data)).Verifiable();
var userContext = new Mock<IUserContext>();
var userService = GetUserService(caller, userContext);
var result = await userService.GetUserSystemDataAsync<SystemData>(userIds, systemId);
Assert.IsTrue(result is not null);
}

[TestMethod]
[DataRow("masa-auth")]
public async Task TestIntSaveUserSystemDataAsync(string systemId)
Expand Down

0 comments on commit c2750f3

Please sign in to comment.