feat: add geography entities with countries, states and cities

This commit is contained in:
masoodafar-web
2025-12-18 00:43:55 +03:30
parent 26e1243cfe
commit ead0cf4235
40 changed files with 5386 additions and 7 deletions
@@ -0,0 +1,40 @@
using CMSMicroservice.Application.CityCQ.Queries.GetAllCitiesByFilter;
using Mapster;
using ProtoCity = CMSMicroservice.Protobuf.Protos.City;
using AppCity = CMSMicroservice.Application.CityCQ.Queries.GetAllCitiesByFilter;
namespace CMSMicroservice.WebApi.Common.Mappings;
public class CityProfile : IRegister
{
void IRegister.Register(TypeAdapterConfig config)
{
// Request: Proto → Application
config.NewConfig<ProtoCity.GetAllCitiesByFilterRequest, AppCity.GetAllCitiesByFilterQuery>()
.Map(dest => dest.PaginationState, src => src.PaginationState)
.Map(dest => dest.SortBy, src => src.SortBy)
.Map(dest => dest.Filter, src => src.Filter);
config.NewConfig<ProtoCity.GetAllCitiesByFilterFilter, AppCity.GetAllCitiesByFilterFilter>()
.Map(dest => dest.Id, src => src.Id)
.Map(dest => dest.Name, src => src.Name)
.Map(dest => dest.Native, src => src.Native)
.Map(dest => dest.StateId, src => src.StateId);
// Response: Application → Proto
config.NewConfig<AppCity.GetAllCitiesByFilterResponseDto, ProtoCity.GetAllCitiesByFilterResponse>()
.Map(dest => dest.MetaData, src => src.MetaData)
.Map(dest => dest.Models, src => src.Models);
config.NewConfig<AppCity.GetAllCitiesByFilterResponseModel, ProtoCity.GetAllCitiesByFilterResponseModel>()
.Map(dest => dest.Id, src => src.Id)
.Map(dest => dest.ExternalId, src => src.ExternalId)
.Map(dest => dest.Name, src => src.Name)
.Map(dest => dest.Native, src => src.Native)
.Map(dest => dest.Latitude, src => src.Latitude)
.Map(dest => dest.Longitude, src => src.Longitude)
.Map(dest => dest.StateId, src => src.StateId)
.Map(dest => dest.StateName, src => src.StateName)
.Map(dest => dest.StateNative, src => src.StateNative);
}
}
@@ -1,5 +1,6 @@
using CMSMicroservice.Application.ClubFeatureCQ.Commands.ToggleUserClubFeature;
using CMSMicroservice.Application.ClubFeatureCQ.Queries.GetUserClubFeatures;
using CMSMicroservice.Application.ClubMembershipCQ.Commands.AcceptClubMembershipContract;
using CMSMicroservice.Protobuf.Protos.ClubMembership;
using Google.Protobuf.WellKnownTypes;
using System;
@@ -43,5 +44,18 @@ public class ClubFeatureProfile : IRegister
.Map(dest => dest.Message, src => src.Message)
.Map(dest => dest.UserClubFeatureId, src => src.UserClubFeatureId.HasValue ? (long?)src.UserClubFeatureId.Value : null)
.Map(dest => dest.IsActive, src => src.IsActive.HasValue ? (bool?)src.IsActive.Value : null);
// AcceptClubMembershipContractRequest → AcceptClubMembershipContractCommand
config.NewConfig<AcceptClubMembershipContractRequest, AcceptClubMembershipContractCommand>()
.Map(dest => dest.UserId, src => src.UserId)
.Map(dest => dest.OtpCode, src => src.OtpCode)
.Map(dest => dest.SignGuid, src => src.SignGuid)
.Map(dest => dest.ContractHtml, src => src.ContractHtml);
// AcceptClubMembershipContractResponseDto → AcceptClubMembershipContractResponse
config.NewConfig<AcceptClubMembershipContractResponseDto, AcceptClubMembershipContractResponse>()
.Map(dest => dest.Success, src => src.Success)
.Map(dest => dest.Message, src => src.Message)
.Map(dest => dest.ContractId, src => src.ContractId);
}
}
@@ -0,0 +1,115 @@
using CMSMicroservice.Application.Common.Interfaces;
using CMSMicroservice.WebApi.Hubs;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging;
namespace CMSMicroservice.WebApi.Common.Services;
/// <summary>
/// Service for sending token-related notifications via SignalR
/// </summary>
public class TokenNotificationService : ITokenNotificationService
{
private readonly IHubContext<TokenNotificationHub> _hubContext;
private readonly ILogger<TokenNotificationService> _logger;
public TokenNotificationService(
IHubContext<TokenNotificationHub> hubContext,
ILogger<TokenNotificationService> logger)
{
_hubContext = hubContext;
_logger = logger;
}
/// <inheritdoc />
public async Task NotifyTokenRevokedAsync(long userId, string reason)
{
try
{
_logger.LogInformation("Notifying token revoked for user {UserId}. Reason: {Reason}", userId, reason);
await _hubContext.Clients.Group($"user_{userId}")
.SendAsync("TokenRevoked", new TokenRevokedNotification
{
UserId = userId,
Reason = reason,
Timestamp = DateTime.UtcNow
});
_logger.LogInformation("Token revoked notification sent for user {UserId}", userId);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to send token revoked notification for user {UserId}", userId);
}
}
/// <inheritdoc />
public async Task NotifyForceRefreshAsync(long userId)
{
try
{
_logger.LogInformation("Notifying force refresh for user {UserId}", userId);
await _hubContext.Clients.Group($"user_{userId}")
.SendAsync("ForceRefreshToken", new ForceRefreshNotification
{
UserId = userId,
Timestamp = DateTime.UtcNow
});
_logger.LogInformation("Force refresh notification sent for user {UserId}", userId);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to send force refresh notification for user {UserId}", userId);
}
}
/// <inheritdoc />
public async Task BroadcastMessageAsync(string message)
{
try
{
_logger.LogInformation("Broadcasting message to all clients: {Message}", message);
await _hubContext.Clients.All.SendAsync("BroadcastMessage", new BroadcastNotification
{
Message = message,
Timestamp = DateTime.UtcNow
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to broadcast message");
}
}
}
/// <summary>
/// Notification payload for token revoked event
/// </summary>
public class TokenRevokedNotification
{
public long UserId { get; set; }
public string Reason { get; set; } = string.Empty;
public DateTime Timestamp { get; set; }
}
/// <summary>
/// Notification payload for force refresh event
/// </summary>
public class ForceRefreshNotification
{
public long UserId { get; set; }
public DateTime Timestamp { get; set; }
}
/// <summary>
/// Notification payload for broadcast message
/// </summary>
public class BroadcastNotification
{
public string Message { get; set; } = string.Empty;
public DateTime Timestamp { get; set; }
}