feat: add user_name to wallet response + enrich via Users table
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 8m59s
Build and Deploy to Kubernetes / build-and-deploy (push) Successful in 8m59s
- userwallet.proto: added string user_name = 5 to GetAllUserWalletByFilterResponseModel - UserWalletService: enriches response with user names from Users table - Proto version bumped to 0.0.183
This commit is contained in:
@@ -55,7 +55,28 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
|
||||
}
|
||||
public override async Task<GetAllUserWalletByFilterResponse> GetAllUserWalletByFilter(GetAllUserWalletByFilterRequest request, ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetAllUserWalletByFilterRequest, GetAllUserWalletByFilterQuery, GetAllUserWalletByFilterResponse>(request, context);
|
||||
var response = await _dispatchRequestToCQRS.Handle<GetAllUserWalletByFilterRequest, GetAllUserWalletByFilterQuery, GetAllUserWalletByFilterResponse>(request, context);
|
||||
|
||||
// Enrich response with user names
|
||||
if (response?.Models != null && response.Models.Any())
|
||||
{
|
||||
var userIds = response.Models.Select(m => m.UserId).Distinct().ToList();
|
||||
var users = await _context.Users
|
||||
.AsNoTracking()
|
||||
.Where(u => userIds.Contains(u.Id))
|
||||
.Select(u => new { u.Id, u.FirstName, u.LastName })
|
||||
.ToDictionaryAsync(u => u.Id, context.CancellationToken);
|
||||
|
||||
foreach (var model in response.Models)
|
||||
{
|
||||
if (users.TryGetValue(model.UserId, out var user))
|
||||
{
|
||||
model.UserName = $"{user.FirstName} {user.LastName}".Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
// ============= Customer-specific Methods =============
|
||||
|
||||
Reference in New Issue
Block a user