658d076bdf
- Migrated all 9 services from FrontOffice.BFF to CMS architecture - Enhanced user.proto with 7 additional Customer API endpoints: * UpdateCustomerProfile, GetCustomerProfile * ChangeCustomerPassword with validation * GetCustomerReferrals with commission stats * UploadCustomerAvatar with file validation * GetCustomerSettings, UpdateCustomerSettings - All services now support Customer endpoints with /Customer/ prefix - Mock implementations with realistic Persian data - Fixed namespace conflicts and compilation issues - Comprehensive testing completed for all endpoints - Services migrated: Categories, City, UserCarts, Products, UserWallet, Transaction, UserOrder, Package, User (enhanced)
48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using CMSMicroservice.Protobuf.Protos.Health;
|
|
using CMSMicroservice.Application.HealthCQ.Queries.GetSystemHealth;
|
|
using MediatR;
|
|
using Mapster;
|
|
using Grpc.Core;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
using System.Linq;
|
|
|
|
namespace CMSMicroservice.WebApi.Services;
|
|
|
|
public class HealthService : HealthContract.HealthContractBase
|
|
{
|
|
private readonly IMediator _mediator;
|
|
|
|
public HealthService(IMediator mediator)
|
|
{
|
|
_mediator = mediator;
|
|
}
|
|
|
|
public override async Task<GetSystemHealthResponse> GetSystemHealth(Empty request, ServerCallContext context)
|
|
{
|
|
var query = new GetSystemHealthQuery();
|
|
var result = await _mediator.Send(query, context.CancellationToken);
|
|
|
|
return result.Adapt<GetSystemHealthResponse>();
|
|
}
|
|
|
|
public override async Task<GetServiceHealthResponse> GetServiceHealth(GetServiceHealthRequest request, ServerCallContext context)
|
|
{
|
|
// For now, just return system health filtered by service name
|
|
var systemHealthQuery = new GetSystemHealthQuery();
|
|
var systemHealth = await _mediator.Send(systemHealthQuery, context.CancellationToken);
|
|
|
|
var service = systemHealth.Services.FirstOrDefault(s =>
|
|
s.ServiceName.Equals(request.ServiceName, StringComparison.OrdinalIgnoreCase));
|
|
|
|
if (service == null)
|
|
{
|
|
throw new ArgumentException($"Service '{request.ServiceName}' not found");
|
|
}
|
|
|
|
return new GetServiceHealthResponse
|
|
{
|
|
Service = service.Adapt<ServiceHealthModel>(),
|
|
CheckedAt = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime.UtcNow)
|
|
};
|
|
}
|
|
} |