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;
|
||||
|
||||
|
@ -60,6 +62,7 @@ public class BlogController : ICarterModule
|
|||
{
|
||||
ent.AddFile(file.Name, file.FileLocation, file.FileName, file.IsHeader, file.IsPrimary, file.FileType);
|
||||
}
|
||||
|
||||
repositoryWrapper.SetRepository<Blog>().Add(ent);
|
||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
return TypedResults.Ok(ent.AdaptToSDto());
|
||||
|
@ -76,6 +79,20 @@ public class BlogController : ICarterModule
|
|||
newEnt.Id = ent.Id;
|
||||
newEnt.CreatedAt = ent.CreatedAt;
|
||||
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);
|
||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
return TypedResults.Ok();
|
||||
|
|
|
@ -12,8 +12,16 @@ public class DashboardController : ICarterModule
|
|||
.WithDisplayName("Get Home Dashboard")
|
||||
.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)
|
||||
=> TypedResults.Ok(await dashboardService.GetHomeDashboardAsyncTask(cancellationToken));
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
using Netina.Common.Models;
|
||||
using Netina.Domain.Dtos.DashboardDtos;
|
||||
|
||||
namespace Netina.Core.BaseServices.Abstracts;
|
||||
namespace Netina.Core.BaseServices.Abstracts;
|
||||
|
||||
public interface IDashboardService : IScopedDependency
|
||||
{
|
||||
public Task<HomeDashboardDto> GetHomeDashboardAsyncTask(CancellationToken cancellationToken = default);
|
||||
public Task<OrderDashboardDto> GetOrdersDashboardAsyncTask(CancellationToken cancellationToken = default);
|
||||
}
|
|
@ -1,12 +1,4 @@
|
|||
using Netina.Core.BaseServices.Abstracts;
|
||||
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;
|
||||
using MD.PersianDateTime.Standard;
|
||||
|
||||
namespace Netina.Core.BaseServices;
|
||||
|
||||
|
@ -22,30 +14,54 @@ public class DashboardService : IDashboardService
|
|||
}
|
||||
public async Task<HomeDashboardDto> GetHomeDashboardAsyncTask(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var response = new HomeDashboardDto();
|
||||
response.BlogsCount = await _repositoryWrapper.SetRepository<Blog>()
|
||||
.TableNoTracking
|
||||
.CountAsync(cancellationToken);
|
||||
var response = new HomeDashboardDto
|
||||
{
|
||||
BlogsCount = await _repositoryWrapper.SetRepository<Blog>()
|
||||
.TableNoTracking
|
||||
.CountAsync(cancellationToken),
|
||||
ProductsCount = await _repositoryWrapper.SetRepository<Product>()
|
||||
.TableNoTracking
|
||||
.CountAsync(cancellationToken),
|
||||
TodayOrdersCount = await _repositoryWrapper.SetRepository<Order>()
|
||||
.TableNoTracking
|
||||
.Where(o => o.OrderAt.Date == DateTime.Today.Date)
|
||||
.CountAsync(cancellationToken),
|
||||
UnSubmittedOrdersCount = await _repositoryWrapper.SetRepository<Order>()
|
||||
.TableNoTracking
|
||||
.Where(o => o.OrderStatus == OrderStatus.Paid || o.OrderStatus == OrderStatus.Submitted)
|
||||
.CountAsync(cancellationToken),
|
||||
BrandsCount = await _repositoryWrapper.SetRepository<Brand>()
|
||||
.TableNoTracking
|
||||
.CountAsync(cancellationToken),
|
||||
SubscribersCount = await _userManager.Users.CountAsync(cancellationToken)
|
||||
};
|
||||
|
||||
response.ProductsCount = await _repositoryWrapper.SetRepository<Product>()
|
||||
.TableNoTracking
|
||||
.CountAsync(cancellationToken);
|
||||
return response;
|
||||
}
|
||||
|
||||
response.TodayOrdersCount = await _repositoryWrapper.SetRepository<Order>()
|
||||
.TableNoTracking
|
||||
.Where(o => o.OrderAt.Date == DateTime.Today.Date)
|
||||
.CountAsync(cancellationToken);
|
||||
|
||||
response.UnSubmittedOrdersCount = await _repositoryWrapper.SetRepository<Order>()
|
||||
.TableNoTracking
|
||||
.Where(o => o.OrderStatus == OrderStatus.Paid || o.OrderStatus == OrderStatus.Submitted)
|
||||
.CountAsync(cancellationToken);
|
||||
|
||||
response.BrandsCount = await _repositoryWrapper.SetRepository<Brand>()
|
||||
.TableNoTracking
|
||||
.CountAsync(cancellationToken);
|
||||
|
||||
response.SubscribersCount = await _userManager.Users.CountAsync(cancellationToken);
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -5,27 +5,58 @@ namespace Netina.Core.CoreServices.SearchServices;
|
|||
public class GetTorobProductsQueryHandler : IRequestHandler<GetTorobProductsQuery, List<TorobProductResponseDto>>
|
||||
{
|
||||
private readonly IRepositoryWrapper _repositoryWrapper;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly SiteSettings _siteSetting;
|
||||
|
||||
public GetTorobProductsQueryHandler(IRepositoryWrapper repositoryWrapper , IOptionsSnapshot<SiteSettings> optionsSnapshot)
|
||||
public GetTorobProductsQueryHandler(IRepositoryWrapper repositoryWrapper, IMediator mediator, IOptionsSnapshot<SiteSettings> optionsSnapshot)
|
||||
{
|
||||
_repositoryWrapper = repositoryWrapper;
|
||||
_mediator = mediator;
|
||||
_siteSetting = optionsSnapshot.Value;
|
||||
}
|
||||
public async Task<List<TorobProductResponseDto>> Handle(GetTorobProductsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var products = await _repositoryWrapper.SetRepository<Product>()
|
||||
var productsSDto = await _repositoryWrapper.SetRepository<Product>()
|
||||
.TableNoTracking
|
||||
.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)
|
||||
.Take(100)
|
||||
.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;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,4 @@
|
|||
using Netina.Common.Models.Exception;
|
||||
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;
|
||||
namespace Netina.Core.EntityServices.DiscountHandlers;
|
||||
|
||||
public class CalculateProductDiscountCommandHandler : IRequestHandler<CalculateProductDiscountCommand, bool>
|
||||
{
|
||||
|
|
|
@ -55,9 +55,12 @@
|
|||
<Using Include="Netina.Domain.CommandQueries.Commands" />
|
||||
<Using Include="Netina.Domain.CommandQueries.Queries" />
|
||||
<Using Include="Netina.Domain.Dtos.DashboardDtos" />
|
||||
<Using Include="Netina.Domain.Dtos.LargDtos" />
|
||||
<Using Include="Netina.Domain.Dtos.RequestDtos" />
|
||||
<Using Include="Netina.Domain.Dtos.ResponseDtos" />
|
||||
<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.Orders" />
|
||||
<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 Viewed { get; set; }
|
||||
public string MainImage { get; set; } = string.Empty;
|
||||
public Guid CategoryId { get; internal set; }
|
||||
public Guid CategoryId { get; set; }
|
||||
|
||||
public Guid BrandId { get; set; }
|
||||
public string BrandName { get; set; } = string.Empty;
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Folder Include="Dtos\FilterDtos\" />
|
||||
<Folder Include="Dtos\DashboardDtos\" />
|
||||
<Folder Include="Entities\StorageFiles\" />
|
||||
<Folder Include="Models\Districts\" />
|
||||
<Folder Include="Models\Settings\" />
|
||||
|
|
Loading…
Reference in New Issue