Commit af143ef3 authored by gdlcf88's avatar gdlcf88

Added history application services

parent cd6f6254
using System;
using Volo.Abp.Application.Dtos;
namespace EasyAbp.EShop.Products.ProductDetailHistories.Dtos
{
public class GetProductDetailHistoryListDto : PagedAndSortedResultRequestDto
{
public Guid ProductDetailId { get; set; }
}
}
\ No newline at end of file
using System;
using Volo.Abp.Application.Dtos;
namespace EasyAbp.EShop.Products.ProductDetailHistories.Dtos
{
public class ProductDetailHistoryDto : EntityDto<Guid>
{
public Guid ProductDetailId { get; set; }
public DateTime ModificationTime { get; set; }
public string SerializedDto { get; set; }
}
}
\ No newline at end of file
using System;
using System.Threading.Tasks;
using EasyAbp.EShop.Products.ProductDetailHistories.Dtos;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace EasyAbp.EShop.Products.ProductDetailHistories
{
public interface IProductDetailHistoryAppService :
ICrudAppService<
ProductDetailHistoryDto,
Guid,
GetProductDetailHistoryListDto,
object,
object>
{
Task<ProductDetailHistoryDto> GetByTimeAsync(Guid productId, DateTime modificationTime);
}
}
\ No newline at end of file
using System;
using Volo.Abp.Application.Dtos;
namespace EasyAbp.EShop.Products.ProductHistories.Dtos
{
public class GetProductHistoryListDto : PagedAndSortedResultRequestDto
{
public Guid ProductId { get; set; }
}
}
\ No newline at end of file
using System;
using Volo.Abp.Application.Dtos;
namespace EasyAbp.EShop.Products.ProductHistories.Dtos
{
public class ProductHistoryDto : EntityDto<Guid>
{
public Guid ProductId { get; set; }
public DateTime ModificationTime { get; set; }
public string SerializedDto { get; set; }
}
}
\ No newline at end of file
using System;
using System.Threading.Tasks;
using EasyAbp.EShop.Products.ProductHistories.Dtos;
using Volo.Abp.Application.Services;
namespace EasyAbp.EShop.Products.ProductHistories
{
public interface IProductHistoryAppService :
ICrudAppService<
ProductHistoryDto,
Guid,
GetProductHistoryListDto,
object,
object>
{
Task<ProductHistoryDto> GetByTimeAsync(Guid productId, DateTime modificationTime);
}
}
\ No newline at end of file
using System;
using System.Linq;
using System.Threading.Tasks;
using EasyAbp.EShop.Products.Authorization;
using EasyAbp.EShop.Products.ProductDetailHistories.Dtos;
using Volo.Abp;
using Volo.Abp.Application.Services;
namespace EasyAbp.EShop.Products.ProductDetailHistories
{
public class ProductDetailHistoryAppService : CrudAppService<ProductDetailHistory, ProductDetailHistoryDto, Guid, GetProductDetailHistoryListDto, object, object>,
IProductDetailHistoryAppService
{
protected override string GetListPolicyName { get; set; } = ProductsPermissions.Products.Default;
private readonly IProductDetailHistoryRepository _repository;
public ProductDetailHistoryAppService(IProductDetailHistoryRepository repository) : base(repository)
{
_repository = repository;
}
protected override IQueryable<ProductDetailHistory> CreateFilteredQuery(GetProductDetailHistoryListDto input)
{
return base.CreateFilteredQuery(input).Where(x => x.ProductDetailId == input.ProductDetailId);
}
public async Task<ProductDetailHistoryDto> GetByTimeAsync(Guid productId, DateTime modificationTime)
{
await CheckGetPolicyAsync();
return MapToGetOutputDto(await _repository.GetAsync(productId, modificationTime));
}
[RemoteService(false)]
public override Task<ProductDetailHistoryDto> CreateAsync(object input)
{
throw new NotImplementedException();
}
[RemoteService(false)]
public override Task<ProductDetailHistoryDto> UpdateAsync(Guid id, object input)
{
throw new NotImplementedException();
}
[RemoteService(false)]
public override Task DeleteAsync(Guid id)
{
throw new NotImplementedException();
}
}
}
\ No newline at end of file
using System;
using System.Linq;
using System.Threading.Tasks;
using EasyAbp.EShop.Products.Authorization;
using EasyAbp.EShop.Products.ProductHistories.Dtos;
using Volo.Abp;
using Volo.Abp.Application.Services;
namespace EasyAbp.EShop.Products.ProductHistories
{
public class ProductHistoryAppService : CrudAppService<ProductHistory, ProductHistoryDto, Guid, GetProductHistoryListDto, object, object>,
IProductHistoryAppService
{
protected override string GetListPolicyName { get; set; } = ProductsPermissions.Products.Default;
private readonly IProductHistoryRepository _repository;
public ProductHistoryAppService(IProductHistoryRepository repository) : base(repository)
{
_repository = repository;
}
protected override IQueryable<ProductHistory> CreateFilteredQuery(GetProductHistoryListDto input)
{
return base.CreateFilteredQuery(input).Where(x => x.ProductId == input.ProductId);
}
public async Task<ProductHistoryDto> GetByTimeAsync(Guid productId, DateTime modificationTime)
{
await CheckGetPolicyAsync();
return MapToGetOutputDto(await _repository.GetAsync(productId, modificationTime));
}
[RemoteService(false)]
public override Task<ProductHistoryDto> CreateAsync(object input)
{
throw new NotImplementedException();
}
[RemoteService(false)]
public override Task<ProductHistoryDto> UpdateAsync(Guid id, object input)
{
throw new NotImplementedException();
}
[RemoteService(false)]
public override Task DeleteAsync(Guid id)
{
throw new NotImplementedException();
}
}
}
\ No newline at end of file
...@@ -10,6 +10,9 @@ using AutoMapper; ...@@ -10,6 +10,9 @@ using AutoMapper;
using EasyAbp.EShop.Products.ProductDetails; using EasyAbp.EShop.Products.ProductDetails;
using EasyAbp.EShop.Products.ProductDetails.Dtos; using EasyAbp.EShop.Products.ProductDetails.Dtos;
using EasyAbp.EShop.Products.ProductDetailHistories; using EasyAbp.EShop.Products.ProductDetailHistories;
using EasyAbp.EShop.Products.ProductDetailHistories.Dtos;
using EasyAbp.EShop.Products.ProductHistories;
using EasyAbp.EShop.Products.ProductHistories.Dtos;
using Volo.Abp.AutoMapper; using Volo.Abp.AutoMapper;
namespace EasyAbp.EShop.Products namespace EasyAbp.EShop.Products
...@@ -44,6 +47,8 @@ namespace EasyAbp.EShop.Products ...@@ -44,6 +47,8 @@ namespace EasyAbp.EShop.Products
CreateMap<CreateUpdateProductTypeDto, ProductType>(MemberList.Source); CreateMap<CreateUpdateProductTypeDto, ProductType>(MemberList.Source);
CreateMap<ProductCategory, ProductCategoryDto>(); CreateMap<ProductCategory, ProductCategoryDto>();
CreateMap<CreateUpdateProductCategoryDto, ProductCategory>(MemberList.Source); CreateMap<CreateUpdateProductCategoryDto, ProductCategory>(MemberList.Source);
CreateMap<ProductHistory, ProductHistoryDto>();
CreateMap<ProductDetailHistory, ProductDetailHistoryDto>();
} }
} }
} }
using System; using System;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
namespace EasyAbp.EShop.Products.ProductDetailHistories namespace EasyAbp.EShop.Products.ProductDetailHistories
{ {
public interface IProductDetailHistoryRepository : IRepository<ProductDetailHistory, Guid> public interface IProductDetailHistoryRepository : IRepository<ProductDetailHistory, Guid>
{ {
Task<ProductDetailHistory> GetAsync(Guid productDetailId, DateTime modificationTime,
CancellationToken cancellationToken = default);
} }
} }
\ No newline at end of file
using System; using System;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
namespace EasyAbp.EShop.Products.ProductHistories namespace EasyAbp.EShop.Products.ProductHistories
{ {
public interface IProductHistoryRepository : IRepository<ProductHistory, Guid> public interface IProductHistoryRepository : IRepository<ProductHistory, Guid>
{ {
Task<ProductHistory> GetAsync(Guid productId, DateTime modificationTime,
CancellationToken cancellationToken = default);
} }
} }
\ No newline at end of file
...@@ -118,6 +118,8 @@ namespace EasyAbp.EShop.Products.EntityFrameworkCore ...@@ -118,6 +118,8 @@ namespace EasyAbp.EShop.Products.EntityFrameworkCore
b.ToTable(options.TablePrefix + "ProductHistories", options.Schema); b.ToTable(options.TablePrefix + "ProductHistories", options.Schema);
b.ConfigureByConvention(); b.ConfigureByConvention();
/* Configure more properties here */ /* Configure more properties here */
b.HasIndex(x => x.ProductId);
b.HasIndex(x => x.ModificationTime);
}); });
builder.Entity<ProductDetailHistory>(b => builder.Entity<ProductDetailHistory>(b =>
...@@ -125,6 +127,8 @@ namespace EasyAbp.EShop.Products.EntityFrameworkCore ...@@ -125,6 +127,8 @@ namespace EasyAbp.EShop.Products.EntityFrameworkCore
b.ToTable(options.TablePrefix + "ProductDetailHistories", options.Schema); b.ToTable(options.TablePrefix + "ProductDetailHistories", options.Schema);
b.ConfigureByConvention(); b.ConfigureByConvention();
/* Configure more properties here */ /* Configure more properties here */
b.HasIndex(x => x.ProductDetailId);
b.HasIndex(x => x.ModificationTime);
}); });
} }
} }
......
using System; using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using EasyAbp.EShop.Products.EntityFrameworkCore; using EasyAbp.EShop.Products.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
...@@ -10,5 +15,19 @@ namespace EasyAbp.EShop.Products.ProductDetailHistories ...@@ -10,5 +15,19 @@ namespace EasyAbp.EShop.Products.ProductDetailHistories
public ProductDetailHistoryRepository(IDbContextProvider<ProductsDbContext> dbContextProvider) : base(dbContextProvider) public ProductDetailHistoryRepository(IDbContextProvider<ProductsDbContext> dbContextProvider) : base(dbContextProvider)
{ {
} }
public async Task<ProductDetailHistory> GetAsync(Guid productDetailId, DateTime modificationTime, CancellationToken cancellationToken = default)
{
var entity = await GetQueryable()
.Where(x => x.ModificationTime == modificationTime && x.ProductDetailId == productDetailId)
.FirstOrDefaultAsync(cancellationToken);
if (entity == null)
{
throw new EntityNotFoundException(typeof(ProductDetailHistory), new {productDetailId, modificationTime});
}
return entity;
}
} }
} }
\ No newline at end of file
using System; using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using EasyAbp.EShop.Products.EntityFrameworkCore; using EasyAbp.EShop.Products.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
...@@ -10,5 +15,19 @@ namespace EasyAbp.EShop.Products.ProductHistories ...@@ -10,5 +15,19 @@ namespace EasyAbp.EShop.Products.ProductHistories
public ProductHistoryRepository(IDbContextProvider<ProductsDbContext> dbContextProvider) : base(dbContextProvider) public ProductHistoryRepository(IDbContextProvider<ProductsDbContext> dbContextProvider) : base(dbContextProvider)
{ {
} }
public async Task<ProductHistory> GetAsync(Guid productId, DateTime modificationTime, CancellationToken cancellationToken = default)
{
var entity = await GetQueryable()
.Where(x => x.ModificationTime == modificationTime && x.ProductId == productId)
.FirstOrDefaultAsync(cancellationToken);
if (entity == null)
{
throw new EntityNotFoundException(typeof(ProductHistory), new {productId, modificationTime});
}
return entity;
}
} }
} }
\ No newline at end of file
using Microsoft.EntityFrameworkCore.Migrations;
namespace EasyMall.Migrations
{
public partial class AddedHistoryEntityIndexes : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_ProductsProductHistories_ModificationTime",
table: "ProductsProductHistories",
column: "ModificationTime");
migrationBuilder.CreateIndex(
name: "IX_ProductsProductHistories_ProductId",
table: "ProductsProductHistories",
column: "ProductId");
migrationBuilder.CreateIndex(
name: "IX_ProductsProductDetailHistories_ModificationTime",
table: "ProductsProductDetailHistories",
column: "ModificationTime");
migrationBuilder.CreateIndex(
name: "IX_ProductsProductDetailHistories_ProductDetailId",
table: "ProductsProductDetailHistories",
column: "ProductDetailId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_ProductsProductHistories_ModificationTime",
table: "ProductsProductHistories");
migrationBuilder.DropIndex(
name: "IX_ProductsProductHistories_ProductId",
table: "ProductsProductHistories");
migrationBuilder.DropIndex(
name: "IX_ProductsProductDetailHistories_ModificationTime",
table: "ProductsProductDetailHistories");
migrationBuilder.DropIndex(
name: "IX_ProductsProductDetailHistories_ProductDetailId",
table: "ProductsProductDetailHistories");
}
}
}
...@@ -163,6 +163,10 @@ namespace EasyMall.Migrations ...@@ -163,6 +163,10 @@ namespace EasyMall.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ModificationTime");
b.HasIndex("ProductDetailId");
b.ToTable("ProductsProductDetailHistories"); b.ToTable("ProductsProductDetailHistories");
}); });
...@@ -245,6 +249,10 @@ namespace EasyMall.Migrations ...@@ -245,6 +249,10 @@ namespace EasyMall.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ModificationTime");
b.HasIndex("ProductId");
b.ToTable("ProductsProductHistories"); b.ToTable("ProductsProductHistories");
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment