diff --git a/.version b/.version index 1e27443..1e4fe9a 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.24.27.47 \ No newline at end of file +0.25.27.48 \ No newline at end of file diff --git a/Netina.Api/AppSettings/appsettings.DevelopmentVesmeh.json b/Netina.Api/AppSettings/appsettings.DevelopmentVesmeh.json index 37083b9..275cfa5 100644 --- a/Netina.Api/AppSettings/appsettings.DevelopmentVesmeh.json +++ b/Netina.Api/AppSettings/appsettings.DevelopmentVesmeh.json @@ -17,7 +17,7 @@ "TaxesFee": 9 }, "SiteSettings": { - "BaseUrl": "http://localhost:32770", + "BaseUrl": "http://192.168.1.12:32770", "WebSiteUrl": "https://vesmeh.com", "AdminPanelBaseUrl": "https://admin.vesmeh.com", "StorageBaseUrl": "https://storage.vesmeh.com", diff --git a/Netina.Api/Controller/DiscountController.cs b/Netina.Api/Controller/DiscountController.cs index d99530f..57502ea 100644 --- a/Netina.Api/Controller/DiscountController.cs +++ b/Netina.Api/Controller/DiscountController.cs @@ -22,10 +22,6 @@ public class DiscountController : ICarterModule .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageDiscounts, ApplicationPermission.ViewDiscounts)) .HasApiVersion(1.0); - group.MapGet("corporate", GetCorporateDiscountAsync) - .WithDisplayName("GetDiscount") - .HasApiVersion(1.0); - group.MapPost("", Post) .HasApiVersion(1.0) .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageDiscounts)); @@ -39,10 +35,6 @@ public class DiscountController : ICarterModule .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageDiscounts)); } - private async Task GetCorporateDiscountAsync([FromQuery] Guid? corporateUserId, [FromServices] IMediator mediator, CancellationToken cancellationToken) - => TypedResults.Ok(await mediator.Send( - new CreateSaleCooperationDiscount(CorporateUserId: corporateUserId ?? default), cancellationToken)); - // GET:Get All Entity private async Task GetAllAsync([FromQuery] int page, IMediator mediator, CancellationToken cancellationToken) diff --git a/Netina.Api/Controller/HealthController.cs b/Netina.Api/Controller/HealthController.cs index 832034a..0d27822 100644 --- a/Netina.Api/Controller/HealthController.cs +++ b/Netina.Api/Controller/HealthController.cs @@ -1,6 +1,4 @@ using MD.PersianDateTime.Standard; -using Netina.Common.Models.Api; -using Netina.Core.BaseServices.Abstracts; namespace Netina.Api.Controller; diff --git a/Netina.Api/Controller/MarketerController.cs b/Netina.Api/Controller/MarketerController.cs new file mode 100644 index 0000000..37770f5 --- /dev/null +++ b/Netina.Api/Controller/MarketerController.cs @@ -0,0 +1,47 @@ +using Netina.Domain.MartenEntities.Settings; + +namespace Netina.Api.Controller; + +public class MarketerController : ICarterModule +{ + public void AddRoutes(IEndpointRouteBuilder app) + { + var group = app.NewVersionedApi("Marketer") + .MapGroup("api/marketer") + .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser()); + + group.MapGet("", GetMarketersAsync) + .WithDisplayName("GetAllMarketers") + .RequireAuthorization(builder=>builder.RequireClaim(CustomClaimType.Permission,ApplicationPermission.ManageUsers , ApplicationPermission.ViewUsers)) + .HasApiVersion(1.0); + + group.MapGet("profile", GetMarketerProfileAsync) + .WithDisplayName("GetAllMarketers") + .HasApiVersion(1.0); + + group.MapPost("signup", SignUpMarketerAsync) + .WithDisplayName("SignUpMarketer") + .HasApiVersion(1.0); + + group.MapGet("signup/contract", GetSignUpMarketerContractAsync) + .WithDisplayName("SignUpMarketerContract") + .HasApiVersion(1.0); + } + + private async Task GetMarketerProfileAsync(IMediator mediator, CancellationToken cancellationToken) + => TypedResults.Ok(await mediator.Send(new GetMarketerProfileQuery(), cancellationToken)); + + private async Task GetSignUpMarketerContractAsync([FromServices] ISettingService settingService,CancellationToken cancellationToken) + { + var setting = await settingService.GetSettingAsync(nameof(MarketerSetting), cancellationToken); + if (setting is MarketerSetting marketerSetting) + return TypedResults.Ok(marketerSetting.ContractTerms); + throw new AppException("MarketerSetting not found"); + } + + private async Task SignUpMarketerAsync([FromBody] SignUpMarketerCommand request, [FromServices] IMediator mediator, CancellationToken cancellationToken) + => TypedResults.Ok(await mediator.Send(request, cancellationToken)); + + private async Task GetMarketersAsync([FromQuery] int page, [FromServices] IMediator mediator, CancellationToken cancellationToken) + => TypedResults.Ok(await mediator.Send(new GetMarketersQuery(page), cancellationToken)); +} \ No newline at end of file diff --git a/Netina.Api/Netina.Api.csproj b/Netina.Api/Netina.Api.csproj index 84c7bb6..44c0289 100644 --- a/Netina.Api/Netina.Api.csproj +++ b/Netina.Api/Netina.Api.csproj @@ -6,8 +6,8 @@ enable true Linux - 0.24.27.47 - 0.24.27.47 + 0.25.27.48 + 0.25.27.48 diff --git a/Netina.Api/Program.cs b/Netina.Api/Program.cs index 0dbbce0..8a368ff 100644 --- a/Netina.Api/Program.cs +++ b/Netina.Api/Program.cs @@ -8,7 +8,7 @@ string env = builder.Environment.IsDevelopment() == true ? "Development" : "Prod builder.Host.UseContentRoot(Directory.GetCurrentDirectory()); if (builder.Environment.IsDevelopment()) { - string projectName = "Hamyan"; + string projectName = "Vesmeh"; builder.Configuration.AddJsonFile($"AppSettings/appsettings.json").AddJsonFile($"AppSettings/appsettings.{env}{projectName}.json"); } diff --git a/Netina.Api/WebFramework/MiddleWares/ExceptionHandlerMiddleware.cs b/Netina.Api/WebFramework/MiddleWares/ExceptionHandlerMiddleware.cs index 936177f..4b2f568 100644 --- a/Netina.Api/WebFramework/MiddleWares/ExceptionHandlerMiddleware.cs +++ b/Netina.Api/WebFramework/MiddleWares/ExceptionHandlerMiddleware.cs @@ -145,7 +145,7 @@ public class ExceptionHandlerMiddleware }); if (httpStatusCode == HttpStatusCode.InternalServerError) - context.Response.StatusCode = 501; + context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; else context.Response.StatusCode = (int)httpStatusCode; context.Response.ContentType = "application/json"; @@ -174,7 +174,7 @@ public class ExceptionHandlerMiddleware }); if (httpStatusCode == HttpStatusCode.InternalServerError) - context.Response.StatusCode = 501; + context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; else context.Response.StatusCode = (int)httpStatusCode; context.Response.ContentType = "application/json"; diff --git a/Netina.Common/Models/Api/ApiResultStatusCode.cs b/Netina.Common/Models/Api/ApiResultStatusCode.cs index f589038..d34acdf 100644 --- a/Netina.Common/Models/Api/ApiResultStatusCode.cs +++ b/Netina.Common/Models/Api/ApiResultStatusCode.cs @@ -36,6 +36,9 @@ namespace Netina.Common.Models.Api [Display(Name = "در ارسال درخواست به سرورهای دیگر مشکلی رخ داده است")] - RefitError = 8 + RefitError = 8, + + [Display(Name = "بازاریاب پیدا نشد یا ثبت نام نکرده است")] + MarketerNotFound = 9, } } \ No newline at end of file diff --git a/Netina.Common/Netina.Common.csproj b/Netina.Common/Netina.Common.csproj index b49a057..a752020 100644 --- a/Netina.Common/Netina.Common.csproj +++ b/Netina.Common/Netina.Common.csproj @@ -1,6 +1,6 @@  - + - + diff --git a/Netina.Core/CoreServices/SettingService.cs b/Netina.Core/CoreServices/SettingService.cs index 3d41261..4a750c5 100644 --- a/Netina.Core/CoreServices/SettingService.cs +++ b/Netina.Core/CoreServices/SettingService.cs @@ -1,11 +1,4 @@ -using Netina.Common.Models.Api; -using Netina.Common.Models.Exception; -using Netina.Core.CoreServices.Abstracts; -using Netina.Domain; -using Netina.Domain.MartenEntities.Settings; -using Netina.Repository.Repositories.Marten; - -namespace Netina.Core.CoreServices; +namespace Netina.Core.CoreServices; public class SettingService : ISettingService diff --git a/Netina.Repository/Handlers/Discounts/CreateSaleCooperationDiscountHandler.cs b/Netina.Core/EntityServices/MarketerHandlers/CreateMarketerDiscountCommandHandler.cs similarity index 61% rename from Netina.Repository/Handlers/Discounts/CreateSaleCooperationDiscountHandler.cs rename to Netina.Core/EntityServices/MarketerHandlers/CreateMarketerDiscountCommandHandler.cs index a661311..da4239b 100644 --- a/Netina.Repository/Handlers/Discounts/CreateSaleCooperationDiscountHandler.cs +++ b/Netina.Core/EntityServices/MarketerHandlers/CreateMarketerDiscountCommandHandler.cs @@ -1,22 +1,25 @@ -using Microsoft.EntityFrameworkCore; +namespace Netina.Core.EntityServices.MarketerHandlers; -namespace Netina.Repository.Handlers.Discounts; - -public class CreateSaleCooperationDiscountHandler : IRequestHandler +public class CreateMarketerDiscountCommandHandler : IRequestHandler { private readonly UserManager _userManager; private readonly IRepositoryWrapper _repositoryWrapper; private readonly ICurrentUserService _currentUserService; + private readonly ISettingService _settingService; - public CreateSaleCooperationDiscountHandler(UserManager userManager,IRepositoryWrapper repositoryWrapper,ICurrentUserService currentUserService) + public CreateMarketerDiscountCommandHandler(UserManager userManager, + IRepositoryWrapper repositoryWrapper, + ICurrentUserService currentUserService, + ISettingService settingService) { _userManager = userManager; _repositoryWrapper = repositoryWrapper; _currentUserService = currentUserService; + _settingService = settingService; } - public async Task Handle(CreateSaleCooperationDiscount request, CancellationToken cancellationToken) + public async Task Handle(CreateMarketerDiscountCommand request, CancellationToken cancellationToken) { - var userId = request.CorporateUserId; + var userId = request.MarketerUserId; if (userId == default) { if (_currentUserService.UserId == null) @@ -34,16 +37,20 @@ public class CreateSaleCooperationDiscountHandler : IRequestHandler() .TableNoTracking .FirstOrDefaultAsync(d => d.IsForSaleCooperation && d.MarketerId == marketer.Id, cancellationToken); if (foundedDiscount == null) { + var setting = await _settingService.GetSettingAsync(nameof(MarketerSetting), cancellationToken); + int discountPercent = 10; + if (setting is MarketerSetting marketerSetting) + discountPercent = marketerSetting.DiscountPercent; + var code = StringExtensions.GetId(); - foundedDiscount = Discount.Create(code,$"کد مخصوص همکاری در فروش برای کاربر - {user.FirstName} {user.LastName}", 10, 0, true, + foundedDiscount = Discount.Create(code, $"کد مخصوص همکاری در فروش برای کاربر - {user.FirstName} {user.LastName}", discountPercent, 0, true, DiscountAmountType.Percent, DiscountType.All, 0, true, DateTime.Today, DateTime.Today.AddYears(10), 0, - false, 0, false, true, 0, false, false,false); + false, 0, false, true, 0, false, false, false); foundedDiscount.SetCorporate(marketer.Id); _repositoryWrapper.SetRepository().Add(foundedDiscount); diff --git a/Netina.Core/EntityServices/MarketerHandlers/GetMarketerProfileQueryHandler.cs b/Netina.Core/EntityServices/MarketerHandlers/GetMarketerProfileQueryHandler.cs new file mode 100644 index 0000000..2da31bc --- /dev/null +++ b/Netina.Core/EntityServices/MarketerHandlers/GetMarketerProfileQueryHandler.cs @@ -0,0 +1,72 @@ +using System.Net; + +namespace Netina.Core.EntityServices.MarketerHandlers; + +public class GetMarketerProfileQueryHandler : IRequestHandler +{ + private readonly IRepositoryWrapper _repositoryWrapper; + private readonly ICurrentUserService _currentUserService; + private readonly ISettingService _settingService; + + public GetMarketerProfileQueryHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService,ISettingService settingService) + { + _repositoryWrapper = repositoryWrapper; + _currentUserService = currentUserService; + _settingService = settingService; + } + public async Task Handle(GetMarketerProfileQuery request, CancellationToken cancellationToken) + { + Guid marketerId; + Marketer? marketer; + if (request.MarketerId != null) + { + marketerId = request.MarketerId.Value; + marketer = await _repositoryWrapper.SetRepository() + .TableNoTracking + .FirstOrDefaultAsync(m => m.Id == marketerId, cancellationToken); + } + else + { + if (_currentUserService.UserId == null) + throw new BaseApiException("User id is null"); + if (!Guid.TryParse(_currentUserService.UserId, out Guid userId)) + throw new BaseApiException("User id is wrong"); + marketer = await _repositoryWrapper.SetRepository() + .TableNoTracking + .FirstOrDefaultAsync(m => m.UserId == userId, cancellationToken); + + } + + if (marketer == null) + throw new BaseApiException(ApiResultStatusCode.MarketerNotFound,"Marketer not found" ,HttpStatusCode.NotFound); + + var discount = await _repositoryWrapper.SetRepository() + .TableNoTracking + .FirstOrDefaultAsync(d => d.MarketerId == marketer.Id, cancellationToken); + + if (discount == null) + throw new BaseApiException("Marketer has no discount"); + + var setting = (await _settingService.GetSettingAsync(nameof(MarketerSetting), cancellationToken)) as MarketerSetting; + if (setting == null) + throw new BaseApiException("MarketerSetting is null"); + + + var response = new MarketerProfileResponseDto(); + + var orderCount = await _repositoryWrapper.SetRepository() + .TableNoTracking + .CountAsync(o => o.DiscountCode == discount.Code, cancellationToken); + response.OrderCount = orderCount; + + var newTotalProductPrice = await _repositoryWrapper.SetRepository() + .TableNoTracking + .Where(o => o.DiscountCode == discount.Code && o.OrderAt.Date > marketer.LastSettlement.Date) + .SumAsync(o => o.TotalProductsPrice, cancellationToken); + response.Balance = (long)(newTotalProductPrice / 100) * setting.ProfitPercent; + response.DiscountCode = discount.Code; + response.LastSettlementAt = marketer.LastSettlement; + + return response; + } +} \ No newline at end of file diff --git a/Netina.Core/EntityServices/MarketerHandlers/SignUpMarketerCommandHandler.cs b/Netina.Core/EntityServices/MarketerHandlers/SignUpMarketerCommandHandler.cs new file mode 100644 index 0000000..4fa674b --- /dev/null +++ b/Netina.Core/EntityServices/MarketerHandlers/SignUpMarketerCommandHandler.cs @@ -0,0 +1,53 @@ +namespace Netina.Core.EntityServices.MarketerHandlers; + +public class SignUpMarketerCommandHandler : IRequestHandler +{ + private readonly UserManager _userManager; + private readonly IMediator _mediator; + private readonly ICurrentUserService _currentUserService; + private readonly IRepositoryWrapper _repositoryWrapper; + + public SignUpMarketerCommandHandler(UserManager userManager,IMediator mediator,ICurrentUserService currentUserService,IRepositoryWrapper repositoryWrapper) + { + _userManager = userManager; + _mediator = mediator; + _currentUserService = currentUserService; + _repositoryWrapper = repositoryWrapper; + } + public async Task Handle(SignUpMarketerCommand request, CancellationToken cancellationToken) + { + + if (_currentUserService.UserId == null) + throw new AppException("User id is null"); + if (!Guid.TryParse(_currentUserService.UserId, out Guid userId)) + throw new AppException("User id is wrong"); + + var user = await _userManager.FindByIdAsync(_currentUserService.UserId); + if (user == null) + throw new AppException("User not found"); + + var marketer = await _repositoryWrapper.SetRepository() + .TableNoTracking + .FirstOrDefaultAsync(m => m.UserId == userId, cancellationToken); + if (marketer != null) + return await _mediator.Send(new GetMarketerProfileQuery(MarketerId: marketer.Id), cancellationToken); + + marketer = new Marketer + { + UserId = user.Id, + FatherName = request.FatherName, + Shaba = request.Shaba, + }; + _repositoryWrapper.SetRepository() + .Add(marketer); + await _repositoryWrapper.SaveChangesAsync(cancellationToken); + + user.BirthDate = DateTimeExtensions.UnixTimeStampToDateTime(request.BirthDate); + user.NationalId = request.NationalId; + await _userManager.UpdateAsync(user); + + await _mediator.Send(new CreateMarketerDiscountCommand(userId), cancellationToken); + + return await _mediator.Send(new GetMarketerProfileQuery(marketer.Id), cancellationToken); + } +} \ No newline at end of file diff --git a/Netina.Core/EntityServices/MarketerHandlers/Validators/SignUpMarketerCommandValidator.cs b/Netina.Core/EntityServices/MarketerHandlers/Validators/SignUpMarketerCommandValidator.cs new file mode 100644 index 0000000..e510ac9 --- /dev/null +++ b/Netina.Core/EntityServices/MarketerHandlers/Validators/SignUpMarketerCommandValidator.cs @@ -0,0 +1,24 @@ +using FluentValidation; + +namespace Netina.Core.EntityServices.MarketerHandlers.Validators; + +public class SignUpMarketerCommandValidator : AbstractValidator +{ + public SignUpMarketerCommandValidator() + { + RuleFor(command => command.FatherName) + .NotNull() + .NotEmpty() + .WithMessage("نام پدر را وارد کنید"); + + RuleFor(command => command.BirthDate) + .NotNull() + .NotEqual(0) + .WithMessage("تاریخ تولد را وارد کنید"); + + RuleFor(command => command.Shaba) + .NotNull() + .NotEmpty() + .WithMessage("شماره شبا را وارد کنید"); + } +} \ No newline at end of file diff --git a/Netina.Core/EntityServices/UserService.cs b/Netina.Core/EntityServices/UserService.cs index 4337306..5657c59 100644 --- a/Netina.Core/EntityServices/UserService.cs +++ b/Netina.Core/EntityServices/UserService.cs @@ -1,18 +1,4 @@ -using Netina.Common.Extensions; -using Netina.Common.Models.Api; -using Netina.Common.Models.Exception; -using Netina.Core.Abstracts; -using Netina.Core.EntityServices.Abstracts; -using Netina.Domain.Dtos.RequestDtos; -using Netina.Domain.Dtos.ResponseDtos; -using Netina.Domain.Dtos.SmallDtos; -using Netina.Domain.Entities.Users; -using Netina.Domain.Enums; -using Netina.Domain.Models.Claims; -using Netina.Repository.Abstracts; -using Netina.Repository.Repositories.Base.Contracts; - -namespace Netina.Core.EntityServices; +namespace Netina.Core.EntityServices; public class UserService : IUserService @@ -94,7 +80,7 @@ public class UserService : IUserService } var returnUser = users.Where(r => r.FullName.Trim() != "همه کاره سیستم").ToList(); - return returnUser; + return returnUser; } public async Task GetUserAsync(Guid userId, CancellationToken cancellationToken = default) @@ -103,6 +89,12 @@ public class UserService : IUserService if (user == null) throw new AppException("User not found", ApiResultStatusCode.NotFound); var dto = user.AdaptToSDto(); + dto.IsMarketer = await _repositoryWrapper.SetRepository() + .TableNoTracking + .AnyAsync(m => m.UserId == userId, cancellationToken); + dto.IsManager = await _repositoryWrapper.SetRepository() + .TableNoTracking + .AnyAsync(m => m.UserId == userId, cancellationToken); var roles = await _userManager.GetRolesAsync(user); foreach (var roleName in roles) { diff --git a/Netina.Domain/CommandQueries/Commands/DiscountCommands.cs b/Netina.Domain/CommandQueries/Commands/DiscountCommands.cs index eeaf9cb..0d772e8 100644 --- a/Netina.Domain/CommandQueries/Commands/DiscountCommands.cs +++ b/Netina.Domain/CommandQueries/Commands/DiscountCommands.cs @@ -48,7 +48,6 @@ public sealed record UpdateDiscountCommand( Guid ProductId, Guid CategoryId) : IRequest; -public sealed record CreateSaleCooperationDiscount(Guid CorporateUserId) : IRequest; public sealed record DeleteDiscountCommand(Guid Id) : IRequest; diff --git a/Netina.Domain/CommandQueries/Commands/MarketerCommands.cs b/Netina.Domain/CommandQueries/Commands/MarketerCommands.cs new file mode 100644 index 0000000..3697c70 --- /dev/null +++ b/Netina.Domain/CommandQueries/Commands/MarketerCommands.cs @@ -0,0 +1,5 @@ +namespace Netina.Domain.CommandQueries.Commands; + +public sealed record SignUpMarketerCommand(string FatherName , long BirthDate, string Shaba , string NationalId) : IRequest; + +public sealed record CreateMarketerDiscountCommand(Guid MarketerUserId) : IRequest; \ No newline at end of file diff --git a/Netina.Domain/CommandQueries/Queries/MarketerQueries.cs b/Netina.Domain/CommandQueries/Queries/MarketerQueries.cs new file mode 100644 index 0000000..eeab928 --- /dev/null +++ b/Netina.Domain/CommandQueries/Queries/MarketerQueries.cs @@ -0,0 +1,5 @@ +namespace Netina.Domain.CommandQueries.Queries; + +public sealed record GetMarketerProfileQuery(Guid? MarketerId = null) : IRequest; + +public sealed record GetMarketersQuery(int Page , string? PhoneNumber = null , string? FullName = null) : IRequest>; \ No newline at end of file diff --git a/Netina.Domain/Dtos/ResponseDtos/MarketerProfileResponseDto.cs b/Netina.Domain/Dtos/ResponseDtos/MarketerProfileResponseDto.cs new file mode 100644 index 0000000..8161605 --- /dev/null +++ b/Netina.Domain/Dtos/ResponseDtos/MarketerProfileResponseDto.cs @@ -0,0 +1,9 @@ +namespace Netina.Domain.Dtos.ResponseDtos; + +public class MarketerProfileResponseDto +{ + public string DiscountCode { get; set; } = string.Empty; + public DateTime LastSettlementAt { get; set; } + public int OrderCount { get; set; } + public long Balance { get; set; } +} \ No newline at end of file diff --git a/Netina.Domain/Dtos/SmallDtos/ApplicationUserSDto.cs b/Netina.Domain/Dtos/SmallDtos/ApplicationUserSDto.cs index 48ef34a..5f4a4fa 100644 --- a/Netina.Domain/Dtos/SmallDtos/ApplicationUserSDto.cs +++ b/Netina.Domain/Dtos/SmallDtos/ApplicationUserSDto.cs @@ -14,6 +14,9 @@ public class ApplicationUserSDto : BaseDto public string FullName => FirstName + " " + LastName; public string RoleName { get; set; } = string.Empty; + public bool IsMarketer { get; set; } + public bool IsManager { get; set; } + public List RoleIds { get; set; } = new(); public long BirthDateTimeStamp => BirthDate.Year > 1970 ? DateTimeExtensions.DateTimeToUnixTimeStamp(BirthDate) : 0; } \ No newline at end of file diff --git a/Netina.Domain/Mappers/ApplicationUserMapper.g.cs b/Netina.Domain/Mappers/ApplicationUserMapper.g.cs index e0ab309..a97a661 100644 --- a/Netina.Domain/Mappers/ApplicationUserMapper.g.cs +++ b/Netina.Domain/Mappers/ApplicationUserMapper.g.cs @@ -54,6 +54,8 @@ namespace Netina.Domain.Mappers SignUpStatus = p4.SignUpStatus, NationalId = p4.NationalId, Email = p4.Email, + IsMarketer = p4.Marketer != null, + IsManager = p4.Manager != null, Id = p4.Id }; } @@ -73,6 +75,8 @@ namespace Netina.Domain.Mappers result.SignUpStatus = p5.SignUpStatus; result.NationalId = p5.NationalId; result.Email = p5.Email; + result.IsMarketer = p5.Marketer != null; + result.IsManager = p5.Manager != null; result.Id = p5.Id; return result; @@ -87,6 +91,8 @@ namespace Netina.Domain.Mappers SignUpStatus = p7.SignUpStatus, NationalId = p7.NationalId, Email = p7.Email, + IsMarketer = p7.Marketer != null, + IsManager = p7.Manager != null, Id = p7.Id }; } diff --git a/Netina.Domain/MapsterRegister.cs b/Netina.Domain/MapsterRegister.cs index 8af4da2..15fcccd 100644 --- a/Netina.Domain/MapsterRegister.cs +++ b/Netina.Domain/MapsterRegister.cs @@ -7,7 +7,7 @@ public class MapsterRegister : IRegister public void Register(TypeAdapterConfig config) { config.NewConfig() - .Map("MainImage", o => o.Files.Count > 0 && o.Files.Any(f=>f.IsPrimary) ? o.Files.FirstOrDefault(f=>f.IsPrimary)!.FileName : string.Empty) + .Map("MainImage", o => o.Files.Count > 0 && o.Files.Any(f => f.IsPrimary) ? o.Files.FirstOrDefault(f => f.IsPrimary)!.FileName : string.Empty) .TwoWays(); config.NewConfig() @@ -36,7 +36,7 @@ public class MapsterRegister : IRegister .TwoWays(); config.NewConfig() - .Map("MainImage",o=>o.Files.FirstOrDefault(f=>f.IsPrimary) != null ? o.Files.FirstOrDefault(f => f.IsPrimary).FileLocation : o.Files.Count>0 ? o.Files.FirstOrDefault().FileLocation : string.Empty) + .Map("MainImage", o => o.Files.FirstOrDefault(f => f.IsPrimary) != null ? o.Files.FirstOrDefault(f => f.IsPrimary).FileLocation : o.Files.Count > 0 ? o.Files.FirstOrDefault().FileLocation : string.Empty) .Map("CategoryName", o => o.Category == null ? null : o.Category.Name) .Map("BrandName", o => o.Brand == null ? null : o.Brand.PersianName) .IgnoreNullValues(false) @@ -100,6 +100,10 @@ public class MapsterRegister : IRegister private void ConfigUserMappers(TypeAdapterConfig config) { + config.NewConfig() + .Map("IsMarketer", o => o.Marketer != null) + .Map("IsManager", o => o.Manager != null) + .TwoWays(); config.NewConfig() .Map("PhoneNumber", o => o.User != null ? o.User.PhoneNumber : string.Empty) diff --git a/Netina.Domain/MartenEntities/Settings/MarketerSetting.cs b/Netina.Domain/MartenEntities/Settings/MarketerSetting.cs index 5f05cb9..48d9002 100644 --- a/Netina.Domain/MartenEntities/Settings/MarketerSetting.cs +++ b/Netina.Domain/MartenEntities/Settings/MarketerSetting.cs @@ -4,4 +4,5 @@ public class MarketerSetting { public int ProfitPercent { get; set; } public string ContractTerms { get; set; } = string.Empty; + public int DiscountPercent { get; set; } } \ No newline at end of file diff --git a/Netina.Domain/Netina.Domain.csproj b/Netina.Domain/Netina.Domain.csproj index 5744c2b..33e99bf 100644 --- a/Netina.Domain/Netina.Domain.csproj +++ b/Netina.Domain/Netina.Domain.csproj @@ -1,6 +1,6 @@  - + - + diff --git a/Netina.Repository/Handlers/Addresses/GetUserAddressesQueryHandler.cs b/Netina.Repository/Handlers/Addresses/GetUserAddressesQueryHandler.cs index be3e75f..cd0633d 100644 --- a/Netina.Repository/Handlers/Addresses/GetUserAddressesQueryHandler.cs +++ b/Netina.Repository/Handlers/Addresses/GetUserAddressesQueryHandler.cs @@ -1,11 +1,4 @@ using Microsoft.EntityFrameworkCore; -using Netina.Common.Models.Api; -using Netina.Common.Models.Exception; -using Netina.Domain.CommandQueries.Queries; -using Netina.Domain.Dtos.SmallDtos; -using Netina.Domain.Entities.Users; -using Netina.Repository.Abstracts; -using Netina.Repository.Repositories.Base.Contracts; namespace Netina.Repository.Handlers.Addresses; diff --git a/Netina.Repository/Handlers/Discounts/Validators/UpdateDiscountCommandValidator.cs b/Netina.Repository/Handlers/Discounts/Validators/UpdateDiscountCommandValidator.cs index 9a3c6ff..ae6664a 100644 --- a/Netina.Repository/Handlers/Discounts/Validators/UpdateDiscountCommandValidator.cs +++ b/Netina.Repository/Handlers/Discounts/Validators/UpdateDiscountCommandValidator.cs @@ -1,6 +1,4 @@ using FluentValidation; -using Netina.Domain.CommandQueries.Commands; -using Netina.Domain.Enums; namespace Netina.Repository.Handlers.Discounts.Validators; diff --git a/Netina.Repository/Handlers/Marketers/GetMarketersQueryHandler.cs b/Netina.Repository/Handlers/Marketers/GetMarketersQueryHandler.cs new file mode 100644 index 0000000..ec3a1cd --- /dev/null +++ b/Netina.Repository/Handlers/Marketers/GetMarketersQueryHandler.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; + +namespace Netina.Repository.Handlers.Marketers; + +public class GetMarketersQueryHandler : IRequestHandler> +{ + private readonly IRepositoryWrapper _repositoryWrapper; + + public GetMarketersQueryHandler(IRepositoryWrapper repositoryWrapper) + { + _repositoryWrapper = repositoryWrapper; + } + public async Task> Handle(GetMarketersQuery request, CancellationToken cancellationToken) + { + var query = _repositoryWrapper.SetRepository() + .TableNoTracking; + + return await query.OrderByDescending(q => q.CreatedAt) + .Skip(request.Page * 20) + .Take(20) + .Select(MarketerMapper.ProjectToSDto) + .ToListAsync(cancellationToken); + } +} \ No newline at end of file