fix : order homepage informations
parent
c152f06e08
commit
27e8f545fe
|
@ -1,4 +1,6 @@
|
||||||
using Netina.Domain.Entities.Blogs;
|
using Marten.Events;
|
||||||
|
using Netina.Domain.Entities.Blogs;
|
||||||
|
using Netina.Domain.Entities.Products;
|
||||||
|
|
||||||
namespace Netina.Api.Controllers;
|
namespace Netina.Api.Controllers;
|
||||||
|
|
||||||
|
@ -60,6 +62,7 @@ public class BlogController : ICarterModule
|
||||||
{
|
{
|
||||||
ent.AddFile(file.Name, file.FileLocation, file.FileName, file.IsHeader, file.IsPrimary, file.FileType);
|
ent.AddFile(file.Name, file.FileLocation, file.FileName, file.IsHeader, file.IsPrimary, file.FileType);
|
||||||
}
|
}
|
||||||
|
|
||||||
repositoryWrapper.SetRepository<Blog>().Add(ent);
|
repositoryWrapper.SetRepository<Blog>().Add(ent);
|
||||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||||
return TypedResults.Ok(ent.AdaptToSDto());
|
return TypedResults.Ok(ent.AdaptToSDto());
|
||||||
|
@ -76,6 +79,20 @@ public class BlogController : ICarterModule
|
||||||
newEnt.Id = ent.Id;
|
newEnt.Id = ent.Id;
|
||||||
newEnt.CreatedAt = ent.CreatedAt;
|
newEnt.CreatedAt = ent.CreatedAt;
|
||||||
newEnt.CreatedBy = ent.CreatedBy;
|
newEnt.CreatedBy = ent.CreatedBy;
|
||||||
|
|
||||||
|
var dbFiles = await repositoryWrapper.SetRepository<BlogStorageFile>().TableNoTracking
|
||||||
|
.Where(s => s.BlogId == newEnt.Id).ToListAsync(cancellationToken);
|
||||||
|
foreach (var dbFile in dbFiles)
|
||||||
|
{
|
||||||
|
if (dto.Files.FirstOrDefault(s => s.Id == dbFile.Id) == null)
|
||||||
|
{
|
||||||
|
repositoryWrapper.SetRepository<BlogStorageFile>().Delete(dbFile);
|
||||||
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var file in dto.Files.Where(f => f.Id == default))
|
||||||
|
newEnt.AddFile(file.Name, file.FileLocation, file.FileName, file.IsHeader, file.IsPrimary, file.FileType);
|
||||||
|
|
||||||
repositoryWrapper.SetRepository<Blog>().Update(newEnt);
|
repositoryWrapper.SetRepository<Blog>().Update(newEnt);
|
||||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||||
return TypedResults.Ok();
|
return TypedResults.Ok();
|
||||||
|
|
|
@ -12,8 +12,16 @@ public class DashboardController : ICarterModule
|
||||||
.WithDisplayName("Get Home Dashboard")
|
.WithDisplayName("Get Home Dashboard")
|
||||||
.HasApiVersion(1.0);
|
.HasApiVersion(1.0);
|
||||||
|
|
||||||
|
group.MapGet("orders", GetOrdersDashboardAsync)
|
||||||
|
.WithDisplayName("Get Orders Dashboard")
|
||||||
|
.HasApiVersion(1.0);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<IResult> GetOrdersDashboardAsync([FromServices] IDashboardService dashboardService, CancellationToken cancellationToken)
|
||||||
|
=> TypedResults.Ok(await dashboardService.GetOrdersDashboardAsyncTask(cancellationToken));
|
||||||
|
|
||||||
private async Task<IResult> GetHomeDashboardAsync([FromServices] IDashboardService dashboardService, CancellationToken cancellationToken)
|
private async Task<IResult> GetHomeDashboardAsync([FromServices] IDashboardService dashboardService, CancellationToken cancellationToken)
|
||||||
=> TypedResults.Ok(await dashboardService.GetHomeDashboardAsyncTask(cancellationToken));
|
=> TypedResults.Ok(await dashboardService.GetHomeDashboardAsyncTask(cancellationToken));
|
||||||
}
|
}
|
|
@ -1,9 +1,7 @@
|
||||||
using Netina.Common.Models;
|
namespace Netina.Core.BaseServices.Abstracts;
|
||||||
using Netina.Domain.Dtos.DashboardDtos;
|
|
||||||
|
|
||||||
namespace Netina.Core.BaseServices.Abstracts;
|
|
||||||
|
|
||||||
public interface IDashboardService : IScopedDependency
|
public interface IDashboardService : IScopedDependency
|
||||||
{
|
{
|
||||||
public Task<HomeDashboardDto> GetHomeDashboardAsyncTask(CancellationToken cancellationToken = default);
|
public Task<HomeDashboardDto> GetHomeDashboardAsyncTask(CancellationToken cancellationToken = default);
|
||||||
|
public Task<OrderDashboardDto> GetOrdersDashboardAsyncTask(CancellationToken cancellationToken = default);
|
||||||
}
|
}
|
|
@ -1,12 +1,4 @@
|
||||||
using Netina.Core.BaseServices.Abstracts;
|
using MD.PersianDateTime.Standard;
|
||||||
using Netina.Domain.Dtos.DashboardDtos;
|
|
||||||
using Netina.Domain.Entities.Blogs;
|
|
||||||
using Netina.Domain.Entities.Brands;
|
|
||||||
using Netina.Domain.Entities.Orders;
|
|
||||||
using Netina.Domain.Entities.Products;
|
|
||||||
using Netina.Domain.Entities.Users;
|
|
||||||
using Netina.Domain.Enums;
|
|
||||||
using Netina.Repository.Repositories.Base.Contracts;
|
|
||||||
|
|
||||||
namespace Netina.Core.BaseServices;
|
namespace Netina.Core.BaseServices;
|
||||||
|
|
||||||
|
@ -22,30 +14,54 @@ public class DashboardService : IDashboardService
|
||||||
}
|
}
|
||||||
public async Task<HomeDashboardDto> GetHomeDashboardAsyncTask(CancellationToken cancellationToken = default)
|
public async Task<HomeDashboardDto> GetHomeDashboardAsyncTask(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var response = new HomeDashboardDto();
|
var response = new HomeDashboardDto
|
||||||
response.BlogsCount = await _repositoryWrapper.SetRepository<Blog>()
|
{
|
||||||
|
BlogsCount = await _repositoryWrapper.SetRepository<Blog>()
|
||||||
.TableNoTracking
|
.TableNoTracking
|
||||||
.CountAsync(cancellationToken);
|
.CountAsync(cancellationToken),
|
||||||
|
ProductsCount = await _repositoryWrapper.SetRepository<Product>()
|
||||||
response.ProductsCount = await _repositoryWrapper.SetRepository<Product>()
|
|
||||||
.TableNoTracking
|
.TableNoTracking
|
||||||
.CountAsync(cancellationToken);
|
.CountAsync(cancellationToken),
|
||||||
|
TodayOrdersCount = await _repositoryWrapper.SetRepository<Order>()
|
||||||
response.TodayOrdersCount = await _repositoryWrapper.SetRepository<Order>()
|
|
||||||
.TableNoTracking
|
.TableNoTracking
|
||||||
.Where(o => o.OrderAt.Date == DateTime.Today.Date)
|
.Where(o => o.OrderAt.Date == DateTime.Today.Date)
|
||||||
.CountAsync(cancellationToken);
|
.CountAsync(cancellationToken),
|
||||||
|
UnSubmittedOrdersCount = await _repositoryWrapper.SetRepository<Order>()
|
||||||
response.UnSubmittedOrdersCount = await _repositoryWrapper.SetRepository<Order>()
|
|
||||||
.TableNoTracking
|
.TableNoTracking
|
||||||
.Where(o => o.OrderStatus == OrderStatus.Paid || o.OrderStatus == OrderStatus.Submitted)
|
.Where(o => o.OrderStatus == OrderStatus.Paid || o.OrderStatus == OrderStatus.Submitted)
|
||||||
.CountAsync(cancellationToken);
|
.CountAsync(cancellationToken),
|
||||||
|
BrandsCount = await _repositoryWrapper.SetRepository<Brand>()
|
||||||
response.BrandsCount = await _repositoryWrapper.SetRepository<Brand>()
|
|
||||||
.TableNoTracking
|
.TableNoTracking
|
||||||
.CountAsync(cancellationToken);
|
.CountAsync(cancellationToken),
|
||||||
|
SubscribersCount = await _userManager.Users.CountAsync(cancellationToken)
|
||||||
|
};
|
||||||
|
|
||||||
response.SubscribersCount = await _userManager.Users.CountAsync(cancellationToken);
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<OrderDashboardDto> GetOrdersDashboardAsyncTask(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
DateTime startOfThisMonth = new PersianDateTime(PersianDateTime.Today.Year, PersianDateTime.Today.Month, 1).ToDateTime();
|
||||||
|
DateTime endOfThisMonth = startOfThisMonth.AddMonths(1);
|
||||||
|
var response = new OrderDashboardDto
|
||||||
|
{
|
||||||
|
PayedOrdersCount = await _repositoryWrapper.SetRepository<Order>()
|
||||||
|
.TableNoTracking
|
||||||
|
.Where(o=>o.IsPayed && o.OrderStatus==OrderStatus.Paid)
|
||||||
|
.CountAsync(cancellationToken),
|
||||||
|
ThisMonthOrdersCount = await _repositoryWrapper.SetRepository<Order>()
|
||||||
|
.TableNoTracking
|
||||||
|
.Where(s => s.OrderAt.Date >= startOfThisMonth.Date && s.OrderAt.Date < endOfThisMonth.Date)
|
||||||
|
.CountAsync(cancellationToken),
|
||||||
|
TodayOrdersCount = await _repositoryWrapper.SetRepository<Order>()
|
||||||
|
.TableNoTracking
|
||||||
|
.Where(o => o.OrderAt.Date == DateTime.Now.Date)
|
||||||
|
.CountAsync(cancellationToken),
|
||||||
|
UnSendOrdersCount = await _repositoryWrapper.SetRepository<Order>()
|
||||||
|
.TableNoTracking
|
||||||
|
.Where(o => o.IsPayed && o.OrderStatus == OrderStatus.Processing)
|
||||||
|
.CountAsync(cancellationToken)
|
||||||
|
};
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,27 +5,58 @@ namespace Netina.Core.CoreServices.SearchServices;
|
||||||
public class GetTorobProductsQueryHandler : IRequestHandler<GetTorobProductsQuery, List<TorobProductResponseDto>>
|
public class GetTorobProductsQueryHandler : IRequestHandler<GetTorobProductsQuery, List<TorobProductResponseDto>>
|
||||||
{
|
{
|
||||||
private readonly IRepositoryWrapper _repositoryWrapper;
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
||||||
|
private readonly IMediator _mediator;
|
||||||
private readonly SiteSettings _siteSetting;
|
private readonly SiteSettings _siteSetting;
|
||||||
|
|
||||||
public GetTorobProductsQueryHandler(IRepositoryWrapper repositoryWrapper , IOptionsSnapshot<SiteSettings> optionsSnapshot)
|
public GetTorobProductsQueryHandler(IRepositoryWrapper repositoryWrapper, IMediator mediator, IOptionsSnapshot<SiteSettings> optionsSnapshot)
|
||||||
{
|
{
|
||||||
_repositoryWrapper = repositoryWrapper;
|
_repositoryWrapper = repositoryWrapper;
|
||||||
|
_mediator = mediator;
|
||||||
_siteSetting = optionsSnapshot.Value;
|
_siteSetting = optionsSnapshot.Value;
|
||||||
}
|
}
|
||||||
public async Task<List<TorobProductResponseDto>> Handle(GetTorobProductsQuery request, CancellationToken cancellationToken)
|
public async Task<List<TorobProductResponseDto>> Handle(GetTorobProductsQuery request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var products = await _repositoryWrapper.SetRepository<Product>()
|
var productsSDto = await _repositoryWrapper.SetRepository<Product>()
|
||||||
.TableNoTracking
|
.TableNoTracking
|
||||||
.OrderByDescending(p => p.ModifiedAt == DateTime.MinValue ? p.CreatedAt : p.ModifiedAt)
|
.OrderByDescending(p => p.ModifiedAt == DateTime.MinValue ? p.CreatedAt : p.ModifiedAt)
|
||||||
.Select(ProductMapper.ProjectToTorobResponseDto)
|
.Select(p => new ProductSDto
|
||||||
|
{
|
||||||
|
Id = p.Id,
|
||||||
|
BeDisplayed = p.BeDisplayed,
|
||||||
|
IsEnable = p.IsEnable,
|
||||||
|
Cost = p.Cost,
|
||||||
|
CategoryId = p.CategoryId,
|
||||||
|
BrandId = p.BrandId,
|
||||||
|
EnglishName = p.EnglishName,
|
||||||
|
PersianName = p.PersianName,
|
||||||
|
Slug = p.Slug,
|
||||||
|
|
||||||
|
})
|
||||||
.Skip(request.Page * 100)
|
.Skip(request.Page * 100)
|
||||||
.Take(100)
|
.Take(100)
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
products.ForEach(p =>
|
|
||||||
|
foreach (var productSDto in productsSDto)
|
||||||
|
await _mediator.Send(new CalculateProductDiscountCommand(productSDto), cancellationToken);
|
||||||
|
var products = new List<TorobProductResponseDto>();
|
||||||
|
foreach (var product in productsSDto)
|
||||||
{
|
{
|
||||||
p.page_url = $"{_siteSetting.WebSiteUrl}/products/{p.product_id}";
|
var torobProduct = new TorobProductResponseDto
|
||||||
});
|
{
|
||||||
|
availibility = product.IsEnable,
|
||||||
|
page_url = $"{_siteSetting.WebSiteUrl}/products/{product.Id}",
|
||||||
|
product_id = product.Id.ToString()
|
||||||
|
};
|
||||||
|
if (product.Cost > product.CostWithDiscount)
|
||||||
|
{
|
||||||
|
torobProduct.old_price = product.Cost;
|
||||||
|
torobProduct.price = product.CostWithDiscount;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
torobProduct.price = product.Cost;
|
||||||
|
products.Add(torobProduct);
|
||||||
|
}
|
||||||
|
|
||||||
return products;
|
return products;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,4 @@
|
||||||
using Netina.Common.Models.Exception;
|
namespace Netina.Core.EntityServices.DiscountHandlers;
|
||||||
using Netina.Domain.CommandQueries.Commands;
|
|
||||||
using Netina.Domain.Dtos.LargDtos;
|
|
||||||
using Netina.Domain.Dtos.SmallDtos;
|
|
||||||
using Netina.Domain.Entities.Discounts;
|
|
||||||
using Netina.Domain.Enums;
|
|
||||||
using Netina.Repository.Repositories.Base.Contracts;
|
|
||||||
|
|
||||||
namespace Netina.Core.EntityServices.DiscountHandlers;
|
|
||||||
|
|
||||||
public class CalculateProductDiscountCommandHandler : IRequestHandler<CalculateProductDiscountCommand, bool>
|
public class CalculateProductDiscountCommandHandler : IRequestHandler<CalculateProductDiscountCommand, bool>
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,9 +55,12 @@
|
||||||
<Using Include="Netina.Domain.CommandQueries.Commands" />
|
<Using Include="Netina.Domain.CommandQueries.Commands" />
|
||||||
<Using Include="Netina.Domain.CommandQueries.Queries" />
|
<Using Include="Netina.Domain.CommandQueries.Queries" />
|
||||||
<Using Include="Netina.Domain.Dtos.DashboardDtos" />
|
<Using Include="Netina.Domain.Dtos.DashboardDtos" />
|
||||||
|
<Using Include="Netina.Domain.Dtos.LargDtos" />
|
||||||
<Using Include="Netina.Domain.Dtos.RequestDtos" />
|
<Using Include="Netina.Domain.Dtos.RequestDtos" />
|
||||||
<Using Include="Netina.Domain.Dtos.ResponseDtos" />
|
<Using Include="Netina.Domain.Dtos.ResponseDtos" />
|
||||||
<Using Include="Netina.Domain.Dtos.SmallDtos" />
|
<Using Include="Netina.Domain.Dtos.SmallDtos" />
|
||||||
|
<Using Include="Netina.Domain.Entities.Blogs" />
|
||||||
|
<Using Include="Netina.Domain.Entities.Brands" />
|
||||||
<Using Include="Netina.Domain.Entities.Discounts" />
|
<Using Include="Netina.Domain.Entities.Discounts" />
|
||||||
<Using Include="Netina.Domain.Entities.Orders" />
|
<Using Include="Netina.Domain.Entities.Orders" />
|
||||||
<Using Include="Netina.Domain.Entities.Products" />
|
<Using Include="Netina.Domain.Entities.Products" />
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace Netina.Domain.Dtos.DashboardDtos;
|
||||||
|
|
||||||
|
public class OrderDashboardDto
|
||||||
|
{
|
||||||
|
public int TodayOrdersCount { get; set; }
|
||||||
|
public int ThisMonthOrdersCount { get; set; }
|
||||||
|
public int PayedOrdersCount { get; set; }
|
||||||
|
public int UnSendOrdersCount { get; set; }
|
||||||
|
}
|
|
@ -24,7 +24,7 @@ public class ProductSDto : BaseDto<ProductSDto, Product>
|
||||||
public int ReviewCount { get; set; }
|
public int ReviewCount { get; set; }
|
||||||
public int Viewed { get; set; }
|
public int Viewed { get; set; }
|
||||||
public string MainImage { get; set; } = string.Empty;
|
public string MainImage { get; set; } = string.Empty;
|
||||||
public Guid CategoryId { get; internal set; }
|
public Guid CategoryId { get; set; }
|
||||||
|
|
||||||
public Guid BrandId { get; set; }
|
public Guid BrandId { get; set; }
|
||||||
public string BrandName { get; set; } = string.Empty;
|
public string BrandName { get; set; } = string.Empty;
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Dtos\FilterDtos\" />
|
<Folder Include="Dtos\FilterDtos\" />
|
||||||
<Folder Include="Dtos\DashboardDtos\" />
|
|
||||||
<Folder Include="Entities\StorageFiles\" />
|
<Folder Include="Entities\StorageFiles\" />
|
||||||
<Folder Include="Models\Districts\" />
|
<Folder Include="Models\Districts\" />
|
||||||
<Folder Include="Models\Settings\" />
|
<Folder Include="Models\Settings\" />
|
||||||
|
|
Loading…
Reference in New Issue