Change to comment PHASE A
parent
28ffed532d
commit
6bd9066f8d
|
@ -1,50 +1,50 @@
|
||||||
namespace Netina.Api.Controllers;
|
namespace Netina.Api.Controllers;
|
||||||
|
|
||||||
public class ProductReviewController : ICarterModule
|
public class ProductCommentController : ICarterModule
|
||||||
{
|
{
|
||||||
public void AddRoutes(IEndpointRouteBuilder app)
|
public void AddRoutes(IEndpointRouteBuilder app)
|
||||||
{
|
{
|
||||||
var group = app.NewVersionedApi("ProductReview")
|
var group = app.NewVersionedApi("ProductComment")
|
||||||
.MapGroup("api/product/review");
|
.MapGroup("api/product/comment");
|
||||||
|
|
||||||
group.MapGet("{id}", GetAsync)
|
group.MapGet("{id}", GetAsync)
|
||||||
.WithDisplayName("Get Product Review")
|
.WithDisplayName("Get Product Comment")
|
||||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ViewAllReviews,ApplicationPermission.ManageReview))
|
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ViewAllReviews,ApplicationPermission.ManageReview))
|
||||||
.HasApiVersion(1.0);
|
.HasApiVersion(1.0);
|
||||||
|
|
||||||
group.MapGet("", GetAllAsync)
|
group.MapGet("", GetAllAsync)
|
||||||
.WithDisplayName("Get Product Reviews")
|
.WithDisplayName("Get Product Comments")
|
||||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ViewAllReviews, ApplicationPermission.ManageReview))
|
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ViewAllReviews, ApplicationPermission.ManageReview))
|
||||||
.HasApiVersion(1.0);
|
.HasApiVersion(1.0);
|
||||||
|
|
||||||
group.MapPost("", PostAsync)
|
group.MapPost("", PostAsync)
|
||||||
.WithDisplayName("Create Product Review")
|
.WithDisplayName("Create Product Comment")
|
||||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser())
|
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser())
|
||||||
.HasApiVersion(1.0);
|
.HasApiVersion(1.0);
|
||||||
|
|
||||||
group.MapPut("confirm/{id}", ConfirmAsync)
|
group.MapPut("confirm/{id}", ConfirmAsync)
|
||||||
.WithDisplayName("Confirm Product Review")
|
.WithDisplayName("Confirm Product Comment")
|
||||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ConfirmReview, ApplicationPermission.ManageReview))
|
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ConfirmReview, ApplicationPermission.ManageReview))
|
||||||
.HasApiVersion(1.0);
|
.HasApiVersion(1.0);
|
||||||
|
|
||||||
group.MapDelete("{id}", DeleteAsync)
|
group.MapDelete("{id}", DeleteAsync)
|
||||||
.WithDisplayName("Delete Product Review")
|
.WithDisplayName("Delete Product Comment")
|
||||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageReview))
|
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageReview))
|
||||||
.HasApiVersion(1.0);
|
.HasApiVersion(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IResult> GetAllAsync([FromQuery] int page, IMediator mediator, CancellationToken cancellationToken)
|
public async Task<IResult> GetAllAsync([FromQuery] int page, IMediator mediator, CancellationToken cancellationToken)
|
||||||
=> TypedResults.Ok(await mediator.Send(new GetReviewsQuery(page), cancellationToken));
|
=> TypedResults.Ok(await mediator.Send(new GetCommentsQuery(page), cancellationToken));
|
||||||
|
|
||||||
public async Task<IResult> GetAsync(Guid id, IMediator mediator, CancellationToken cancellationToken)
|
public async Task<IResult> GetAsync(Guid id, IMediator mediator, CancellationToken cancellationToken)
|
||||||
=> TypedResults.Ok(await mediator.Send(new GetReviewQuery(id), cancellationToken));
|
=> TypedResults.Ok(await mediator.Send(new GetCommentQuery(id), cancellationToken));
|
||||||
|
|
||||||
public async Task<IResult> PostAsync(CreateReviewCommand request, IMediator mediator, CancellationToken cancellationToken)
|
public async Task<IResult> PostAsync(CreateCommentCommand request, IMediator mediator, CancellationToken cancellationToken)
|
||||||
=> TypedResults.Ok(await mediator.Send(request, cancellationToken));
|
=> TypedResults.Ok(await mediator.Send(request, cancellationToken));
|
||||||
|
|
||||||
public async Task<IResult> ConfirmAsync(Guid id, IMediator mediator, CancellationToken cancellationToken)
|
public async Task<IResult> ConfirmAsync(Guid id, IMediator mediator, CancellationToken cancellationToken)
|
||||||
=> TypedResults.Ok(await mediator.Send(new ConfirmReviewCommand(id), cancellationToken));
|
=> TypedResults.Ok(await mediator.Send(new ConfirmCommentCommand(id), cancellationToken));
|
||||||
|
|
||||||
public async Task<IResult> DeleteAsync(Guid id, IMediator mediator, CancellationToken cancellationToken)
|
public async Task<IResult> DeleteAsync(Guid id, IMediator mediator, CancellationToken cancellationToken)
|
||||||
=> TypedResults.Ok(await mediator.Send(new DeleteReviewCommand(id), cancellationToken));
|
=> TypedResults.Ok(await mediator.Send(new DeleteCommentCommand(id), cancellationToken));
|
||||||
}
|
}
|
|
@ -38,7 +38,7 @@ public class ProductController : ICarterModule
|
||||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageProducts))
|
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageProducts))
|
||||||
.HasApiVersion(1.0);
|
.HasApiVersion(1.0);
|
||||||
|
|
||||||
group.MapGet("{productId}/review",GetProductReviewsAsync)
|
group.MapGet("{productId}/comment",GetProductCommentsAsync)
|
||||||
.WithDisplayName("Get Product Reviews")
|
.WithDisplayName("Get Product Reviews")
|
||||||
.HasApiVersion(1.0);
|
.HasApiVersion(1.0);
|
||||||
|
|
||||||
|
@ -48,8 +48,8 @@ public class ProductController : ICarterModule
|
||||||
.HasApiVersion(1.0);
|
.HasApiVersion(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IResult> GetProductReviewsAsync([FromQuery] int page, [FromRoute] Guid productId, IMediator mediator, CancellationToken cancellationToken)
|
private async Task<IResult> GetProductCommentsAsync([FromQuery] int page, [FromQuery]int count, [FromRoute] Guid productId, IMediator mediator, CancellationToken cancellationToken)
|
||||||
=> TypedResults.Ok(await mediator.Send(new GetReviewsQuery(page, productId), cancellationToken));
|
=> TypedResults.Ok(await mediator.Send(new GetCommentsQuery(page, count, productId), cancellationToken));
|
||||||
|
|
||||||
// GET:Get All Entity
|
// GET:Get All Entity
|
||||||
public async Task<IResult> GetAllAsync([FromQuery] int page,
|
public async Task<IResult> GetAllAsync([FromQuery] int page,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
|
||||||
|
|
||||||
|
namespace Netina.Core.BaseServices;
|
||||||
|
|
||||||
public class SettingService(IMartenRepositoryWrapper martenRepositoryWrapper) : ISettingService
|
public class SettingService(IMartenRepositoryWrapper martenRepositoryWrapper) : ISettingService
|
||||||
{
|
{
|
||||||
public async Task<object> GetSettingAsync(string settingName, CancellationToken cancellationToken = default)
|
public async Task<object> GetSettingAsync(string settingName, CancellationToken cancellationToken = default)
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
using Netina.Domain.Entities.Comments;
|
||||||
|
|
||||||
|
namespace Netina.Core.EntityServices.CommentHandlers;
|
||||||
|
|
||||||
|
public class ConfirmCommentCommandHandler(IRepositoryWrapper repositoryWrapper)
|
||||||
|
: IRequestHandler<ConfirmCommentCommand, Guid>
|
||||||
|
{
|
||||||
|
public async Task<Guid> Handle(ConfirmCommentCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var review = await repositoryWrapper.SetRepository<Comment>().TableNoTracking
|
||||||
|
.FirstOrDefaultAsync(r => r.Id == request.Id, cancellationToken);
|
||||||
|
if (review == null)
|
||||||
|
throw new AppException("Comment not found", ApiResultStatusCode.NotFound);
|
||||||
|
review.ConfirmReview();
|
||||||
|
|
||||||
|
var productComment = await repositoryWrapper.SetRepository<ProductComment>()
|
||||||
|
.TableNoTracking.FirstOrDefaultAsync(f => f.Id == request.Id, cancellationToken);
|
||||||
|
if (productComment != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
var product = await repositoryWrapper.SetRepository<Product>()
|
||||||
|
.TableNoTracking
|
||||||
|
.FirstOrDefaultAsync(p => p.Id == productComment.ProductId, cancellationToken);
|
||||||
|
if (product == null)
|
||||||
|
throw new AppException("Product not found", ApiResultStatusCode.NotFound);
|
||||||
|
|
||||||
|
product.AddRate(productComment.Rate);
|
||||||
|
|
||||||
|
repositoryWrapper.SetRepository<Product>().Update(product);
|
||||||
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
repositoryWrapper.SetRepository<Comment>().Update(review);
|
||||||
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||||
|
return review.Id;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,20 +0,0 @@
|
||||||
using Review = Netina.Domain.Entities.Reviews.Review;
|
|
||||||
|
|
||||||
namespace Netina.Core.EntityServices.ReviewHandlers;
|
|
||||||
|
|
||||||
public class ConfirmReviewCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
||||||
: IRequestHandler<ConfirmReviewCommand, Guid>
|
|
||||||
{
|
|
||||||
public async Task<Guid> Handle(ConfirmReviewCommand request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var review = await repositoryWrapper.SetRepository<Review>().TableNoTracking
|
|
||||||
.FirstOrDefaultAsync(r => r.Id == request.Id, cancellationToken);
|
|
||||||
if (review == null)
|
|
||||||
throw new AppException("Review not found", ApiResultStatusCode.NotFound);
|
|
||||||
review.ConfirmReview();
|
|
||||||
|
|
||||||
repositoryWrapper.SetRepository<Review>().Update(review);
|
|
||||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
||||||
return review.Id;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -26,7 +26,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="CoreServices\WebSiteServices\" />
|
<Folder Include="CoreServices\WebSiteServices\" />
|
||||||
<Folder Include="EntityServices\ProductHandlers\" />
|
<Folder Include="EntityServices\ProductHandlers\" />
|
||||||
<Folder Include="EntityServices\ReviewHandlers\" />
|
|
||||||
<Folder Include="Models\Api\" />
|
<Folder Include="Models\Api\" />
|
||||||
<Folder Include="Models\Scraper\" />
|
<Folder Include="Models\Scraper\" />
|
||||||
<Folder Include="Utilities\" />
|
<Folder Include="Utilities\" />
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
namespace Netina.Domain.CommandQueries.Commands;
|
||||||
|
|
||||||
|
public sealed record CreateCommentCommand(
|
||||||
|
string Title,
|
||||||
|
string Content,
|
||||||
|
float Rate,
|
||||||
|
bool IsBuyer,
|
||||||
|
bool IsAdmin,
|
||||||
|
Guid? ParentId,
|
||||||
|
Guid? BlogId = null,
|
||||||
|
Guid? ProductId = null,
|
||||||
|
Guid? UserId = null) : IRequest<Guid>;
|
||||||
|
|
||||||
|
public sealed record UpdateCommentCommand(
|
||||||
|
Guid Id,
|
||||||
|
string Title,
|
||||||
|
string Content,
|
||||||
|
float Rate,
|
||||||
|
bool IsBuyer,
|
||||||
|
bool IsAdmin,
|
||||||
|
Guid? ParentId,
|
||||||
|
Guid? BlogId = null,
|
||||||
|
Guid? ProductId = null,
|
||||||
|
Guid? UserId = null) : IRequest<Guid>;
|
||||||
|
|
||||||
|
public sealed record ConfirmCommentCommand(Guid Id) : IRequest<Guid>;
|
||||||
|
public sealed record DeleteCommentCommand(Guid Id) : IRequest<Guid>;
|
|
@ -1,6 +0,0 @@
|
||||||
namespace Netina.Domain.CommandQueries.Commands;
|
|
||||||
|
|
||||||
public sealed record CreateReviewCommand(string Title, string Comment, float Rate, bool IsBuyer,bool IsAdmin, Guid ProductId, Guid UserId) : IRequest<Guid>;
|
|
||||||
public sealed record UpdateReviewCommand(Guid Id,string Title, string Comment, float Rate, bool IsBuyer, bool IsAdmin, Guid ProductId, Guid UserId): IRequest<Guid>;
|
|
||||||
public sealed record ConfirmReviewCommand(Guid Id) : IRequest<Guid>;
|
|
||||||
public sealed record DeleteReviewCommand(Guid Id) : IRequest<Guid>;
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
namespace Netina.Domain.CommandQueries.Queries;
|
||||||
|
|
||||||
|
public record GetCommentsQuery(int Page = 0,int Count = Refers.SizeM ,Guid? ProductId = null, Guid? BlogId = null) : IRequest<List<CommentSDto>>;
|
||||||
|
public record GetCommentQuery(Guid Id) : IRequest<CommentLDto>;
|
|
@ -1,4 +0,0 @@
|
||||||
namespace Netina.Domain.CommandQueries.Queries;
|
|
||||||
|
|
||||||
public record GetReviewsQuery(int Page = 0,Guid? ProductId = null) : IRequest<List<ReviewSDto>>;
|
|
||||||
public record GetReviewQuery(Guid Id) : IRequest<ReviewLDto>;
|
|
|
@ -1,14 +1,19 @@
|
||||||
using Review = Netina.Domain.Entities.Reviews.Review;
|
using Netina.Domain.Entities.Comments;
|
||||||
|
|
||||||
namespace Netina.Domain.Dtos.LargDtos;
|
namespace Netina.Domain.Dtos.LargDtos;
|
||||||
|
|
||||||
public class ReviewLDto : BaseDto<ReviewLDto,Review>
|
public class CommentLDto : BaseDto<CommentLDto,Comment>
|
||||||
{
|
{
|
||||||
public string Title { get; set; } = string.Empty;
|
public string Title { get; set; } = string.Empty;
|
||||||
public string Comment { get; set; } = string.Empty;
|
public string Comment { get; set; } = string.Empty;
|
||||||
public float Rate { get; set; }
|
public float Rate { get; set; }
|
||||||
public bool IsBuyer { get; set; }
|
public bool IsBuyer { get; set; }
|
||||||
public bool IsConfirmed { get; set; }
|
public bool IsConfirmed { get; set; }
|
||||||
public Guid ProductId { get; set; }
|
public Guid ParentId { get; set; }
|
||||||
public Guid UserId { get; set; }
|
public Guid UserId { get; set; }
|
||||||
|
|
||||||
|
public string UserFullName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[AdaptIgnore]
|
||||||
|
public List<CommentSDto> Children { get; set; } = new();
|
||||||
}
|
}
|
|
@ -27,7 +27,7 @@ public class ProductLDto : BaseDto<ProductLDto,Product>
|
||||||
public bool IsSpecialOffer { get; set; }
|
public bool IsSpecialOffer { get; set; }
|
||||||
|
|
||||||
public List<SpecificationSDto> Specifications { get; set; } = new();
|
public List<SpecificationSDto> Specifications { get; set; } = new();
|
||||||
public List<ReviewSDto> Reviews { get; set; } = new();
|
public List<CommentSDto> Reviews { get; set; } = new();
|
||||||
public List<StorageFileSDto> Files { get; set; } = new();
|
public List<StorageFileSDto> Files { get; set; } = new();
|
||||||
|
|
||||||
public DiscountSDto? SpecialOffer { get; set; }
|
public DiscountSDto? SpecialOffer { get; set; }
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
using Netina.Domain.Entities.Comments;
|
||||||
|
|
||||||
|
namespace Netina.Domain.Dtos.SmallDtos;
|
||||||
|
|
||||||
|
public class CommentSDto : BaseDto<CommentSDto, Comment>
|
||||||
|
{
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
public string Content { get; set; } = string.Empty;
|
||||||
|
public string FullName { get; set; } = string.Empty;
|
||||||
|
public string Email { get; set; } = string.Empty;
|
||||||
|
public string PhoneNumber { get; set; } = string.Empty;
|
||||||
|
public bool IsConfirmed { get; set; }
|
||||||
|
public Guid ParentId { get; set; }
|
||||||
|
public Guid UserId { get; set; }
|
||||||
|
|
||||||
|
public string UserFullName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[AdaptIgnore]
|
||||||
|
public List<CommentSDto> Children { get; set; } = new();
|
||||||
|
}
|
|
@ -1,14 +0,0 @@
|
||||||
using Review = Netina.Domain.Entities.Reviews.Review;
|
|
||||||
|
|
||||||
namespace Netina.Domain.Dtos.SmallDtos;
|
|
||||||
|
|
||||||
public class ReviewSDto : BaseDto<ReviewSDto, Review>
|
|
||||||
{
|
|
||||||
public string Title { get; set; } = string.Empty;
|
|
||||||
public string Comment { get; set; } = string.Empty;
|
|
||||||
public float Rate { get; set; }
|
|
||||||
public bool IsBuyer { get; set; }
|
|
||||||
public bool IsAdmin { get; set; }
|
|
||||||
public Guid ProductId { get; set; }
|
|
||||||
public Guid UserId { get; set; }
|
|
||||||
}
|
|
|
@ -30,6 +30,11 @@ public partial class BlogStorageFile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public partial class BlogComment
|
||||||
|
{
|
||||||
|
public static BlogComment Create(string title, string content, float rate, bool isAdmin, Guid userId, Guid blogId)
|
||||||
|
=> new(title, content, rate, isAdmin, userId, blogId);
|
||||||
|
}
|
||||||
public partial class BlogCategory
|
public partial class BlogCategory
|
||||||
{
|
{
|
||||||
public static BlogCategory Create(string name, string description, bool isMain)
|
public static BlogCategory Create(string name, string description, bool isMain)
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
using Netina.Domain.Entities.Comments;
|
||||||
|
|
||||||
|
namespace Netina.Domain.Entities.Blogs;
|
||||||
|
|
||||||
|
public partial class BlogComment : Comment
|
||||||
|
{
|
||||||
|
public BlogComment()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlogComment(string title, string content, float rate, bool isAdmin, Guid userId, Guid blogId)
|
||||||
|
: base(title, content, rate, isAdmin, userId)
|
||||||
|
{
|
||||||
|
BlogId = blogId;
|
||||||
|
}
|
||||||
|
public Guid BlogId { get; internal set; }
|
||||||
|
public Blog? Blog { get; internal set; }
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
namespace Netina.Domain.Entities.Comments;
|
||||||
|
|
||||||
|
public partial class Comment
|
||||||
|
{
|
||||||
|
public static Comment Create(string title, string content, float rate,bool isAdmin, Guid userId)
|
||||||
|
{
|
||||||
|
return new Comment(title, content, rate,isAdmin, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ConfirmReview()
|
||||||
|
=> IsConfirmed = true;
|
||||||
|
|
||||||
|
public void SetParent(Guid parentId)
|
||||||
|
{
|
||||||
|
ParentId = parentId;
|
||||||
|
IsRoot = false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,34 +1,35 @@
|
||||||
namespace Netina.Domain.Entities.Reviews;
|
namespace Netina.Domain.Entities.Comments;
|
||||||
[AdaptTwoWays("[name]LDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)]
|
[AdaptTwoWays("[name]LDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)]
|
||||||
[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget)]
|
[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget)]
|
||||||
[AdaptTo("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Projection)]
|
[AdaptTo("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Projection)]
|
||||||
[GenerateMapper]
|
[GenerateMapper]
|
||||||
public partial class Review : ApiEntity
|
public partial class Comment : ApiEntity
|
||||||
{
|
{
|
||||||
public Review()
|
public Comment()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Review(string title, string comment, float rate, bool isBuyer,bool isAdmin, Guid productId, Guid userId)
|
public Comment(string title, string content, float rate, bool isAdmin, Guid userId)
|
||||||
{
|
{
|
||||||
Title = title;
|
Title = title;
|
||||||
Comment = comment;
|
Content = content;
|
||||||
Rate = rate;
|
Rate = rate;
|
||||||
IsBuyer = isBuyer;
|
|
||||||
IsAdmin = isAdmin;
|
IsAdmin = isAdmin;
|
||||||
ProductId = productId;
|
IsRoot = true;
|
||||||
UserId = userId;
|
UserId = userId;
|
||||||
}
|
}
|
||||||
public string Title { get; internal set; } = string.Empty;
|
public string Title { get; internal set; } = string.Empty;
|
||||||
public string Comment { get; internal set; } = string.Empty;
|
public string Content { get; internal set; } = string.Empty;
|
||||||
public float Rate { get; internal set; }
|
public float Rate { get; internal set; }
|
||||||
public bool IsBuyer { get; internal set; }
|
|
||||||
public bool IsConfirmed { get; internal set; }
|
public bool IsConfirmed { get; internal set; }
|
||||||
public bool IsAdmin { get; internal set; }
|
public bool IsAdmin { get; internal set; }
|
||||||
|
public bool IsRoot { get; internal set; }
|
||||||
|
public Guid? ParentId { get; internal set; }
|
||||||
|
public Comment? Parent { get; internal set; }
|
||||||
|
|
||||||
public Guid ProductId { get; internal set; }
|
|
||||||
public Product? Product { get; internal set; }
|
public List<Comment> Children { get; internal set; } = new();
|
||||||
|
|
||||||
public Guid UserId { get; internal set; }
|
public Guid UserId { get; internal set; }
|
||||||
public ApplicationUser? User { get; internal set; }
|
public ApplicationUser? User { get; internal set; }
|
|
@ -60,6 +60,12 @@ public partial class Product
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public partial class ProductComment
|
||||||
|
{
|
||||||
|
public static ProductComment Create(string title, string content, float rate, bool isBuyer, bool isAdmin, Guid userId, Guid productId)
|
||||||
|
=> new(title, content, rate, isBuyer, isAdmin, userId, productId);
|
||||||
|
}
|
||||||
|
|
||||||
public partial class ProductStorageFile
|
public partial class ProductStorageFile
|
||||||
{
|
{
|
||||||
public static ProductStorageFile Create(string name, string fileLocation, string fileName, bool isHeader,
|
public static ProductStorageFile Create(string name, string fileLocation, string fileName, bool isHeader,
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
namespace Netina.Domain.Entities.Products;
|
using Netina.Domain.Entities.Comments;
|
||||||
|
|
||||||
|
namespace Netina.Domain.Entities.Products;
|
||||||
|
|
||||||
[AdaptTwoWays("[name]LDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)]
|
[AdaptTwoWays("[name]LDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget | MapType.Projection)]
|
||||||
[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget )]
|
[AdaptTwoWays("[name]SDto", IgnoreAttributes = new[] { typeof(AdaptIgnoreAttribute) }, MapType = MapType.Map | MapType.MapToTarget )]
|
||||||
|
@ -80,7 +82,7 @@ public partial class Product : ApiEntity
|
||||||
public ProductCategory? Category { get; internal set; }
|
public ProductCategory? Category { get; internal set; }
|
||||||
|
|
||||||
public List<Specification> Specifications { get; internal set; } = new();
|
public List<Specification> Specifications { get; internal set; } = new();
|
||||||
public List<Reviews.Review> Reviews { get; internal set; } = new();
|
public List<Comment> Reviews { get; internal set; } = new();
|
||||||
public List<ProductStorageFile> Files { get; internal set; } = new();
|
public List<ProductStorageFile> Files { get; internal set; } = new();
|
||||||
|
|
||||||
public List<OrderProduct> OrderProducts { get; internal set; } = new();
|
public List<OrderProduct> OrderProducts { get; internal set; } = new();
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
using Netina.Domain.Entities.Comments;
|
||||||
|
|
||||||
|
namespace Netina.Domain.Entities.Products;
|
||||||
|
|
||||||
|
public partial class ProductComment : Comment
|
||||||
|
{
|
||||||
|
public ProductComment()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProductComment(string title, string content, float rate, bool isBuyer, bool isAdmin, Guid userId, Guid productId)
|
||||||
|
: base(title, content, rate, isAdmin, userId)
|
||||||
|
{
|
||||||
|
ProductId = productId;
|
||||||
|
IsBuyer = isBuyer;
|
||||||
|
}
|
||||||
|
public bool IsBuyer { get; internal set; }
|
||||||
|
public Guid ProductId { get; internal set; }
|
||||||
|
public Product? Product { get; internal set; }
|
||||||
|
}
|
|
@ -1,12 +0,0 @@
|
||||||
namespace Netina.Domain.Entities.Reviews;
|
|
||||||
|
|
||||||
public partial class Review
|
|
||||||
{
|
|
||||||
public static Reviews.Review Create(string title, string comment, float rate, bool isBuyer,bool isAdmin, Guid productId, Guid userId)
|
|
||||||
{
|
|
||||||
return new Reviews.Review(title, comment, rate, isBuyer,isAdmin, productId, userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ConfirmReview()
|
|
||||||
=> IsConfirmed = true;
|
|
||||||
}
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace Netina.Domain.Mappers
|
||||||
|
{
|
||||||
|
public static partial class BlogCommentMapper
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,184 +2,162 @@ using System;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using Netina.Domain.Dtos.LargDtos;
|
using Netina.Domain.Dtos.LargDtos;
|
||||||
using Netina.Domain.Dtos.SmallDtos;
|
using Netina.Domain.Dtos.SmallDtos;
|
||||||
using Netina.Domain.Entities.Reviews;
|
using Netina.Domain.Entities.Comments;
|
||||||
|
|
||||||
namespace Netina.Domain.Mappers
|
namespace Netina.Domain.Mappers
|
||||||
{
|
{
|
||||||
public static partial class ReviewMapper
|
public static partial class CommentMapper
|
||||||
{
|
{
|
||||||
public static Review AdaptToReview(this ReviewLDto p1)
|
public static Comment AdaptToComment(this CommentLDto p1)
|
||||||
{
|
{
|
||||||
return p1 == null ? null : new Review()
|
return p1 == null ? null : new Comment()
|
||||||
{
|
{
|
||||||
Title = p1.Title,
|
Title = p1.Title,
|
||||||
Comment = p1.Comment,
|
|
||||||
Rate = p1.Rate,
|
Rate = p1.Rate,
|
||||||
IsBuyer = p1.IsBuyer,
|
|
||||||
IsConfirmed = p1.IsConfirmed,
|
IsConfirmed = p1.IsConfirmed,
|
||||||
ProductId = p1.ProductId,
|
ParentId = (Guid?)p1.ParentId,
|
||||||
UserId = p1.UserId,
|
UserId = p1.UserId,
|
||||||
Id = p1.Id,
|
Id = p1.Id,
|
||||||
CreatedAt = p1.CreatedAt
|
CreatedAt = p1.CreatedAt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static Review AdaptTo(this ReviewLDto p2, Review p3)
|
public static Comment AdaptTo(this CommentLDto p2, Comment p3)
|
||||||
{
|
{
|
||||||
if (p2 == null)
|
if (p2 == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Review result = p3 ?? new Review();
|
Comment result = p3 ?? new Comment();
|
||||||
|
|
||||||
result.Title = p2.Title;
|
result.Title = p2.Title;
|
||||||
result.Comment = p2.Comment;
|
|
||||||
result.Rate = p2.Rate;
|
result.Rate = p2.Rate;
|
||||||
result.IsBuyer = p2.IsBuyer;
|
|
||||||
result.IsConfirmed = p2.IsConfirmed;
|
result.IsConfirmed = p2.IsConfirmed;
|
||||||
result.ProductId = p2.ProductId;
|
result.ParentId = (Guid?)p2.ParentId;
|
||||||
result.UserId = p2.UserId;
|
result.UserId = p2.UserId;
|
||||||
result.Id = p2.Id;
|
result.Id = p2.Id;
|
||||||
result.CreatedAt = p2.CreatedAt;
|
result.CreatedAt = p2.CreatedAt;
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
public static Expression<Func<ReviewLDto, Review>> ProjectToReview => p4 => new Review()
|
public static Expression<Func<CommentLDto, Comment>> ProjectToComment => p4 => new Comment()
|
||||||
{
|
{
|
||||||
Title = p4.Title,
|
Title = p4.Title,
|
||||||
Comment = p4.Comment,
|
|
||||||
Rate = p4.Rate,
|
Rate = p4.Rate,
|
||||||
IsBuyer = p4.IsBuyer,
|
|
||||||
IsConfirmed = p4.IsConfirmed,
|
IsConfirmed = p4.IsConfirmed,
|
||||||
ProductId = p4.ProductId,
|
ParentId = (Guid?)p4.ParentId,
|
||||||
UserId = p4.UserId,
|
UserId = p4.UserId,
|
||||||
Id = p4.Id,
|
Id = p4.Id,
|
||||||
CreatedAt = p4.CreatedAt
|
CreatedAt = p4.CreatedAt
|
||||||
};
|
};
|
||||||
public static ReviewLDto AdaptToLDto(this Review p5)
|
public static CommentLDto AdaptToLDto(this Comment p5)
|
||||||
{
|
{
|
||||||
return p5 == null ? null : new ReviewLDto()
|
return p5 == null ? null : new CommentLDto()
|
||||||
{
|
{
|
||||||
Title = p5.Title,
|
Title = p5.Title,
|
||||||
Comment = p5.Comment,
|
|
||||||
Rate = p5.Rate,
|
Rate = p5.Rate,
|
||||||
IsBuyer = p5.IsBuyer,
|
|
||||||
IsConfirmed = p5.IsConfirmed,
|
IsConfirmed = p5.IsConfirmed,
|
||||||
ProductId = p5.ProductId,
|
ParentId = p5.ParentId == null ? default(Guid) : (Guid)p5.ParentId,
|
||||||
UserId = p5.UserId,
|
UserId = p5.UserId,
|
||||||
Id = p5.Id,
|
Id = p5.Id,
|
||||||
CreatedAt = p5.CreatedAt
|
CreatedAt = p5.CreatedAt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static ReviewLDto AdaptTo(this Review p6, ReviewLDto p7)
|
public static CommentLDto AdaptTo(this Comment p6, CommentLDto p7)
|
||||||
{
|
{
|
||||||
if (p6 == null)
|
if (p6 == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ReviewLDto result = p7 ?? new ReviewLDto();
|
CommentLDto result = p7 ?? new CommentLDto();
|
||||||
|
|
||||||
result.Title = p6.Title;
|
result.Title = p6.Title;
|
||||||
result.Comment = p6.Comment;
|
|
||||||
result.Rate = p6.Rate;
|
result.Rate = p6.Rate;
|
||||||
result.IsBuyer = p6.IsBuyer;
|
|
||||||
result.IsConfirmed = p6.IsConfirmed;
|
result.IsConfirmed = p6.IsConfirmed;
|
||||||
result.ProductId = p6.ProductId;
|
result.ParentId = p6.ParentId == null ? default(Guid) : (Guid)p6.ParentId;
|
||||||
result.UserId = p6.UserId;
|
result.UserId = p6.UserId;
|
||||||
result.Id = p6.Id;
|
result.Id = p6.Id;
|
||||||
result.CreatedAt = p6.CreatedAt;
|
result.CreatedAt = p6.CreatedAt;
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
public static Expression<Func<Review, ReviewLDto>> ProjectToLDto => p8 => new ReviewLDto()
|
public static Expression<Func<Comment, CommentLDto>> ProjectToLDto => p8 => new CommentLDto()
|
||||||
{
|
{
|
||||||
Title = p8.Title,
|
Title = p8.Title,
|
||||||
Comment = p8.Comment,
|
|
||||||
Rate = p8.Rate,
|
Rate = p8.Rate,
|
||||||
IsBuyer = p8.IsBuyer,
|
|
||||||
IsConfirmed = p8.IsConfirmed,
|
IsConfirmed = p8.IsConfirmed,
|
||||||
ProductId = p8.ProductId,
|
ParentId = p8.ParentId == null ? default(Guid) : (Guid)p8.ParentId,
|
||||||
UserId = p8.UserId,
|
UserId = p8.UserId,
|
||||||
Id = p8.Id,
|
Id = p8.Id,
|
||||||
CreatedAt = p8.CreatedAt
|
CreatedAt = p8.CreatedAt
|
||||||
};
|
};
|
||||||
public static Review AdaptToReview(this ReviewSDto p9)
|
public static Comment AdaptToComment(this CommentSDto p9)
|
||||||
{
|
{
|
||||||
return p9 == null ? null : new Review()
|
return p9 == null ? null : new Comment()
|
||||||
{
|
{
|
||||||
Title = p9.Title,
|
Title = p9.Title,
|
||||||
Comment = p9.Comment,
|
Content = p9.Content,
|
||||||
Rate = p9.Rate,
|
IsConfirmed = p9.IsConfirmed,
|
||||||
IsBuyer = p9.IsBuyer,
|
ParentId = (Guid?)p9.ParentId,
|
||||||
IsAdmin = p9.IsAdmin,
|
|
||||||
ProductId = p9.ProductId,
|
|
||||||
UserId = p9.UserId,
|
UserId = p9.UserId,
|
||||||
Id = p9.Id,
|
Id = p9.Id,
|
||||||
CreatedAt = p9.CreatedAt
|
CreatedAt = p9.CreatedAt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static Review AdaptTo(this ReviewSDto p10, Review p11)
|
public static Comment AdaptTo(this CommentSDto p10, Comment p11)
|
||||||
{
|
{
|
||||||
if (p10 == null)
|
if (p10 == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Review result = p11 ?? new Review();
|
Comment result = p11 ?? new Comment();
|
||||||
|
|
||||||
result.Title = p10.Title;
|
result.Title = p10.Title;
|
||||||
result.Comment = p10.Comment;
|
result.Content = p10.Content;
|
||||||
result.Rate = p10.Rate;
|
result.IsConfirmed = p10.IsConfirmed;
|
||||||
result.IsBuyer = p10.IsBuyer;
|
result.ParentId = (Guid?)p10.ParentId;
|
||||||
result.IsAdmin = p10.IsAdmin;
|
|
||||||
result.ProductId = p10.ProductId;
|
|
||||||
result.UserId = p10.UserId;
|
result.UserId = p10.UserId;
|
||||||
result.Id = p10.Id;
|
result.Id = p10.Id;
|
||||||
result.CreatedAt = p10.CreatedAt;
|
result.CreatedAt = p10.CreatedAt;
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
public static ReviewSDto AdaptToSDto(this Review p12)
|
public static CommentSDto AdaptToSDto(this Comment p12)
|
||||||
{
|
{
|
||||||
return p12 == null ? null : new ReviewSDto()
|
return p12 == null ? null : new CommentSDto()
|
||||||
{
|
{
|
||||||
Title = p12.Title,
|
Title = p12.Title,
|
||||||
Comment = p12.Comment,
|
Content = p12.Content,
|
||||||
Rate = p12.Rate,
|
IsConfirmed = p12.IsConfirmed,
|
||||||
IsBuyer = p12.IsBuyer,
|
ParentId = p12.ParentId == null ? default(Guid) : (Guid)p12.ParentId,
|
||||||
IsAdmin = p12.IsAdmin,
|
|
||||||
ProductId = p12.ProductId,
|
|
||||||
UserId = p12.UserId,
|
UserId = p12.UserId,
|
||||||
Id = p12.Id,
|
Id = p12.Id,
|
||||||
CreatedAt = p12.CreatedAt
|
CreatedAt = p12.CreatedAt
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static ReviewSDto AdaptTo(this Review p13, ReviewSDto p14)
|
public static CommentSDto AdaptTo(this Comment p13, CommentSDto p14)
|
||||||
{
|
{
|
||||||
if (p13 == null)
|
if (p13 == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ReviewSDto result = p14 ?? new ReviewSDto();
|
CommentSDto result = p14 ?? new CommentSDto();
|
||||||
|
|
||||||
result.Title = p13.Title;
|
result.Title = p13.Title;
|
||||||
result.Comment = p13.Comment;
|
result.Content = p13.Content;
|
||||||
result.Rate = p13.Rate;
|
result.IsConfirmed = p13.IsConfirmed;
|
||||||
result.IsBuyer = p13.IsBuyer;
|
result.ParentId = p13.ParentId == null ? default(Guid) : (Guid)p13.ParentId;
|
||||||
result.IsAdmin = p13.IsAdmin;
|
|
||||||
result.ProductId = p13.ProductId;
|
|
||||||
result.UserId = p13.UserId;
|
result.UserId = p13.UserId;
|
||||||
result.Id = p13.Id;
|
result.Id = p13.Id;
|
||||||
result.CreatedAt = p13.CreatedAt;
|
result.CreatedAt = p13.CreatedAt;
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
public static Expression<Func<Review, ReviewSDto>> ProjectToSDto => p15 => new ReviewSDto()
|
public static Expression<Func<Comment, CommentSDto>> ProjectToSDto => p15 => new CommentSDto()
|
||||||
{
|
{
|
||||||
Title = p15.Title,
|
Title = p15.Title,
|
||||||
Comment = p15.Comment,
|
Content = p15.Content,
|
||||||
Rate = p15.Rate,
|
IsConfirmed = p15.IsConfirmed,
|
||||||
IsBuyer = p15.IsBuyer,
|
ParentId = p15.ParentId == null ? default(Guid) : (Guid)p15.ParentId,
|
||||||
IsAdmin = p15.IsAdmin,
|
|
||||||
ProductId = p15.ProductId,
|
|
||||||
UserId = p15.UserId,
|
UserId = p15.UserId,
|
||||||
Id = p15.Id,
|
Id = p15.Id,
|
||||||
CreatedAt = p15.CreatedAt
|
CreatedAt = p15.CreatedAt
|
|
@ -0,0 +1,6 @@
|
||||||
|
namespace Netina.Domain.Mappers
|
||||||
|
{
|
||||||
|
public static partial class ProductCommentMapper
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,9 +7,9 @@ using Netina.Domain.Dtos.LargDtos;
|
||||||
using Netina.Domain.Dtos.ResponseDtos.Torob;
|
using Netina.Domain.Dtos.ResponseDtos.Torob;
|
||||||
using Netina.Domain.Dtos.SmallDtos;
|
using Netina.Domain.Dtos.SmallDtos;
|
||||||
using Netina.Domain.Entities.Brands;
|
using Netina.Domain.Entities.Brands;
|
||||||
|
using Netina.Domain.Entities.Comments;
|
||||||
using Netina.Domain.Entities.ProductCategories;
|
using Netina.Domain.Entities.ProductCategories;
|
||||||
using Netina.Domain.Entities.Products;
|
using Netina.Domain.Entities.Products;
|
||||||
using Netina.Domain.Entities.Reviews;
|
|
||||||
using Netina.Domain.Entities.Users;
|
using Netina.Domain.Entities.Users;
|
||||||
|
|
||||||
namespace Netina.Domain.Mappers
|
namespace Netina.Domain.Mappers
|
||||||
|
@ -121,18 +121,16 @@ namespace Netina.Domain.Mappers
|
||||||
Id = p20.Id,
|
Id = p20.Id,
|
||||||
CreatedAt = p20.CreatedAt
|
CreatedAt = p20.CreatedAt
|
||||||
}).ToList<Specification>(),
|
}).ToList<Specification>(),
|
||||||
Reviews = p19.Reviews.Select<ReviewSDto, Review>(p21 => new Review()
|
Reviews = p19.Reviews.Select<CommentSDto, Comment>(p21 => new Comment()
|
||||||
{
|
{
|
||||||
Title = p21.Title,
|
Title = p21.Title,
|
||||||
Comment = p21.Comment,
|
Content = p21.Content,
|
||||||
Rate = p21.Rate,
|
IsConfirmed = p21.IsConfirmed,
|
||||||
IsBuyer = p21.IsBuyer,
|
ParentId = (Guid?)p21.ParentId,
|
||||||
IsAdmin = p21.IsAdmin,
|
|
||||||
ProductId = p21.ProductId,
|
|
||||||
UserId = p21.UserId,
|
UserId = p21.UserId,
|
||||||
Id = p21.Id,
|
Id = p21.Id,
|
||||||
CreatedAt = p21.CreatedAt
|
CreatedAt = p21.CreatedAt
|
||||||
}).ToList<Review>(),
|
}).ToList<Comment>(),
|
||||||
Files = p19.Files.Select<StorageFileSDto, ProductStorageFile>(p22 => new ProductStorageFile()
|
Files = p19.Files.Select<StorageFileSDto, ProductStorageFile>(p22 => new ProductStorageFile()
|
||||||
{
|
{
|
||||||
Name = p22.Name,
|
Name = p22.Name,
|
||||||
|
@ -242,18 +240,16 @@ namespace Netina.Domain.Mappers
|
||||||
Id = p36.Id,
|
Id = p36.Id,
|
||||||
CreatedAt = p36.CreatedAt
|
CreatedAt = p36.CreatedAt
|
||||||
}).ToList<SpecificationSDto>(),
|
}).ToList<SpecificationSDto>(),
|
||||||
Reviews = p35.Reviews.Select<Review, ReviewSDto>(p37 => new ReviewSDto()
|
Reviews = p35.Reviews.Select<Comment, CommentSDto>(p37 => new CommentSDto()
|
||||||
{
|
{
|
||||||
Title = p37.Title,
|
Title = p37.Title,
|
||||||
Comment = p37.Comment,
|
Content = p37.Content,
|
||||||
Rate = p37.Rate,
|
IsConfirmed = p37.IsConfirmed,
|
||||||
IsBuyer = p37.IsBuyer,
|
ParentId = p37.ParentId == null ? default(Guid) : (Guid)p37.ParentId,
|
||||||
IsAdmin = p37.IsAdmin,
|
|
||||||
ProductId = p37.ProductId,
|
|
||||||
UserId = p37.UserId,
|
UserId = p37.UserId,
|
||||||
Id = p37.Id,
|
Id = p37.Id,
|
||||||
CreatedAt = p37.CreatedAt
|
CreatedAt = p37.CreatedAt
|
||||||
}).ToList<ReviewSDto>(),
|
}).ToList<CommentSDto>(),
|
||||||
Files = p35.Files.Select<ProductStorageFile, StorageFileSDto>(p38 => new StorageFileSDto()
|
Files = p35.Files.Select<ProductStorageFile, StorageFileSDto>(p38 => new StorageFileSDto()
|
||||||
{
|
{
|
||||||
Name = p38.Name,
|
Name = p38.Name,
|
||||||
|
@ -476,28 +472,26 @@ namespace Netina.Domain.Mappers
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Review> funcMain2(List<ReviewSDto> p3)
|
private static List<Comment> funcMain2(List<CommentSDto> p3)
|
||||||
{
|
{
|
||||||
if (p3 == null)
|
if (p3 == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<Review> result = new List<Review>(p3.Count);
|
List<Comment> result = new List<Comment>(p3.Count);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int len = p3.Count;
|
int len = p3.Count;
|
||||||
|
|
||||||
while (i < len)
|
while (i < len)
|
||||||
{
|
{
|
||||||
ReviewSDto item = p3[i];
|
CommentSDto item = p3[i];
|
||||||
result.Add(item == null ? null : new Review()
|
result.Add(item == null ? null : new Comment()
|
||||||
{
|
{
|
||||||
Title = item.Title,
|
Title = item.Title,
|
||||||
Comment = item.Comment,
|
Content = item.Content,
|
||||||
Rate = item.Rate,
|
IsConfirmed = item.IsConfirmed,
|
||||||
IsBuyer = item.IsBuyer,
|
ParentId = (Guid?)item.ParentId,
|
||||||
IsAdmin = item.IsAdmin,
|
|
||||||
ProductId = item.ProductId,
|
|
||||||
UserId = item.UserId,
|
UserId = item.UserId,
|
||||||
Id = item.Id,
|
Id = item.Id,
|
||||||
CreatedAt = item.CreatedAt
|
CreatedAt = item.CreatedAt
|
||||||
|
@ -598,28 +592,26 @@ namespace Netina.Domain.Mappers
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Review> funcMain8(List<ReviewSDto> p15, List<Review> p16)
|
private static List<Comment> funcMain8(List<CommentSDto> p15, List<Comment> p16)
|
||||||
{
|
{
|
||||||
if (p15 == null)
|
if (p15 == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<Review> result = new List<Review>(p15.Count);
|
List<Comment> result = new List<Comment>(p15.Count);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int len = p15.Count;
|
int len = p15.Count;
|
||||||
|
|
||||||
while (i < len)
|
while (i < len)
|
||||||
{
|
{
|
||||||
ReviewSDto item = p15[i];
|
CommentSDto item = p15[i];
|
||||||
result.Add(item == null ? null : new Review()
|
result.Add(item == null ? null : new Comment()
|
||||||
{
|
{
|
||||||
Title = item.Title,
|
Title = item.Title,
|
||||||
Comment = item.Comment,
|
Content = item.Content,
|
||||||
Rate = item.Rate,
|
IsConfirmed = item.IsConfirmed,
|
||||||
IsBuyer = item.IsBuyer,
|
ParentId = (Guid?)item.ParentId,
|
||||||
IsAdmin = item.IsAdmin,
|
|
||||||
ProductId = item.ProductId,
|
|
||||||
UserId = item.UserId,
|
UserId = item.UserId,
|
||||||
Id = item.Id,
|
Id = item.Id,
|
||||||
CreatedAt = item.CreatedAt
|
CreatedAt = item.CreatedAt
|
||||||
|
@ -692,28 +684,26 @@ namespace Netina.Domain.Mappers
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ReviewSDto> funcMain11(List<Review> p25)
|
private static List<CommentSDto> funcMain11(List<Comment> p25)
|
||||||
{
|
{
|
||||||
if (p25 == null)
|
if (p25 == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<ReviewSDto> result = new List<ReviewSDto>(p25.Count);
|
List<CommentSDto> result = new List<CommentSDto>(p25.Count);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int len = p25.Count;
|
int len = p25.Count;
|
||||||
|
|
||||||
while (i < len)
|
while (i < len)
|
||||||
{
|
{
|
||||||
Review item = p25[i];
|
Comment item = p25[i];
|
||||||
result.Add(item == null ? null : new ReviewSDto()
|
result.Add(item == null ? null : new CommentSDto()
|
||||||
{
|
{
|
||||||
Title = item.Title,
|
Title = item.Title,
|
||||||
Comment = item.Comment,
|
Content = item.Content,
|
||||||
Rate = item.Rate,
|
IsConfirmed = item.IsConfirmed,
|
||||||
IsBuyer = item.IsBuyer,
|
ParentId = item.ParentId == null ? default(Guid) : (Guid)item.ParentId,
|
||||||
IsAdmin = item.IsAdmin,
|
|
||||||
ProductId = item.ProductId,
|
|
||||||
UserId = item.UserId,
|
UserId = item.UserId,
|
||||||
Id = item.Id,
|
Id = item.Id,
|
||||||
CreatedAt = item.CreatedAt
|
CreatedAt = item.CreatedAt
|
||||||
|
@ -785,28 +775,26 @@ namespace Netina.Domain.Mappers
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<ReviewSDto> funcMain14(List<Review> p31, List<ReviewSDto> p32)
|
private static List<CommentSDto> funcMain14(List<Comment> p31, List<CommentSDto> p32)
|
||||||
{
|
{
|
||||||
if (p31 == null)
|
if (p31 == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<ReviewSDto> result = new List<ReviewSDto>(p31.Count);
|
List<CommentSDto> result = new List<CommentSDto>(p31.Count);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int len = p31.Count;
|
int len = p31.Count;
|
||||||
|
|
||||||
while (i < len)
|
while (i < len)
|
||||||
{
|
{
|
||||||
Review item = p31[i];
|
Comment item = p31[i];
|
||||||
result.Add(item == null ? null : new ReviewSDto()
|
result.Add(item == null ? null : new CommentSDto()
|
||||||
{
|
{
|
||||||
Title = item.Title,
|
Title = item.Title,
|
||||||
Comment = item.Comment,
|
Content = item.Content,
|
||||||
Rate = item.Rate,
|
IsConfirmed = item.IsConfirmed,
|
||||||
IsBuyer = item.IsBuyer,
|
ParentId = item.ParentId == null ? default(Guid) : (Guid)item.ParentId,
|
||||||
IsAdmin = item.IsAdmin,
|
|
||||||
ProductId = item.ProductId,
|
|
||||||
UserId = item.UserId,
|
UserId = item.UserId,
|
||||||
Id = item.Id,
|
Id = item.Id,
|
||||||
CreatedAt = item.CreatedAt
|
CreatedAt = item.CreatedAt
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
namespace Netina.Domain.Models;
|
||||||
|
|
||||||
|
public static class Refers
|
||||||
|
{
|
||||||
|
public const int SizeS = 10;
|
||||||
|
public const int SizeM = 15;
|
||||||
|
public const int SizeL = 20;
|
||||||
|
}
|
|
@ -82,6 +82,7 @@
|
||||||
<Using Include="Netina.Domain.Enums" />
|
<Using Include="Netina.Domain.Enums" />
|
||||||
<Using Include="Netina.Domain.MartenEntities.Faqs" />
|
<Using Include="Netina.Domain.MartenEntities.Faqs" />
|
||||||
<Using Include="Netina.Domain.MartenEntities.Settings" />
|
<Using Include="Netina.Domain.MartenEntities.Settings" />
|
||||||
|
<Using Include="Netina.Domain.Models" />
|
||||||
<Using Include="System.ComponentModel.DataAnnotations" />
|
<Using Include="System.ComponentModel.DataAnnotations" />
|
||||||
<Using Include="System.Diagnostics" />
|
<Using Include="System.Diagnostics" />
|
||||||
<Using Include="System.Reflection" />
|
<Using Include="System.Reflection" />
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
using AppException = Netina.Common.Models.Exception.AppException;
|
||||||
|
|
||||||
|
namespace Netina.Repository.Handlers.Comments;
|
||||||
|
|
||||||
|
public class CreateCommentCommandHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
|
||||||
|
: IRequestHandler<CreateCommentCommand, Guid>
|
||||||
|
{
|
||||||
|
public async Task<Guid> Handle(CreateCommentCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
Guid userId;
|
||||||
|
if (request.UserId == null)
|
||||||
|
{
|
||||||
|
if (!Guid.TryParse(currentUserService.UserId, out userId))
|
||||||
|
throw new AppException("User id is wrong", ApiResultStatusCode.BadRequest);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
userId = request.UserId.Value;
|
||||||
|
|
||||||
|
if (request.BlogId != null)
|
||||||
|
{
|
||||||
|
var entBlog = BlogComment.Create(request.Title, request.Content, request.Rate, request.IsAdmin, userId,
|
||||||
|
request.BlogId.Value);
|
||||||
|
|
||||||
|
if (request.ParentId != null)
|
||||||
|
entBlog.SetParent(request.ParentId.Value);
|
||||||
|
repositoryWrapper.SetRepository<BlogComment>().Add(entBlog);
|
||||||
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||||
|
return entBlog.Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.ProductId != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
var entBlog = ProductComment.Create(request.Title, request.Content, request.Rate, request.IsBuyer,
|
||||||
|
request.IsAdmin, userId, request.ProductId.Value);
|
||||||
|
if (request.ParentId != null)
|
||||||
|
entBlog.SetParent(request.ParentId.Value);
|
||||||
|
|
||||||
|
repositoryWrapper.SetRepository<ProductComment>().Add(entBlog);
|
||||||
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||||
|
return entBlog.Id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var ent = Comment.Create(request.Title, request.Content, request.Rate, request.IsAdmin, userId);
|
||||||
|
if (request.ParentId != null)
|
||||||
|
ent.SetParent(request.ParentId.Value);
|
||||||
|
repositoryWrapper.SetRepository<Comment>().Add(ent);
|
||||||
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||||
|
return ent.Id;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
namespace Netina.Repository.Handlers.Comments;
|
||||||
|
|
||||||
|
public class DeleteCommentCommandHandler(IRepositoryWrapper repositoryWrapper)
|
||||||
|
: IRequestHandler<DeleteCommentCommand, Guid>
|
||||||
|
{
|
||||||
|
public async Task<Guid> Handle(DeleteCommentCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var review = await repositoryWrapper.SetRepository<Comment>().TableNoTracking
|
||||||
|
.FirstOrDefaultAsync(r => r.Id == request.Id, cancellationToken);
|
||||||
|
if (review == null)
|
||||||
|
throw new AppException("Comment not found", ApiResultStatusCode.NotFound);
|
||||||
|
|
||||||
|
if (review.IsConfirmed)
|
||||||
|
{
|
||||||
|
var productComment = await repositoryWrapper.SetRepository<ProductComment>()
|
||||||
|
.TableNoTracking.FirstOrDefaultAsync(f => f.Id == request.Id, cancellationToken);
|
||||||
|
if (productComment != null)
|
||||||
|
{
|
||||||
|
var product = await repositoryWrapper.SetRepository<Product>()
|
||||||
|
.TableNoTracking
|
||||||
|
.FirstOrDefaultAsync(p => p.Id == productComment.ProductId, cancellationToken);
|
||||||
|
if (product != null)
|
||||||
|
{
|
||||||
|
product.RemoveRate(review.Rate);
|
||||||
|
repositoryWrapper.SetRepository<Product>().Update(product);
|
||||||
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositoryWrapper.SetRepository<Comment>().Delete(review);
|
||||||
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||||
|
return review.Id;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
using Netina.Domain.Entities.Comments;
|
||||||
|
|
||||||
|
namespace Netina.Repository.Handlers.Comments;
|
||||||
|
|
||||||
|
public class GetCommentQueryHandler(IRepositoryWrapper repositoryWrapper) : IRequestHandler<GetCommentQuery, CommentLDto>
|
||||||
|
{
|
||||||
|
public async Task<CommentLDto> Handle(GetCommentQuery request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var review = await repositoryWrapper.SetRepository<Comment>()
|
||||||
|
.TableNoTracking
|
||||||
|
.Where(r => r.Id == request.Id)
|
||||||
|
.Select(CommentMapper.ProjectToLDto)
|
||||||
|
.FirstOrDefaultAsync(cancellationToken);
|
||||||
|
if (review == null)
|
||||||
|
throw new AppException("Comment not found", ApiResultStatusCode.NotFound);
|
||||||
|
|
||||||
|
return review;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
namespace Netina.Repository.Handlers.Comments;
|
||||||
|
|
||||||
|
public class GetCommentsQueryHandler(IRepositoryWrapper repositoryWrapper)
|
||||||
|
: IRequestHandler<GetCommentsQuery, List<CommentSDto>>
|
||||||
|
{
|
||||||
|
public async Task<List<CommentSDto>> Handle(GetCommentsQuery request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var count = request.Count == 0 ? Refers.SizeL : request.Count;
|
||||||
|
if (count > 50)
|
||||||
|
throw new BaseApiException(ApiResultStatusCode.BadRequest, "Count limit is 50");
|
||||||
|
|
||||||
|
if (request.BlogId != null)
|
||||||
|
{
|
||||||
|
var blogQuery = repositoryWrapper.SetRepository<BlogComment>().TableNoTracking
|
||||||
|
.Where(b => b.IsRoot && b.BlogId == request.BlogId)
|
||||||
|
.Skip(request.Page * count)
|
||||||
|
.Take(count)
|
||||||
|
.Select(CommentMapper.ProjectToSDto);
|
||||||
|
var blogRoots = await blogQuery.ToListAsync(cancellationToken);
|
||||||
|
foreach (var root in blogRoots)
|
||||||
|
await LoadChildrenAsync(root, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.ProductId != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
var blogQuery = repositoryWrapper.SetRepository<ProductComment>().TableNoTracking
|
||||||
|
.Where(b => b.IsRoot && b.ProductId == request.ProductId)
|
||||||
|
.Skip(request.Page * count)
|
||||||
|
.Take(count)
|
||||||
|
.Select(CommentMapper.ProjectToSDto);
|
||||||
|
var blogRoots = await blogQuery.ToListAsync(cancellationToken);
|
||||||
|
foreach (var root in blogRoots)
|
||||||
|
await LoadChildrenAsync(root, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
var query = repositoryWrapper.SetRepository<Comment>().TableNoTracking
|
||||||
|
.Where(b => b.IsRoot)
|
||||||
|
.Skip(request.Page * count)
|
||||||
|
.Take(count)
|
||||||
|
.Select(CommentMapper.ProjectToSDto);
|
||||||
|
var roots = await query.ToListAsync(cancellationToken);
|
||||||
|
foreach (var root in roots)
|
||||||
|
await LoadChildrenAsync(root, cancellationToken);
|
||||||
|
|
||||||
|
return roots;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LoadChildrenAsync(CommentSDto comment, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var children = await repositoryWrapper.SetRepository<Comment>()
|
||||||
|
.TableNoTracking
|
||||||
|
.Where(c => c.ParentId == comment.Id)
|
||||||
|
.Select(CommentMapper.ProjectToSDto)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
foreach (var blogComment in children)
|
||||||
|
await LoadChildrenAsync(blogComment, cancellationToken);
|
||||||
|
|
||||||
|
comment.Children = children;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,17 @@
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Netina.Repository.Handlers.Reviews.Validators;
|
namespace Netina.Repository.Handlers.Comments.Validators;
|
||||||
|
|
||||||
public class CreateReviewCommandValidator : AbstractValidator<CreateReviewCommand>
|
public class CreateCommentCommandValidator : AbstractValidator<CreateCommentCommand>
|
||||||
{
|
{
|
||||||
public CreateReviewCommandValidator()
|
public CreateCommentCommandValidator()
|
||||||
{
|
{
|
||||||
RuleFor(d => d.Title)
|
RuleFor(d => d.Title)
|
||||||
.NotNull()
|
.NotNull()
|
||||||
.NotEmpty()
|
.NotEmpty()
|
||||||
.WithMessage("عنوان نظر مورد نظر را وارد کنید");
|
.WithMessage("عنوان نظر مورد نظر را وارد کنید");
|
||||||
|
|
||||||
RuleFor(d => d.Comment)
|
RuleFor(d => d.Content)
|
||||||
.NotNull()
|
.NotNull()
|
||||||
.NotEmpty()
|
.NotEmpty()
|
||||||
.WithMessage("متن نظر مورد نظر را وارد کنید");
|
.WithMessage("متن نظر مورد نظر را وارد کنید");
|
|
@ -1,17 +1,17 @@
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
|
||||||
namespace Netina.Repository.Handlers.Reviews.Validators;
|
namespace Netina.Repository.Handlers.Comments.Validators;
|
||||||
|
|
||||||
public class UpdateReviewCommandValidator : AbstractValidator<UpdateReviewCommand>
|
public class UpdateCommentCommandValidator : AbstractValidator<UpdateCommentCommand>
|
||||||
{
|
{
|
||||||
public UpdateReviewCommandValidator()
|
public UpdateCommentCommandValidator()
|
||||||
{
|
{
|
||||||
RuleFor(d => d.Title)
|
RuleFor(d => d.Title)
|
||||||
.NotNull()
|
.NotNull()
|
||||||
.NotEmpty()
|
.NotEmpty()
|
||||||
.WithMessage("عنوان نظر مورد نظر را وارد کنید");
|
.WithMessage("عنوان نظر مورد نظر را وارد کنید");
|
||||||
|
|
||||||
RuleFor(d => d.Comment)
|
RuleFor(d => d.Content)
|
||||||
.NotNull()
|
.NotNull()
|
||||||
.NotEmpty()
|
.NotEmpty()
|
||||||
.WithMessage("متن نظر مورد نظر را وارد کنید");
|
.WithMessage("متن نظر مورد نظر را وارد کنید");
|
|
@ -1,34 +0,0 @@
|
||||||
using AppException = Netina.Common.Models.Exception.AppException;
|
|
||||||
|
|
||||||
namespace Netina.Repository.Handlers.Reviews;
|
|
||||||
|
|
||||||
public class CreateReviewCommandHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
|
|
||||||
: IRequestHandler<CreateReviewCommand, Guid>
|
|
||||||
{
|
|
||||||
public async Task<Guid> Handle(CreateReviewCommand request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
Guid userId = request.UserId;
|
|
||||||
if (userId == default)
|
|
||||||
{
|
|
||||||
if (!Guid.TryParse(currentUserService.UserId, out userId))
|
|
||||||
throw new AppException("User id is wrong", ApiResultStatusCode.BadRequest);
|
|
||||||
}
|
|
||||||
var review = Review.Create(request.Title, request.Comment, request.Rate, request.IsBuyer, request.IsAdmin, request.ProductId,
|
|
||||||
userId);
|
|
||||||
var product = await repositoryWrapper.SetRepository<Product>()
|
|
||||||
.TableNoTracking
|
|
||||||
.FirstOrDefaultAsync(p => p.Id == request.ProductId, cancellationToken);
|
|
||||||
if (product == null)
|
|
||||||
throw new AppException("Product not found", ApiResultStatusCode.NotFound);
|
|
||||||
|
|
||||||
product.AddRate(request.Rate);
|
|
||||||
|
|
||||||
repositoryWrapper.SetRepository<Product>().Update(product);
|
|
||||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
||||||
|
|
||||||
repositoryWrapper.SetRepository<Review>().Add(review);
|
|
||||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
||||||
|
|
||||||
return review.Id;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
namespace Netina.Repository.Handlers.Reviews;
|
|
||||||
|
|
||||||
public class DeleteReviewCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
||||||
: IRequestHandler<DeleteReviewCommand, Guid>
|
|
||||||
{
|
|
||||||
public async Task<Guid> Handle(DeleteReviewCommand request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var review = await repositoryWrapper.SetRepository<Review>().TableNoTracking
|
|
||||||
.FirstOrDefaultAsync(r => r.Id == request.Id, cancellationToken);
|
|
||||||
if (review == null)
|
|
||||||
throw new AppException("Review not found", ApiResultStatusCode.NotFound);
|
|
||||||
|
|
||||||
var product = await repositoryWrapper.SetRepository<Product>()
|
|
||||||
.TableNoTracking
|
|
||||||
.FirstOrDefaultAsync(p => p.Id == review.ProductId, cancellationToken);
|
|
||||||
if (product != null)
|
|
||||||
{
|
|
||||||
product.RemoveRate(review.Rate);
|
|
||||||
repositoryWrapper.SetRepository<Product>().Update(product);
|
|
||||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
repositoryWrapper.SetRepository<Review>().Delete(review);
|
|
||||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
||||||
return review.Id;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
using Review = Netina.Domain.Entities.Reviews.Review;
|
|
||||||
|
|
||||||
namespace Netina.Repository.Handlers.Reviews;
|
|
||||||
|
|
||||||
public class GetReviewQueryHandler(IRepositoryWrapper repositoryWrapper) : IRequestHandler<GetReviewQuery, ReviewLDto>
|
|
||||||
{
|
|
||||||
public async Task<ReviewLDto> Handle(GetReviewQuery request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var review = await repositoryWrapper.SetRepository<Review>()
|
|
||||||
.TableNoTracking
|
|
||||||
.Where(r => r.Id == request.Id)
|
|
||||||
.Select(ReviewMapper.ProjectToLDto)
|
|
||||||
.FirstOrDefaultAsync(cancellationToken);
|
|
||||||
if (review == null)
|
|
||||||
throw new AppException("Review not found", ApiResultStatusCode.NotFound);
|
|
||||||
|
|
||||||
return review;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
using Review = Netina.Domain.Entities.Reviews.Review;
|
|
||||||
|
|
||||||
namespace Netina.Repository.Handlers.Reviews;
|
|
||||||
|
|
||||||
public class GetReviewsQueryHandler(IRepositoryWrapper repositoryWrapper)
|
|
||||||
: IRequestHandler<GetReviewsQuery, List<ReviewSDto>>
|
|
||||||
{
|
|
||||||
public async Task<List<ReviewSDto>> Handle(GetReviewsQuery request, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var query = repositoryWrapper.SetRepository<Review>()
|
|
||||||
.TableNoTracking;
|
|
||||||
if (request.ProductId != null)
|
|
||||||
query = query.Where(q => q.ProductId == request.ProductId);
|
|
||||||
|
|
||||||
return await query
|
|
||||||
.OrderByDescending(r => r.CreatedAt)
|
|
||||||
.Skip(request.Page * 15)
|
|
||||||
.Take(15)
|
|
||||||
.Select(ReviewMapper.ProjectToSDto)
|
|
||||||
.ToListAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -59,15 +59,17 @@
|
||||||
<Using Include="Netina.Domain.Dtos.LargDtos" />
|
<Using Include="Netina.Domain.Dtos.LargDtos" />
|
||||||
<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.Discounts" />
|
<Using Include="Netina.Domain.Entities.Discounts" />
|
||||||
<Using Include="Netina.Domain.Entities.ProductCategories" />
|
<Using Include="Netina.Domain.Entities.ProductCategories" />
|
||||||
<Using Include="Netina.Domain.Entities.Products" />
|
<Using Include="Netina.Domain.Entities.Products" />
|
||||||
<Using Include="Netina.Domain.Entities.Reviews" />
|
<Using Include="Netina.Domain.Entities.Comments" />
|
||||||
<Using Include="Netina.Domain.Entities.Users" />
|
<Using Include="Netina.Domain.Entities.Users" />
|
||||||
<Using Include="Netina.Domain.Enums" />
|
<Using Include="Netina.Domain.Enums" />
|
||||||
<Using Include="Netina.Domain.Extensions" />
|
<Using Include="Netina.Domain.Extensions" />
|
||||||
<Using Include="Netina.Domain.Mappers" />
|
<Using Include="Netina.Domain.Mappers" />
|
||||||
<Using Include="Netina.Domain.MartenEntities.Faqs" />
|
<Using Include="Netina.Domain.MartenEntities.Faqs" />
|
||||||
|
<Using Include="Netina.Domain.Models" />
|
||||||
<Using Include="Netina.Domain.Models.Claims" />
|
<Using Include="Netina.Domain.Models.Claims" />
|
||||||
<Using Include="Netina.Domain.Models.Settings" />
|
<Using Include="Netina.Domain.Models.Settings" />
|
||||||
<Using Include="Netina.Repository.Abstracts" />
|
<Using Include="Netina.Repository.Abstracts" />
|
||||||
|
|
Loading…
Reference in New Issue