feat : add new version 0.21.24.41 , fix dont display product
parent
c910afcda6
commit
acd24336b2
|
@ -38,8 +38,8 @@
|
|||
},
|
||||
"JwtSettings": {
|
||||
"SecretKey": "YAEMAMZAMAN_KHODET_NEGAHDAR_IN_KEY_BASH_nw+8E0EABj0Wg8c4mHg/bDBf5qGMhmBPb6u16DVe9/MzYva1e+/J1zImyIoQX2Lmra2kvzsIjGiwP7r3Znd_YA_JADE_NASABE_v+Ro/CDixScDv6EkpZnkBv9MFdPnSmFXNGMH9gA1BzQUoC1iSX9Aq+pMIw/cMKXI9WA==_YA_HUSEIN_SEYED_SHOHADA_BE_OMID_KHODET",
|
||||
"Issuer": "Brizco",
|
||||
"Audience": "Brizco",
|
||||
"Issuer": "NetinaShop",
|
||||
"Audience": "NetinaShop",
|
||||
"ExpireAddDay": "15"
|
||||
}
|
||||
},
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<AssemblyVersion>0.20.23.40</AssemblyVersion>
|
||||
<FileVersion>0.20.23.40</FileVersion>
|
||||
<AssemblyVersion>0.21.24.41</AssemblyVersion>
|
||||
<FileVersion>0.21.24.41</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using System.Security.Cryptography;
|
||||
using NetinaShop.Repository.Abstracts;
|
||||
using Polly;
|
||||
using static NetinaShop.Infrastructure.Models.Scrapers.Digikala.GetDigikalProductResponseDto;
|
||||
|
||||
namespace NetinaShop.Api.Services;
|
||||
|
||||
|
@ -17,6 +19,17 @@ public class CurrentUserService : ICurrentUserService
|
|||
public string? UserName => _httpContextAccessor.HttpContext?.User?.FindFirstValue(ClaimTypes.Name);
|
||||
public string? DeviceId => GetDeviceId(_httpContextAccessor.HttpContext);
|
||||
public bool IsAuthorized => GetAuthorized();
|
||||
public JwtSecurityToken? JwtToken => GetJwtToken();
|
||||
private JwtSecurityToken? GetJwtToken()
|
||||
{
|
||||
var stream = _httpContextAccessor.HttpContext?.Request.Headers.Authorization.FirstOrDefault();
|
||||
if (stream == null)
|
||||
return null;
|
||||
var handler = new JwtSecurityTokenHandler();
|
||||
var jsonToken = handler.ReadToken(stream.Split(" ").Last());
|
||||
return jsonToken as JwtSecurityToken;
|
||||
}
|
||||
|
||||
public List<string>? Permissions => _httpContextAccessor.HttpContext?.User?.FindAll("Permission")?.Select(c => c.Value)?.ToList();
|
||||
|
||||
private string? GetDeviceId(HttpContext? context)
|
||||
|
@ -47,4 +60,5 @@ public class CurrentUserService : ICurrentUserService
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
namespace NetinaShop.Repository.Abstracts;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
|
||||
namespace NetinaShop.Repository.Abstracts;
|
||||
|
||||
public interface ICurrentUserService : IScopedDependency
|
||||
{
|
||||
|
@ -7,5 +9,7 @@ public interface ICurrentUserService : IScopedDependency
|
|||
string? UserName { get; }
|
||||
string? DeviceId { get; }
|
||||
bool IsAuthorized { get; }
|
||||
JwtSecurityToken? JwtToken { get; }
|
||||
|
||||
public List<string>? Permissions { get; }
|
||||
}
|
|
@ -1,4 +1,8 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using static Microsoft.AspNetCore.Hosting.Internal.HostingApplication;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Net;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace NetinaShop.Repository.Handlers.Products;
|
||||
|
||||
|
@ -6,16 +10,24 @@ public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, GetProd
|
|||
{
|
||||
private readonly IRepositoryWrapper _repositoryWrapper;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
|
||||
public GetProductsQueryHandler(IRepositoryWrapper repositoryWrapper, IMediator mediator)
|
||||
public GetProductsQueryHandler(IRepositoryWrapper repositoryWrapper, IMediator mediator, ICurrentUserService currentUserService)
|
||||
{
|
||||
_repositoryWrapper = repositoryWrapper;
|
||||
_mediator = mediator;
|
||||
_currentUserService = currentUserService;
|
||||
}
|
||||
public async Task<GetProductsResponseDto> Handle(GetProductsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new GetProductsResponseDto();
|
||||
var products = _repositoryWrapper.SetRepository<Product>().TableNoTracking;
|
||||
if (_currentUserService.JwtToken == null)
|
||||
products = products.Where(p => p.BeDisplayed);
|
||||
var roleClaim = _currentUserService.JwtToken?.Claims.FirstOrDefault(c => c.Type == "role");
|
||||
if (roleClaim != null && roleClaim.Value.Contains("Customer"))
|
||||
products = products.Where(p => p.BeDisplayed);
|
||||
|
||||
if (request.IsActive != null)
|
||||
products = products.Where(p => p.IsEnable == request.IsActive);
|
||||
if (request.ProductName != null)
|
||||
|
@ -66,7 +78,7 @@ public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, GetProd
|
|||
response.Pager.TotalItems = await products.CountAsync(cancellationToken);
|
||||
response.Pager.TotalPage = response.Pager.TotalItems % 20 == 0 ? response.Pager.TotalItems / 20 : (response.Pager.TotalItems / 20) + 1;
|
||||
|
||||
if(await products.AnyAsync(cancellationToken))
|
||||
if (await products.AnyAsync(cancellationToken))
|
||||
{
|
||||
response.Filters.Price.MaximumValue = await products.MaxAsync(p => p.Cost, cancellationToken);
|
||||
response.Filters.Price.MinimumValue = await products.MinAsync(p => p.Cost, cancellationToken);
|
||||
|
@ -88,4 +100,5 @@ public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, GetProd
|
|||
response.Products = productSDtos;
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue