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:
@@ -3,7 +3,7 @@
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>0.0.182</Version>
|
||||
<Version>0.0.183</Version>
|
||||
<DebugType>None</DebugType>
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
|
||||
|
||||
@@ -154,6 +154,7 @@ message GetAllUserWalletByFilterResponseModel
|
||||
int64 user_id = 2;
|
||||
int64 balance = 3;
|
||||
int64 network_balance = 4;
|
||||
string user_name = 5;
|
||||
}
|
||||
|
||||
// ============= Customer-specific Messages =============
|
||||
|
||||
@@ -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