From f7da86ec024a0528bdf56db468bdae9ee2f5800b Mon Sep 17 00:00:00 2001 From: MeysamMoghaddam <65253484+MeysamMoghaddam@users.noreply.github.com> Date: Mon, 13 Oct 2025 08:19:47 +0330 Subject: [PATCH] Generator Changes at 10/13/2025 8:08:52 AM --- .../Interfaces/IApplicationDbContext.cs | 2 +- .../SetAddressAsDefaultCommand.cs | 7 + .../SetAddressAsDefaultCommandHandler.cs | 29 ++ .../SetAddressAsDefaultCommandValidator.cs | 16 + .../SetAddressAsDefaultEventHandler.cs | 21 + .../CreateNewUser/CreateNewUserCommand.cs | 8 + .../CreateNewUserCommandValidator.cs | 6 + .../Commands/UpdateUser/UpdateUserCommand.cs | 8 + .../UpdateUser/UpdateUserCommandValidator.cs | 6 + .../GetAllUserByFilterQuery.cs | 8 + .../GetAllUserByFilterQueryHandler.cs | 4 + .../GetAllUserByFilterResponseDto.cs | 8 + .../Queries/GetUser/GetUserResponseDto.cs | 8 + .../CreateNewUserOrderCommand.cs | 2 + .../CreateNewUserOrderCommandValidator.cs | 2 + .../UpdateUserOrder/UpdateUserOrderCommand.cs | 2 + .../UpdateUserOrderCommandValidator.cs | 2 + .../GetAllUserOrderByFilterQuery.cs | 2 + .../GetAllUserOrderByFilterQueryHandler.cs | 1 + .../GetAllUserOrderByFilterResponseDto.cs | 2 + .../GetUserOrder/GetUserOrderResponseDto.cs | 2 + src/CMSMicroservice.Domain/Entities/User.cs | 12 +- .../Entities/UserAddress.cs | 2 + .../Entities/UserOrder.cs | 4 + .../SetAddressAsDefaultEvent.cs | 10 + .../Persistence/ApplicationDbContext.cs | 2 +- .../Configurations/UserConfiguration.cs | 4 + .../Configurations/UserOrderConfiguration.cs | 6 + .../Migrations/20251013044349_u04.Designer.cs | 472 ++++++++++++++++++ .../Migrations/20251013044349_u04.cs | 109 ++++ .../ApplicationDbContextModelSnapshot.cs | 30 ++ .../CMSMicroservice.Protobuf.csproj | 2 +- .../Protos/user.proto | 20 + .../Protos/useraddress.proto | 10 + .../Protos/userorder.proto | 5 + .../User/CreateNewUserRequestValidator.cs | 6 + .../User/UpdateUserRequestValidator.cs | 6 + .../SetAddressAsDefaultRequestValidator.cs | 19 + .../CreateNewUserOrderRequestValidator.cs | 2 + .../UpdateUserOrderRequestValidator.cs | 2 + .../Services/UserAddressService.cs | 5 + 41 files changed, 869 insertions(+), 5 deletions(-) create mode 100644 src/CMSMicroservice.Application/UserAddressCQ/Commands/SetAddressAsDefault/SetAddressAsDefaultCommand.cs create mode 100644 src/CMSMicroservice.Application/UserAddressCQ/Commands/SetAddressAsDefault/SetAddressAsDefaultCommandHandler.cs create mode 100644 src/CMSMicroservice.Application/UserAddressCQ/Commands/SetAddressAsDefault/SetAddressAsDefaultCommandValidator.cs create mode 100644 src/CMSMicroservice.Application/UserAddressCQ/EventHandlers/SetAddressAsDefaultEventHandlers/SetAddressAsDefaultEventHandler.cs create mode 100644 src/CMSMicroservice.Domain/Events/UserAddressEvents/SetAddressAsDefaultEvent.cs create mode 100644 src/CMSMicroservice.Infrastructure/Persistence/Migrations/20251013044349_u04.Designer.cs create mode 100644 src/CMSMicroservice.Infrastructure/Persistence/Migrations/20251013044349_u04.cs create mode 100644 src/CMSMicroservice.Protobuf/Validator/UserAddress/SetAddressAsDefaultRequestValidator.cs diff --git a/src/CMSMicroservice.Application/Common/Interfaces/IApplicationDbContext.cs b/src/CMSMicroservice.Application/Common/Interfaces/IApplicationDbContext.cs index 8e7d8b5..34dd9e4 100644 --- a/src/CMSMicroservice.Application/Common/Interfaces/IApplicationDbContext.cs +++ b/src/CMSMicroservice.Application/Common/Interfaces/IApplicationDbContext.cs @@ -4,10 +4,10 @@ public interface IApplicationDbContext { DbSet UserAddresss { get; } DbSet Packages { get; } - DbSet UserOrders { get; } DbSet Roles { get; } DbSet UserRoles { get; } DbSet OtpTokens { get; } + DbSet UserOrders { get; } DbSet Users { get; } Task SaveChangesAsync(CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/src/CMSMicroservice.Application/UserAddressCQ/Commands/SetAddressAsDefault/SetAddressAsDefaultCommand.cs b/src/CMSMicroservice.Application/UserAddressCQ/Commands/SetAddressAsDefault/SetAddressAsDefaultCommand.cs new file mode 100644 index 0000000..d98b2b1 --- /dev/null +++ b/src/CMSMicroservice.Application/UserAddressCQ/Commands/SetAddressAsDefault/SetAddressAsDefaultCommand.cs @@ -0,0 +1,7 @@ +namespace CMSMicroservice.Application.UserAddressCQ.Commands.SetAddressAsDefault; +public record SetAddressAsDefaultCommand : IRequest +{ + //شناسه + public long Id { get; init; } + +} \ No newline at end of file diff --git a/src/CMSMicroservice.Application/UserAddressCQ/Commands/SetAddressAsDefault/SetAddressAsDefaultCommandHandler.cs b/src/CMSMicroservice.Application/UserAddressCQ/Commands/SetAddressAsDefault/SetAddressAsDefaultCommandHandler.cs new file mode 100644 index 0000000..33335ae --- /dev/null +++ b/src/CMSMicroservice.Application/UserAddressCQ/Commands/SetAddressAsDefault/SetAddressAsDefaultCommandHandler.cs @@ -0,0 +1,29 @@ +using CMSMicroservice.Domain.Events; +namespace CMSMicroservice.Application.UserAddressCQ.Commands.SetAddressAsDefault; +public class SetAddressAsDefaultCommandHandler : IRequestHandler +{ + private readonly IApplicationDbContext _context; + + public SetAddressAsDefaultCommandHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task Handle(SetAddressAsDefaultCommand request, CancellationToken cancellationToken) + { + var entity = await _context.UserAddresss + .FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken) ?? throw new NotFoundException(nameof(UserAddress), request.Id); + + var entities = await _context.UserAddresss + .Where(x => x.UserId == entity.UserId) + .ToListAsync(cancellationToken); + entities.ForEach(x => x.IsDefault = false); + await _context.SaveChangesAsync(cancellationToken); + + entity.IsDefault = true; + _context.UserAddresss.Update(entity); + entity.AddDomainEvent(new SetAddressAsDefaultEvent(entity)); + await _context.SaveChangesAsync(cancellationToken); + return Unit.Value; + } +} diff --git a/src/CMSMicroservice.Application/UserAddressCQ/Commands/SetAddressAsDefault/SetAddressAsDefaultCommandValidator.cs b/src/CMSMicroservice.Application/UserAddressCQ/Commands/SetAddressAsDefault/SetAddressAsDefaultCommandValidator.cs new file mode 100644 index 0000000..ccd4752 --- /dev/null +++ b/src/CMSMicroservice.Application/UserAddressCQ/Commands/SetAddressAsDefault/SetAddressAsDefaultCommandValidator.cs @@ -0,0 +1,16 @@ +namespace CMSMicroservice.Application.UserAddressCQ.Commands.SetAddressAsDefault; +public class SetAddressAsDefaultCommandValidator : AbstractValidator +{ + public SetAddressAsDefaultCommandValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((SetAddressAsDefaultCommand)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Application/UserAddressCQ/EventHandlers/SetAddressAsDefaultEventHandlers/SetAddressAsDefaultEventHandler.cs b/src/CMSMicroservice.Application/UserAddressCQ/EventHandlers/SetAddressAsDefaultEventHandlers/SetAddressAsDefaultEventHandler.cs new file mode 100644 index 0000000..0e609a4 --- /dev/null +++ b/src/CMSMicroservice.Application/UserAddressCQ/EventHandlers/SetAddressAsDefaultEventHandlers/SetAddressAsDefaultEventHandler.cs @@ -0,0 +1,21 @@ +using CMSMicroservice.Domain.Events; +using Microsoft.Extensions.Logging; + +namespace CMSMicroservice.Application.UserAddressCQ.EventHandlers; + +public class SetAddressAsDefaultEventHandler : INotificationHandler +{ + private readonly ILogger _logger; + + public SetAddressAsDefaultEventHandler(ILogger logger) + { + _logger = logger; + } + + public Task Handle(SetAddressAsDefaultEvent notification, CancellationToken cancellationToken) + { + _logger.LogInformation("Domain Event: {DomainEvent}", notification.GetType().Name); + + return Task.CompletedTask; + } +} diff --git a/src/CMSMicroservice.Application/UserCQ/Commands/CreateNewUser/CreateNewUserCommand.cs b/src/CMSMicroservice.Application/UserCQ/Commands/CreateNewUser/CreateNewUserCommand.cs index ec02065..822ef76 100644 --- a/src/CMSMicroservice.Application/UserCQ/Commands/CreateNewUser/CreateNewUserCommand.cs +++ b/src/CMSMicroservice.Application/UserCQ/Commands/CreateNewUser/CreateNewUserCommand.cs @@ -13,5 +13,13 @@ public record CreateNewUserCommand : IRequest public string? AvatarPath { get; init; } //شناسه والد public long? ParentId { get; init; } + //اعلان ایمیل + public bool EmailNotifications { get; init; } + //اعلان پیامک + public bool SmsNotifications { get; init; } + //اعلان پوش + public bool PushNotifications { get; init; } + //تاریخ تولد + public DateTime? BirthDate { get; init; } } \ No newline at end of file diff --git a/src/CMSMicroservice.Application/UserCQ/Commands/CreateNewUser/CreateNewUserCommandValidator.cs b/src/CMSMicroservice.Application/UserCQ/Commands/CreateNewUser/CreateNewUserCommandValidator.cs index 1e42bfd..592769e 100644 --- a/src/CMSMicroservice.Application/UserCQ/Commands/CreateNewUser/CreateNewUserCommandValidator.cs +++ b/src/CMSMicroservice.Application/UserCQ/Commands/CreateNewUser/CreateNewUserCommandValidator.cs @@ -5,6 +5,12 @@ public class CreateNewUserCommandValidator : AbstractValidator model.Mobile) .NotEmpty(); + RuleFor(model => model.EmailNotifications) + .NotNull(); + RuleFor(model => model.SmsNotifications) + .NotNull(); + RuleFor(model => model.PushNotifications) + .NotNull(); } public Func>> ValidateValue => async (model, propertyName) => { diff --git a/src/CMSMicroservice.Application/UserCQ/Commands/UpdateUser/UpdateUserCommand.cs b/src/CMSMicroservice.Application/UserCQ/Commands/UpdateUser/UpdateUserCommand.cs index f001c59..14f30e9 100644 --- a/src/CMSMicroservice.Application/UserCQ/Commands/UpdateUser/UpdateUserCommand.cs +++ b/src/CMSMicroservice.Application/UserCQ/Commands/UpdateUser/UpdateUserCommand.cs @@ -15,5 +15,13 @@ public record UpdateUserCommand : IRequest public bool IsRulesAccepted { get; init; } //تاریخ پذیرش قوانین public DateTime? RulesAcceptedAt { get; init; } + //اعلان ایمیل + public bool EmailNotifications { get; init; } + //اعلان پیامک + public bool SmsNotifications { get; init; } + //اعلان پوش + public bool PushNotifications { get; init; } + //تاریخ تولد + public DateTime? BirthDate { get; init; } } \ No newline at end of file diff --git a/src/CMSMicroservice.Application/UserCQ/Commands/UpdateUser/UpdateUserCommandValidator.cs b/src/CMSMicroservice.Application/UserCQ/Commands/UpdateUser/UpdateUserCommandValidator.cs index 23773ae..84bff69 100644 --- a/src/CMSMicroservice.Application/UserCQ/Commands/UpdateUser/UpdateUserCommandValidator.cs +++ b/src/CMSMicroservice.Application/UserCQ/Commands/UpdateUser/UpdateUserCommandValidator.cs @@ -7,6 +7,12 @@ public class UpdateUserCommandValidator : AbstractValidator .NotNull(); RuleFor(model => model.IsRulesAccepted) .NotNull(); + RuleFor(model => model.EmailNotifications) + .NotNull(); + RuleFor(model => model.SmsNotifications) + .NotNull(); + RuleFor(model => model.PushNotifications) + .NotNull(); } public Func>> ValidateValue => async (model, propertyName) => { diff --git a/src/CMSMicroservice.Application/UserCQ/Queries/GetAllUserByFilter/GetAllUserByFilterQuery.cs b/src/CMSMicroservice.Application/UserCQ/Queries/GetAllUserByFilter/GetAllUserByFilterQuery.cs index 0252115..af569c5 100644 --- a/src/CMSMicroservice.Application/UserCQ/Queries/GetAllUserByFilter/GetAllUserByFilterQuery.cs +++ b/src/CMSMicroservice.Application/UserCQ/Queries/GetAllUserByFilter/GetAllUserByFilterQuery.cs @@ -30,4 +30,12 @@ public record GetAllUserByFilterQuery : IRequest public bool? IsMobileVerified { get; set; } //تاریخ فعال سازی موبایل public DateTime? MobileVerifiedAt { get; set; } + //اعلان ایمیل + public bool? EmailNotifications { get; set; } + //اعلان پیامک + public bool? SmsNotifications { get; set; } + //اعلان پوش + public bool? PushNotifications { get; set; } + //تاریخ تولد + public DateTime? BirthDate { get; set; } } diff --git a/src/CMSMicroservice.Application/UserCQ/Queries/GetAllUserByFilter/GetAllUserByFilterQueryHandler.cs b/src/CMSMicroservice.Application/UserCQ/Queries/GetAllUserByFilter/GetAllUserByFilterQueryHandler.cs index cfc88ea..883805f 100644 --- a/src/CMSMicroservice.Application/UserCQ/Queries/GetAllUserByFilter/GetAllUserByFilterQueryHandler.cs +++ b/src/CMSMicroservice.Application/UserCQ/Queries/GetAllUserByFilter/GetAllUserByFilterQueryHandler.cs @@ -26,6 +26,10 @@ public class GetAllUserByFilterQueryHandler : IRequestHandler request.Filter.ReferralCode == null || x.ReferralCode == request.Filter.ReferralCode) .Where(x => request.Filter.IsMobileVerified == null || x.IsMobileVerified == request.Filter.IsMobileVerified) .Where(x => request.Filter.ParentId == null || x.ParentId == request.Filter.ParentId) + .Where(x => request.Filter.SmsNotifications == null || x.SmsNotifications == request.Filter.SmsNotifications) + .Where(x => request.Filter.EmailNotifications == null || x.EmailNotifications == request.Filter.EmailNotifications) + .Where(x => request.Filter.PushNotifications == null || x.PushNotifications == request.Filter.PushNotifications) + .Where(x => request.Filter.BirthDate == null || x.BirthDate == request.Filter.BirthDate) ; } return new GetAllUserByFilterResponseDto diff --git a/src/CMSMicroservice.Application/UserCQ/Queries/GetAllUserByFilter/GetAllUserByFilterResponseDto.cs b/src/CMSMicroservice.Application/UserCQ/Queries/GetAllUserByFilter/GetAllUserByFilterResponseDto.cs index 36def23..2e34e2f 100644 --- a/src/CMSMicroservice.Application/UserCQ/Queries/GetAllUserByFilter/GetAllUserByFilterResponseDto.cs +++ b/src/CMSMicroservice.Application/UserCQ/Queries/GetAllUserByFilter/GetAllUserByFilterResponseDto.cs @@ -28,4 +28,12 @@ public class GetAllUserByFilterResponseDto public bool IsMobileVerified { get; set; } //تاریخ فعال سازی موبایل public DateTime? MobileVerifiedAt { get; set; } + //اعلان ایمیل + public bool EmailNotifications { get; set; } + //اعلان پیامک + public bool SmsNotifications { get; set; } + //اعلان پوش + public bool PushNotifications { get; set; } + //تاریخ تولد + public DateTime? BirthDate { get; set; } } diff --git a/src/CMSMicroservice.Application/UserCQ/Queries/GetUser/GetUserResponseDto.cs b/src/CMSMicroservice.Application/UserCQ/Queries/GetUser/GetUserResponseDto.cs index 8fc26f8..cc14bdd 100644 --- a/src/CMSMicroservice.Application/UserCQ/Queries/GetUser/GetUserResponseDto.cs +++ b/src/CMSMicroservice.Application/UserCQ/Queries/GetUser/GetUserResponseDto.cs @@ -21,5 +21,13 @@ public class GetUserResponseDto public bool IsMobileVerified { get; set; } //تاریخ فعال سازی موبایل public DateTime? MobileVerifiedAt { get; set; } + //اعلان ایمیل + public bool EmailNotifications { get; set; } + //اعلان پیامک + public bool SmsNotifications { get; set; } + //اعلان پوش + public bool PushNotifications { get; set; } + //تاریخ تولد + public DateTime? BirthDate { get; set; } } \ No newline at end of file diff --git a/src/CMSMicroservice.Application/UserOrderCQ/Commands/CreateNewUserOrder/CreateNewUserOrderCommand.cs b/src/CMSMicroservice.Application/UserOrderCQ/Commands/CreateNewUserOrder/CreateNewUserOrderCommand.cs index 7d96144..4dd0aa9 100644 --- a/src/CMSMicroservice.Application/UserOrderCQ/Commands/CreateNewUserOrder/CreateNewUserOrderCommand.cs +++ b/src/CMSMicroservice.Application/UserOrderCQ/Commands/CreateNewUserOrder/CreateNewUserOrderCommand.cs @@ -13,5 +13,7 @@ public record CreateNewUserOrderCommand : IRequest model.UserId) .NotNull(); + RuleFor(model => model.UserAddressId) + .NotNull(); } public Func>> ValidateValue => async (model, propertyName) => { diff --git a/src/CMSMicroservice.Application/UserOrderCQ/Commands/UpdateUserOrder/UpdateUserOrderCommand.cs b/src/CMSMicroservice.Application/UserOrderCQ/Commands/UpdateUserOrder/UpdateUserOrderCommand.cs index c73120d..7fbe596 100644 --- a/src/CMSMicroservice.Application/UserOrderCQ/Commands/UpdateUserOrder/UpdateUserOrderCommand.cs +++ b/src/CMSMicroservice.Application/UserOrderCQ/Commands/UpdateUserOrder/UpdateUserOrderCommand.cs @@ -15,5 +15,7 @@ public record UpdateUserOrderCommand : IRequest public DateTime? PaymentDate { get; init; } //شناسه کاربر public long UserId { get; init; } + //شناسه آدرس کاربر + public long UserAddressId { get; init; } } \ No newline at end of file diff --git a/src/CMSMicroservice.Application/UserOrderCQ/Commands/UpdateUserOrder/UpdateUserOrderCommandValidator.cs b/src/CMSMicroservice.Application/UserOrderCQ/Commands/UpdateUserOrder/UpdateUserOrderCommandValidator.cs index 1ae70e7..74440a1 100644 --- a/src/CMSMicroservice.Application/UserOrderCQ/Commands/UpdateUserOrder/UpdateUserOrderCommandValidator.cs +++ b/src/CMSMicroservice.Application/UserOrderCQ/Commands/UpdateUserOrder/UpdateUserOrderCommandValidator.cs @@ -13,6 +13,8 @@ public class UpdateUserOrderCommandValidator : AbstractValidator model.UserId) .NotNull(); + RuleFor(model => model.UserAddressId) + .NotNull(); } public Func>> ValidateValue => async (model, propertyName) => { diff --git a/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetAllUserOrderByFilter/GetAllUserOrderByFilterQuery.cs b/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetAllUserOrderByFilter/GetAllUserOrderByFilterQuery.cs index f3372b0..8fdee62 100644 --- a/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetAllUserOrderByFilter/GetAllUserOrderByFilterQuery.cs +++ b/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetAllUserOrderByFilter/GetAllUserOrderByFilterQuery.cs @@ -24,4 +24,6 @@ public record GetAllUserOrderByFilterQuery : IRequest request.Filter.PaymentStatus == null || x.PaymentStatus == request.Filter.PaymentStatus) .Where(x => request.Filter.PaymentDate == null || x.PaymentDate == request.Filter.PaymentDate) .Where(x => request.Filter.UserId == null || x.UserId == request.Filter.UserId) + .Where(x => request.Filter.UserAddressId == null || x.UserAddressId == request.Filter.UserAddressId) ; } return new GetAllUserOrderByFilterResponseDto diff --git a/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetAllUserOrderByFilter/GetAllUserOrderByFilterResponseDto.cs b/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetAllUserOrderByFilter/GetAllUserOrderByFilterResponseDto.cs index fa7f9f4..0d68dff 100644 --- a/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetAllUserOrderByFilter/GetAllUserOrderByFilterResponseDto.cs +++ b/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetAllUserOrderByFilter/GetAllUserOrderByFilterResponseDto.cs @@ -22,4 +22,6 @@ public class GetAllUserOrderByFilterResponseDto public DateTime? PaymentDate { get; set; } //شناسه کاربر public long UserId { get; set; } + //شناسه آدرس کاربر + public long UserAddressId { get; set; } } diff --git a/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetUserOrder/GetUserOrderResponseDto.cs b/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetUserOrder/GetUserOrderResponseDto.cs index ac05f8e..439b6fc 100644 --- a/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetUserOrder/GetUserOrderResponseDto.cs +++ b/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetUserOrder/GetUserOrderResponseDto.cs @@ -15,5 +15,7 @@ public class GetUserOrderResponseDto public DateTime? PaymentDate { get; set; } //شناسه کاربر public long UserId { get; set; } + //شناسه آدرس کاربر + public long UserAddressId { get; set; } } \ No newline at end of file diff --git a/src/CMSMicroservice.Domain/Entities/User.cs b/src/CMSMicroservice.Domain/Entities/User.cs index 1e98e03..0176954 100644 --- a/src/CMSMicroservice.Domain/Entities/User.cs +++ b/src/CMSMicroservice.Domain/Entities/User.cs @@ -26,12 +26,20 @@ public class User : BaseAuditableEntity public bool IsRulesAccepted { get; set; } //تاریخ پذیرش قوانین public DateTime? RulesAcceptedAt { get; set; } + //اعلان ایمیل + public bool EmailNotifications { get; set; } + //اعلان پیامک + public bool SmsNotifications { get; set; } + //اعلان پوش + public bool PushNotifications { get; set; } + //تاریخ تولد + public DateTime? BirthDate { get; set; } //UserAddress Collection Navigation Reference public virtual ICollection UserAddresss { get; set; } - //UserOrder Collection Navigation Reference - public virtual ICollection UserOrders { get; set; } //UserRole Collection Navigation Reference public virtual ICollection UserRoles { get; set; } + //UserOrder Collection Navigation Reference + public virtual ICollection UserOrders { get; set; } //User Collection Navigation Reference public virtual ICollection Users { get; set; } } \ No newline at end of file diff --git a/src/CMSMicroservice.Domain/Entities/UserAddress.cs b/src/CMSMicroservice.Domain/Entities/UserAddress.cs index 2929e33..723f744 100644 --- a/src/CMSMicroservice.Domain/Entities/UserAddress.cs +++ b/src/CMSMicroservice.Domain/Entities/UserAddress.cs @@ -16,4 +16,6 @@ public class UserAddress : BaseAuditableEntity public bool IsDefault { get; set; } //شناسه شهر public long CityId { get; set; } + //UserOrder Collection Navigation Reference + public virtual ICollection UserOrders { get; set; } } \ No newline at end of file diff --git a/src/CMSMicroservice.Domain/Entities/UserOrder.cs b/src/CMSMicroservice.Domain/Entities/UserOrder.cs index d2d658b..8b73599 100644 --- a/src/CMSMicroservice.Domain/Entities/UserOrder.cs +++ b/src/CMSMicroservice.Domain/Entities/UserOrder.cs @@ -18,4 +18,8 @@ public class UserOrder : BaseAuditableEntity public long UserId { get; set; } //User Navigation Property public virtual User User { get; set; } + //شناسه آدرس کاربر + public long UserAddressId { get; set; } + //UserAddress Navigation Property + public virtual UserAddress UserAddress { get; set; } } \ No newline at end of file diff --git a/src/CMSMicroservice.Domain/Events/UserAddressEvents/SetAddressAsDefaultEvent.cs b/src/CMSMicroservice.Domain/Events/UserAddressEvents/SetAddressAsDefaultEvent.cs new file mode 100644 index 0000000..3d3ee31 --- /dev/null +++ b/src/CMSMicroservice.Domain/Events/UserAddressEvents/SetAddressAsDefaultEvent.cs @@ -0,0 +1,10 @@ +namespace CMSMicroservice.Domain.Events; +public class SetAddressAsDefaultEvent : BaseEvent +{ + public SetAddressAsDefaultEvent(UserAddress item) + { + Item = item; + } + + public UserAddress Item { get; } +} diff --git a/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContext.cs b/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContext.cs index 07d0c2f..8ea6548 100644 --- a/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContext.cs +++ b/src/CMSMicroservice.Infrastructure/Persistence/ApplicationDbContext.cs @@ -41,10 +41,10 @@ public class ApplicationDbContext : DbContext, IApplicationDbContext } public DbSet UserAddresss => Set(); public DbSet Packages => Set(); - public DbSet UserOrders => Set(); public DbSet Roles => Set(); public DbSet UserRoles => Set(); public DbSet OtpTokens => Set(); + public DbSet UserOrders => Set(); public DbSet Users => Set(); } \ No newline at end of file diff --git a/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserConfiguration.cs b/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserConfiguration.cs index 19b4c52..5eac832 100644 --- a/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserConfiguration.cs +++ b/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserConfiguration.cs @@ -27,5 +27,9 @@ public class UserConfiguration : IEntityTypeConfiguration builder.Property(entity => entity.MobileVerifiedAt).IsRequired(false); builder.Property(entity => entity.IsRulesAccepted).IsRequired(true); builder.Property(entity => entity.RulesAcceptedAt).IsRequired(false); + builder.Property(entity => entity.EmailNotifications).IsRequired(true); + builder.Property(entity => entity.SmsNotifications).IsRequired(true); + builder.Property(entity => entity.PushNotifications).IsRequired(true); + builder.Property(entity => entity.BirthDate).IsRequired(false); } } \ No newline at end of file diff --git a/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserOrderConfiguration.cs b/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserOrderConfiguration.cs index 656ba1f..2545e2e 100644 --- a/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserOrderConfiguration.cs +++ b/src/CMSMicroservice.Infrastructure/Persistence/Configurations/UserOrderConfiguration.cs @@ -26,5 +26,11 @@ public class UserOrderConfiguration : IEntityTypeConfiguration .WithMany(entity => entity.UserOrders) .HasForeignKey(entity => entity.UserId) .IsRequired(true); + builder + .HasOne(entity => entity.UserAddress) + .WithMany(entity => entity.UserOrders) + .HasForeignKey(entity => entity.UserAddressId) + .OnDelete(deleteBehavior: DeleteBehavior.Restrict) + .IsRequired(true); } } \ No newline at end of file diff --git a/src/CMSMicroservice.Infrastructure/Persistence/Migrations/20251013044349_u04.Designer.cs b/src/CMSMicroservice.Infrastructure/Persistence/Migrations/20251013044349_u04.Designer.cs new file mode 100644 index 0000000..b857f9b --- /dev/null +++ b/src/CMSMicroservice.Infrastructure/Persistence/Migrations/20251013044349_u04.Designer.cs @@ -0,0 +1,472 @@ +// +using System; +using CMSMicroservice.Infrastructure.Persistence; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace CMSMicroservice.Infrastructure.Persistence.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20251013044349_u04")] + partial class u04 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("CMS") + .HasAnnotation("ProductVersion", "7.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.OtpToken", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Attempts") + .HasColumnType("int"); + + b.Property("CodeHash") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("IsUsed") + .HasColumnType("bit"); + + b.Property("LastModified") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("Mobile") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Purpose") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("OtpTokens", "CMS"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ImagePath") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastModified") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Packages", "CMS"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastModified") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Roles", "CMS"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AvatarPath") + .HasColumnType("nvarchar(max)"); + + b.Property("BirthDate") + .HasColumnType("datetime2"); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("EmailNotifications") + .HasColumnType("bit"); + + b.Property("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("IsMobileVerified") + .HasColumnType("bit"); + + b.Property("IsRulesAccepted") + .HasColumnType("bit"); + + b.Property("LastModified") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + b.Property("Mobile") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MobileVerifiedAt") + .HasColumnType("datetime2"); + + b.Property("NationalCode") + .HasColumnType("nvarchar(max)"); + + b.Property("ParentId") + .HasColumnType("bigint"); + + b.Property("PushNotifications") + .HasColumnType("bit"); + + b.Property("ReferralCode") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("RulesAcceptedAt") + .HasColumnType("datetime2"); + + b.Property("SmsNotifications") + .HasColumnType("bit"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("Users", "CMS"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserAddress", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CityId") + .HasColumnType("bigint"); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("IsDefault") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastModified") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("PostalCode") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("UserAddresss", "CMS"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastModified") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("PackageId") + .HasColumnType("bigint"); + + b.Property("PaymentDate") + .HasColumnType("datetime2"); + + b.Property("PaymentStatus") + .HasColumnType("bit"); + + b.Property("Price") + .HasColumnType("bigint"); + + b.Property("TransactionId") + .HasColumnType("bigint"); + + b.Property("UserAddressId") + .HasColumnType("bigint"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("PackageId"); + + b.HasIndex("UserAddressId"); + + b.HasIndex("UserId"); + + b.ToTable("UserOrders", "CMS"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Created") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastModified") + .HasColumnType("datetime2"); + + b.Property("LastModifiedBy") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .HasColumnType("bigint"); + + b.Property("UserId") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.HasIndex("UserId"); + + b.ToTable("UserRoles", "CMS"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.User", b => + { + b.HasOne("CMSMicroservice.Domain.Entities.User", "Parent") + .WithMany("Users") + .HasForeignKey("ParentId"); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserAddress", b => + { + b.HasOne("CMSMicroservice.Domain.Entities.User", "User") + .WithMany("UserAddresss") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserOrder", b => + { + b.HasOne("CMSMicroservice.Domain.Entities.Package", "Package") + .WithMany("UserOrders") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CMSMicroservice.Domain.Entities.UserAddress", "UserAddress") + .WithMany("UserOrders") + .HasForeignKey("UserAddressId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("CMSMicroservice.Domain.Entities.User", "User") + .WithMany("UserOrders") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Package"); + + b.Navigation("User"); + + b.Navigation("UserAddress"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserRole", b => + { + b.HasOne("CMSMicroservice.Domain.Entities.Role", "Role") + .WithMany("UserRoles") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CMSMicroservice.Domain.Entities.User", "User") + .WithMany("UserRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.Package", b => + { + b.Navigation("UserOrders"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.Role", b => + { + b.Navigation("UserRoles"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.User", b => + { + b.Navigation("UserAddresss"); + + b.Navigation("UserOrders"); + + b.Navigation("UserRoles"); + + b.Navigation("Users"); + }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserAddress", b => + { + b.Navigation("UserOrders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/CMSMicroservice.Infrastructure/Persistence/Migrations/20251013044349_u04.cs b/src/CMSMicroservice.Infrastructure/Persistence/Migrations/20251013044349_u04.cs new file mode 100644 index 0000000..ea38c25 --- /dev/null +++ b/src/CMSMicroservice.Infrastructure/Persistence/Migrations/20251013044349_u04.cs @@ -0,0 +1,109 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CMSMicroservice.Infrastructure.Persistence.Migrations +{ + /// + public partial class u04 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "BirthDate", + schema: "CMS", + table: "Users", + type: "datetime2", + nullable: true); + + migrationBuilder.AddColumn( + name: "EmailNotifications", + schema: "CMS", + table: "Users", + type: "bit", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "PushNotifications", + schema: "CMS", + table: "Users", + type: "bit", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "SmsNotifications", + schema: "CMS", + table: "Users", + type: "bit", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "UserAddressId", + schema: "CMS", + table: "UserOrders", + type: "bigint", + nullable: false, + defaultValue: 0L); + + migrationBuilder.CreateIndex( + name: "IX_UserOrders_UserAddressId", + schema: "CMS", + table: "UserOrders", + column: "UserAddressId"); + + migrationBuilder.AddForeignKey( + name: "FK_UserOrders_UserAddresss_UserAddressId", + schema: "CMS", + table: "UserOrders", + column: "UserAddressId", + principalSchema: "CMS", + principalTable: "UserAddresss", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_UserOrders_UserAddresss_UserAddressId", + schema: "CMS", + table: "UserOrders"); + + migrationBuilder.DropIndex( + name: "IX_UserOrders_UserAddressId", + schema: "CMS", + table: "UserOrders"); + + migrationBuilder.DropColumn( + name: "BirthDate", + schema: "CMS", + table: "Users"); + + migrationBuilder.DropColumn( + name: "EmailNotifications", + schema: "CMS", + table: "Users"); + + migrationBuilder.DropColumn( + name: "PushNotifications", + schema: "CMS", + table: "Users"); + + migrationBuilder.DropColumn( + name: "SmsNotifications", + schema: "CMS", + table: "Users"); + + migrationBuilder.DropColumn( + name: "UserAddressId", + schema: "CMS", + table: "UserOrders"); + } + } +} diff --git a/src/CMSMicroservice.Infrastructure/Persistence/Migrations/ApplicationDbContextModelSnapshot.cs b/src/CMSMicroservice.Infrastructure/Persistence/Migrations/ApplicationDbContextModelSnapshot.cs index a1428f6..a3d25cf 100644 --- a/src/CMSMicroservice.Infrastructure/Persistence/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/CMSMicroservice.Infrastructure/Persistence/Migrations/ApplicationDbContextModelSnapshot.cs @@ -162,12 +162,18 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations b.Property("AvatarPath") .HasColumnType("nvarchar(max)"); + b.Property("BirthDate") + .HasColumnType("datetime2"); + b.Property("Created") .HasColumnType("datetime2"); b.Property("CreatedBy") .HasColumnType("nvarchar(max)"); + b.Property("EmailNotifications") + .HasColumnType("bit"); + b.Property("FirstName") .HasColumnType("nvarchar(max)"); @@ -202,6 +208,9 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations b.Property("ParentId") .HasColumnType("bigint"); + b.Property("PushNotifications") + .HasColumnType("bit"); + b.Property("ReferralCode") .IsRequired() .HasColumnType("nvarchar(max)"); @@ -209,6 +218,9 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations b.Property("RulesAcceptedAt") .HasColumnType("datetime2"); + b.Property("SmsNotifications") + .HasColumnType("bit"); + b.HasKey("Id"); b.HasIndex("ParentId"); @@ -305,6 +317,9 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations b.Property("TransactionId") .HasColumnType("bigint"); + b.Property("UserAddressId") + .HasColumnType("bigint"); + b.Property("UserId") .HasColumnType("bigint"); @@ -312,6 +327,8 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations b.HasIndex("PackageId"); + b.HasIndex("UserAddressId"); + b.HasIndex("UserId"); b.ToTable("UserOrders", "CMS"); @@ -383,6 +400,12 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("CMSMicroservice.Domain.Entities.UserAddress", "UserAddress") + .WithMany("UserOrders") + .HasForeignKey("UserAddressId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + b.HasOne("CMSMicroservice.Domain.Entities.User", "User") .WithMany("UserOrders") .HasForeignKey("UserId") @@ -392,6 +415,8 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations b.Navigation("Package"); b.Navigation("User"); + + b.Navigation("UserAddress"); }); modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserRole", b => @@ -433,6 +458,11 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations b.Navigation("Users"); }); + + modelBuilder.Entity("CMSMicroservice.Domain.Entities.UserAddress", b => + { + b.Navigation("UserOrders"); + }); #pragma warning restore 612, 618 } } diff --git a/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj b/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj index aa94be5..7bde4b6 100644 --- a/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj +++ b/src/CMSMicroservice.Protobuf/CMSMicroservice.Protobuf.csproj @@ -4,7 +4,7 @@ net7.0 enable enable - 0.0.116 + 0.0.117 None False False diff --git a/src/CMSMicroservice.Protobuf/Protos/user.proto b/src/CMSMicroservice.Protobuf/Protos/user.proto index 046ed99..858d39f 100644 --- a/src/CMSMicroservice.Protobuf/Protos/user.proto +++ b/src/CMSMicroservice.Protobuf/Protos/user.proto @@ -58,6 +58,10 @@ message CreateNewUserRequest google.protobuf.StringValue national_code = 4; google.protobuf.StringValue avatar_path = 5; google.protobuf.Int64Value parent_id = 6; + bool email_notifications = 7; + bool sms_notifications = 8; + bool push_notifications = 9; + google.protobuf.Timestamp birth_date = 10; } message CreateNewUserResponse { @@ -72,6 +76,10 @@ message UpdateUserRequest google.protobuf.StringValue avatar_path = 5; bool is_rules_accepted = 6; google.protobuf.Timestamp rules_accepted_at = 7; + bool email_notifications = 8; + bool sms_notifications = 9; + bool push_notifications = 10; + google.protobuf.Timestamp birth_date = 11; } message DeleteUserRequest { @@ -93,6 +101,10 @@ message GetUserResponse string referral_code = 8; bool is_mobile_verified = 9; google.protobuf.Timestamp mobile_verified_at = 10; + bool email_notifications = 11; + bool sms_notifications = 12; + bool push_notifications = 13; + google.protobuf.Timestamp birth_date = 14; } message GetAllUserByFilterRequest { @@ -112,6 +124,10 @@ message GetAllUserByFilterFilter google.protobuf.StringValue referral_code = 8; google.protobuf.BoolValue is_mobile_verified = 9; google.protobuf.Timestamp mobile_verified_at = 10; + google.protobuf.BoolValue email_notifications = 11; + google.protobuf.BoolValue sms_notifications = 12; + google.protobuf.BoolValue push_notifications = 13; + google.protobuf.Timestamp birth_date = 14; } message GetAllUserByFilterResponse { @@ -130,6 +146,10 @@ message GetAllUserByFilterResponseModel string referral_code = 8; bool is_mobile_verified = 9; google.protobuf.Timestamp mobile_verified_at = 10; + bool email_notifications = 11; + bool sms_notifications = 12; + bool push_notifications = 13; + google.protobuf.Timestamp birth_date = 14; } message GetJwtTokenRequest { diff --git a/src/CMSMicroservice.Protobuf/Protos/useraddress.proto b/src/CMSMicroservice.Protobuf/Protos/useraddress.proto index c918159..7dd1944 100644 --- a/src/CMSMicroservice.Protobuf/Protos/useraddress.proto +++ b/src/CMSMicroservice.Protobuf/Protos/useraddress.proto @@ -43,6 +43,12 @@ service UserAddressContract }; }; + rpc SetAddressAsDefault(SetAddressAsDefaultRequest) returns (google.protobuf.Empty){ + option (google.api.http) = { + post: "/SetAddressAsDefault" + body: "*" + }; + }; } message CreateNewUserAddressRequest { @@ -116,3 +122,7 @@ message GetAllUserAddressByFilterResponseModel bool is_default = 6; int64 city_id = 7; } +message SetAddressAsDefaultRequest +{ + int64 id = 1; +} diff --git a/src/CMSMicroservice.Protobuf/Protos/userorder.proto b/src/CMSMicroservice.Protobuf/Protos/userorder.proto index f2c98e9..b8f64b4 100644 --- a/src/CMSMicroservice.Protobuf/Protos/userorder.proto +++ b/src/CMSMicroservice.Protobuf/Protos/userorder.proto @@ -52,6 +52,7 @@ message CreateNewUserOrderRequest bool payment_status = 4; google.protobuf.Timestamp payment_date = 5; int64 user_id = 6; + int64 user_address_id = 7; } message CreateNewUserOrderResponse { @@ -66,6 +67,7 @@ message UpdateUserOrderRequest bool payment_status = 5; google.protobuf.Timestamp payment_date = 6; int64 user_id = 7; + int64 user_address_id = 8; } message DeleteUserOrderRequest { @@ -84,6 +86,7 @@ message GetUserOrderResponse bool payment_status = 5; google.protobuf.Timestamp payment_date = 6; int64 user_id = 7; + int64 user_address_id = 8; } message GetAllUserOrderByFilterRequest { @@ -100,6 +103,7 @@ message GetAllUserOrderByFilterFilter google.protobuf.BoolValue payment_status = 5; google.protobuf.Timestamp payment_date = 6; google.protobuf.Int64Value user_id = 7; + google.protobuf.Int64Value user_address_id = 8; } message GetAllUserOrderByFilterResponse { @@ -115,4 +119,5 @@ message GetAllUserOrderByFilterResponseModel bool payment_status = 5; google.protobuf.Timestamp payment_date = 6; int64 user_id = 7; + int64 user_address_id = 8; } diff --git a/src/CMSMicroservice.Protobuf/Validator/User/CreateNewUserRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/User/CreateNewUserRequestValidator.cs index 434e58a..5f05ef6 100644 --- a/src/CMSMicroservice.Protobuf/Validator/User/CreateNewUserRequestValidator.cs +++ b/src/CMSMicroservice.Protobuf/Validator/User/CreateNewUserRequestValidator.cs @@ -8,6 +8,12 @@ public class CreateNewUserRequestValidator : AbstractValidator model.Mobile) .NotEmpty(); + RuleFor(model => model.EmailNotifications) + .NotNull(); + RuleFor(model => model.SmsNotifications) + .NotNull(); + RuleFor(model => model.PushNotifications) + .NotNull(); } public Func>> ValidateValue => async (model, propertyName) => { diff --git a/src/CMSMicroservice.Protobuf/Validator/User/UpdateUserRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/User/UpdateUserRequestValidator.cs index fa0647f..67a2d7b 100644 --- a/src/CMSMicroservice.Protobuf/Validator/User/UpdateUserRequestValidator.cs +++ b/src/CMSMicroservice.Protobuf/Validator/User/UpdateUserRequestValidator.cs @@ -10,6 +10,12 @@ public class UpdateUserRequestValidator : AbstractValidator .NotNull(); RuleFor(model => model.IsRulesAccepted) .NotNull(); + RuleFor(model => model.EmailNotifications) + .NotNull(); + RuleFor(model => model.SmsNotifications) + .NotNull(); + RuleFor(model => model.PushNotifications) + .NotNull(); } public Func>> ValidateValue => async (model, propertyName) => { diff --git a/src/CMSMicroservice.Protobuf/Validator/UserAddress/SetAddressAsDefaultRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/UserAddress/SetAddressAsDefaultRequestValidator.cs new file mode 100644 index 0000000..ab78a8b --- /dev/null +++ b/src/CMSMicroservice.Protobuf/Validator/UserAddress/SetAddressAsDefaultRequestValidator.cs @@ -0,0 +1,19 @@ +using FluentValidation; +using CMSMicroservice.Protobuf.Protos.UserAddress; +namespace CMSMicroservice.Protobuf.Validator.UserAddress; + +public class SetAddressAsDefaultRequestValidator : AbstractValidator +{ + public SetAddressAsDefaultRequestValidator() + { + RuleFor(model => model.Id) + .NotNull(); + } + public Func>> ValidateValue => async (model, propertyName) => + { + var result = await ValidateAsync(ValidationContext.CreateWithOptions((SetAddressAsDefaultRequest)model, x => x.IncludeProperties(propertyName))); + if (result.IsValid) + return Array.Empty(); + return result.Errors.Select(e => e.ErrorMessage); + }; +} diff --git a/src/CMSMicroservice.Protobuf/Validator/UserOrder/CreateNewUserOrderRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/UserOrder/CreateNewUserOrderRequestValidator.cs index efbfe29..d6e33fb 100644 --- a/src/CMSMicroservice.Protobuf/Validator/UserOrder/CreateNewUserOrderRequestValidator.cs +++ b/src/CMSMicroservice.Protobuf/Validator/UserOrder/CreateNewUserOrderRequestValidator.cs @@ -14,6 +14,8 @@ public class CreateNewUserOrderRequestValidator : AbstractValidator model.UserId) .NotNull(); + RuleFor(model => model.UserAddressId) + .NotNull(); } public Func>> ValidateValue => async (model, propertyName) => { diff --git a/src/CMSMicroservice.Protobuf/Validator/UserOrder/UpdateUserOrderRequestValidator.cs b/src/CMSMicroservice.Protobuf/Validator/UserOrder/UpdateUserOrderRequestValidator.cs index c5a0801..513bb89 100644 --- a/src/CMSMicroservice.Protobuf/Validator/UserOrder/UpdateUserOrderRequestValidator.cs +++ b/src/CMSMicroservice.Protobuf/Validator/UserOrder/UpdateUserOrderRequestValidator.cs @@ -16,6 +16,8 @@ public class UpdateUserOrderRequestValidator : AbstractValidator model.UserId) .NotNull(); + RuleFor(model => model.UserAddressId) + .NotNull(); } public Func>> ValidateValue => async (model, propertyName) => { diff --git a/src/CMSMicroservice.WebApi/Services/UserAddressService.cs b/src/CMSMicroservice.WebApi/Services/UserAddressService.cs index 8872b5a..adc57e6 100644 --- a/src/CMSMicroservice.WebApi/Services/UserAddressService.cs +++ b/src/CMSMicroservice.WebApi/Services/UserAddressService.cs @@ -5,6 +5,7 @@ using CMSMicroservice.Application.UserAddressCQ.Commands.UpdateUserAddress; using CMSMicroservice.Application.UserAddressCQ.Commands.DeleteUserAddress; using CMSMicroservice.Application.UserAddressCQ.Queries.GetUserAddress; using CMSMicroservice.Application.UserAddressCQ.Queries.GetAllUserAddressByFilter; +using CMSMicroservice.Application.UserAddressCQ.Commands.SetAddressAsDefault; namespace CMSMicroservice.WebApi.Services; public class UserAddressService : UserAddressContract.UserAddressContractBase { @@ -34,4 +35,8 @@ public class UserAddressService : UserAddressContract.UserAddressContractBase { return await _dispatchRequestToCQRS.Handle(request, context); } + public override async Task SetAddressAsDefault(SetAddressAsDefaultRequest request, ServerCallContext context) + { + return await _dispatchRequestToCQRS.Handle(request, context); + } }