Merge pull request #69 from Qtoss-AI/hdongDev
hdong: add search user logic.
This commit is contained in:
commit
1c71836226
|
|
@ -48,6 +48,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
|
|||
void UpdateUserIsDisable(string userId, bool isDisable) => throw new NotImplementedException();
|
||||
void UpdateUsersIsDisable(List<string> userIds, bool isDisable) => throw new NotImplementedException();
|
||||
PagedItems<User> GetUsers(UserFilter filter) => throw new NotImplementedException();
|
||||
List<User> SearchLoginUsers(User filter, string source = UserSource.Internal) =>throw new NotImplementedException();
|
||||
User? GetUserDetails(string userId, bool includeAgent = false) => throw new NotImplementedException();
|
||||
bool UpdateUser(User user, bool updateUserAgents = false) => throw new NotImplementedException();
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ public interface IUserService
|
|||
{
|
||||
Task<User> GetUser(string id);
|
||||
Task<PagedItems<User>> GetUsers(UserFilter filter);
|
||||
Task<List<User>> SearchLoginUsers(User filter);
|
||||
Task<User?> GetUserDetails(string userId, bool includeAgent = false);
|
||||
Task<bool> IsAdminUser(string userId);
|
||||
Task<UserAuthorization> GetUserAuthorizations(IEnumerable<string>? agentIds = null);
|
||||
|
|
|
|||
|
|
@ -128,6 +128,63 @@ public partial class FileRepository
|
|||
};
|
||||
}
|
||||
|
||||
public List<User> SearchLoginUsers(User filter, string source = UserSource.Internal)
|
||||
{
|
||||
List<User> searchResult = new List<User>();
|
||||
|
||||
// search by filters
|
||||
if (!string.IsNullOrWhiteSpace(filter.Id))
|
||||
{
|
||||
var curUser = Users.FirstOrDefault(x => x.Source == source && x.Id == filter.Id.ToLower());
|
||||
User user = curUser != null ? curUser : null;
|
||||
if (user != null)
|
||||
{
|
||||
searchResult.Add(user);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(filter.Phone) && !string.IsNullOrWhiteSpace(filter.RegionCode))
|
||||
{
|
||||
string[] regionCodeData = filter.RegionCode.Split('|');
|
||||
if (regionCodeData.Length == 2)
|
||||
{
|
||||
string phoneNoCallingCode = filter.Phone;
|
||||
string phoneWithCallingCode = filter.Phone;
|
||||
if (!filter.Phone.StartsWith('+'))
|
||||
{
|
||||
phoneNoCallingCode = filter.Phone;
|
||||
phoneWithCallingCode = $"{regionCodeData[1]}{filter.Phone}";
|
||||
}
|
||||
else
|
||||
{
|
||||
phoneNoCallingCode = filter.Phone.Replace(regionCodeData[1], "");
|
||||
}
|
||||
searchResult = Users.AsQueryable()
|
||||
.Where(x => x.Source == source && (x.Phone == phoneNoCallingCode || x.Phone == phoneWithCallingCode) && x.RegionCode == regionCodeData[0])
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(filter.Email))
|
||||
{
|
||||
var curUser = Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.Email == filter.Email.ToString());
|
||||
User user = curUser != null ? curUser : null;
|
||||
if (user != null)
|
||||
{
|
||||
searchResult.Add(user);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(filter.UserName))
|
||||
{
|
||||
var curUser = Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.UserName == filter.UserName);
|
||||
User user = curUser != null ? curUser : null;
|
||||
if (user != null)
|
||||
{
|
||||
searchResult.Add(user);
|
||||
}
|
||||
}
|
||||
|
||||
return searchResult;
|
||||
}
|
||||
|
||||
public User? GetUserDetails(string userId, bool includeAgent = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(userId)) return null;
|
||||
|
|
|
|||
|
|
@ -570,6 +570,18 @@ public class UserService : IUserService
|
|||
return false;
|
||||
}
|
||||
|
||||
public async Task<List<User>> SearchLoginUsers(User filter)
|
||||
{
|
||||
if (filter == null)
|
||||
{
|
||||
return new List<User>();
|
||||
}
|
||||
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
|
||||
return db.SearchLoginUsers(filter);
|
||||
}
|
||||
|
||||
public async Task<bool> VerifyPhoneExisting(string phone, string regionCode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(phone))
|
||||
|
|
|
|||
|
|
@ -233,6 +233,75 @@ public partial class MongoRepository
|
|||
};
|
||||
}
|
||||
|
||||
public List<User> SearchLoginUsers(User filter, string source = UserSource.Internal)
|
||||
{
|
||||
List<User> searchResult = new List<User>();
|
||||
|
||||
// search by filters
|
||||
if (!string.IsNullOrWhiteSpace(filter.Id))
|
||||
{
|
||||
var curUser = _dc.Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.Id == filter.Id.ToLower());
|
||||
User user = curUser != null ? curUser.ToUser() : null;
|
||||
if (user != null)
|
||||
{
|
||||
searchResult.Add(user);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(filter.Phone) && !string.IsNullOrWhiteSpace(filter.RegionCode))
|
||||
{
|
||||
string[] regionCodeData = filter.RegionCode.Split('|');
|
||||
if (regionCodeData.Length == 2)
|
||||
{
|
||||
string phoneNoCallingCode = filter.Phone;
|
||||
string phoneWithCallingCode = filter.Phone;
|
||||
if (!filter.Phone.StartsWith('+'))
|
||||
{
|
||||
phoneNoCallingCode = filter.Phone;
|
||||
phoneWithCallingCode = $"{regionCodeData[1]}{filter.Phone}";
|
||||
}
|
||||
else
|
||||
{
|
||||
phoneNoCallingCode = filter.Phone.Replace(regionCodeData[1], "");
|
||||
}
|
||||
var phoneUsers = _dc.Users.AsQueryable()
|
||||
.Where(x => x.Source == source && (x.Phone == phoneNoCallingCode || x.Phone == phoneWithCallingCode) && x.RegionCode == regionCodeData[0])
|
||||
.ToList();
|
||||
|
||||
if (phoneUsers != null && phoneUsers.Count > 0)
|
||||
{
|
||||
foreach (var user in phoneUsers)
|
||||
{
|
||||
if (user != null)
|
||||
{
|
||||
searchResult.Add(user.ToUser());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(filter.Email))
|
||||
{
|
||||
var curUser = _dc.Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.Email == filter.Email.ToString());
|
||||
User user = curUser != null ? curUser.ToUser() : null;
|
||||
if (user != null)
|
||||
{
|
||||
searchResult.Add(user);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(filter.UserName))
|
||||
{
|
||||
var curUser = _dc.Users.AsQueryable().FirstOrDefault(x => x.Source == source && x.UserName == filter.UserName);
|
||||
User user = curUser != null ? curUser.ToUser() : null;
|
||||
if (user != null)
|
||||
{
|
||||
searchResult.Add(user);
|
||||
}
|
||||
}
|
||||
|
||||
return searchResult;
|
||||
}
|
||||
|
||||
public User? GetUserDetails(string userId, bool includeAgent = false)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(userId)) return null;
|
||||
|
|
|
|||
Loading…
Reference in a new issue