improvements, fixes, etc...

This commit is contained in:
Loretta 2024-11-21 12:28:53 +01:00
parent acc9496490
commit 637d5c1dc8
3 changed files with 36 additions and 29 deletions

View File

@ -17,6 +17,7 @@ public class ProductToAuctionDto : IProductToAuctionDto
public List<AuctionBidDto> AuctionBidDtos { get; } = []; public List<AuctionBidDto> AuctionBidDtos { get; } = [];
public bool IsActiveItem => AuctionStatus is AuctionStatus.Active or AuctionStatus.FirstWarning or AuctionStatus.SecondWarning;
public ProductToAuctionDto() public ProductToAuctionDto()
{ {

View File

@ -1,27 +1,36 @@
using System.Globalization; using System.Globalization;
using AyCode.Core.Extensions; using AyCode.Core.Extensions;
using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages; using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
using Newtonsoft.Json.Linq;
using Nop.Plugin.Misc.AuctionPlugin.Models; using Nop.Plugin.Misc.AuctionPlugin.Models;
using Nop.Plugin.Misc.AuctionPlugin.Services; using Nop.Plugin.Misc.AuctionPlugin.Services;
using Nop.Services.Catalog; using Nop.Services.Catalog;
using Newtonsoft.Json;
using Nop.Services.Logging; using Nop.Services.Logging;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Newtonsoft.Json.Serialization;
using Microsoft.AspNetCore.SignalR; using Microsoft.AspNetCore.SignalR;
using Nop.Core; using Nop.Core;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
using Nop.Services.Customers;
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{ {
//- SortIndex
//- Rátettem egy unique-ot az AuctionId és a ProductId-ra!!!
//- Új field-ek a db-be! pl.: WinnerCustomerId, stb...
//- IsActiveItem
//- Product onupdate
//- lock
//- ha saját licit a legjobb vagy lezárt, ne lehessen bid-elni
//- az előző esetben a kliensen a gombot is tiltani, már a.cshtml-ben ellenőrizni!
//- ha nincs login elszállhat a kliens
//- csak a watch-olt item-eknél legyen announcment
//- ha bid-elt 1x is, kerüljön a watch-ba
//- DbTransaction-t vhogy megcsinánli!
//- NextStepAmount
public class SignalRMessageHandler public class SignalRMessageHandler
{ {
protected readonly ILogger _logger; private readonly ILogger _logger;
protected readonly IProductService _productService; private readonly IProductService _productService;
protected readonly AuctionService _auctionService; private readonly AuctionService _auctionService;
private IHubContext<AuctionHub> _hubContext; private readonly IHubContext<AuctionHub> _hubContext;
private readonly IWorkContext _workContext; private readonly IWorkContext _workContext;
public SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext<AuctionHub> hubContext, IWorkContext workContext) public SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext<AuctionHub> hubContext, IWorkContext workContext)
@ -114,7 +123,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
await _auctionService.UpdateProductToAuctionMappingAsync(productToAuction); await _auctionService.UpdateProductToAuctionMappingAsync(productToAuction);
var bid = new MessageWrapper var productToauctionChangedNotification = new MessageWrapper
{ {
MessageType = nameof(ProductToAuctionStatusNotification), MessageType = nameof(ProductToAuctionStatusNotification),
SenderId = senderId, SenderId = senderId,
@ -124,7 +133,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
}.ToJson() }.ToJson()
}; };
await _hubContext.Clients.All.SendAsync("send", bid.ToJson()); await _hubContext.Clients.All.SendAsync("send", productToauctionChangedNotification.ToJson());
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -204,7 +213,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{ {
ProductName = auctionBid.ProductId.ToString(), ProductName = auctionBid.ProductId.ToString(),
BidPrice = auctionBid.BidPrice.ToString(CultureInfo.InvariantCulture), BidPrice = auctionBid.BidPrice.ToString(CultureInfo.InvariantCulture),
NextStepAmount = "50000", NextStepAmount = "50000", //TODO: - J.
ToasterMessage = string.Empty, //TODO: - J. ToasterMessage = string.Empty, //TODO: - J.
}.ToJson() }.ToJson()
}; };

View File

@ -1,9 +1,5 @@
using AyCode.Core.Extensions; using Nop.Core;
using Nop.Core;
using Nop.Core.Caching; using Nop.Core.Caching;
using Nop.Core.Domain.Customers;
using Nop.Data;
using Nop.Plugin.Misc.AuctionPlugin.Domains;
using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer; using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos; using Nop.Plugin.Misc.AuctionPlugin.Domains.Dtos;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
@ -25,21 +21,18 @@ public class AuctionService : IAuctionService
/// <remarks> /// <remarks>
/// {0} : current store ID /// {0} : current store ID
/// </remarks> /// </remarks>
protected readonly CacheKey _auctionAllKey = new("Nop.auction.all-{0}", AUCTION_PATTERN_KEY); private readonly CacheKey _auctionAllKey = new("Nop.auction.all-{0}", AUCTION_PATTERN_KEY); //nem ezt használjuk a kódban, nem gond?! - J.
protected const string AUCTION_PATTERN_KEY = "Nop.auction."; private const string AUCTION_PATTERN_KEY = "Nop.auction.";
#endregion #endregion
#region Fields #region Fields
protected readonly AuctionDbContext _ctx; private readonly AuctionDbContext _ctx;
//protected readonly IRepository<AuctionBid> _customerBidRepository; private readonly IShortTermCacheManager _shortTermCacheManager;
//protected readonly IRepository<Auction> _auctionRepository; private readonly IStaticCacheManager _staticCacheManager;
//protected readonly IRepository<ProductToAuctionMapping> _productToAuctionRepository; private readonly IWorkContext _workContext;
protected readonly IShortTermCacheManager _shortTermCacheManager; private readonly ILogger _logger;
protected readonly IStaticCacheManager _staticCacheManager;
protected readonly IWorkContext _workContext;
protected readonly ILogger _logger;
#endregion #endregion
#region Ctor #region Ctor
@ -50,6 +43,8 @@ public class AuctionService : IAuctionService
/// <param name="ctx"></param> /// <param name="ctx"></param>
/// <param name="shortTermCacheManager">Short term cache manager</param> /// <param name="shortTermCacheManager">Short term cache manager</param>
/// <param name="staticCacheManager">Cache manager</param> /// <param name="staticCacheManager">Cache manager</param>
/// <param name="workContext"></param>
/// <param name="logger"></param>
public AuctionService( public AuctionService(
AuctionDbContext ctx, AuctionDbContext ctx,
//IRepository<Auction> auctionRepository, //IRepository<Auction> auctionRepository,
@ -93,6 +88,8 @@ public class AuctionService : IAuctionService
/// </returns> /// </returns>
public async Task<IPagedList<AuctionBid>> GetAllBidsAsync(int customerId = 0, int pageIndex = 0, int pageSize = int.MaxValue) public async Task<IPagedList<AuctionBid>> GetAllBidsAsync(int customerId = 0, int pageIndex = 0, int pageSize = int.MaxValue)
{ {
//TODO: megcsinálni! - J.
var rez = new List<AuctionBid>(); var rez = new List<AuctionBid>();
//var rez = await _shortTermCacheManager.GetAsync(async () => await _customerBidRepository.GetAllAsync(query => //var rez = await _shortTermCacheManager.GetAsync(async () => await _customerBidRepository.GetAllAsync(query =>
//{ //{
@ -209,12 +206,12 @@ public class AuctionService : IAuctionService
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId) public async Task<List<ProductToAuctionMapping>> GetProductToAuctionsByProductIdAsync(int productId)
{ {
return new List<ProductToAuctionMapping>(await _ctx.ProductToAuctions.GetByProductId(productId).ToListAsync()); return [..await _ctx.ProductToAuctions.GetByProductId(productId).ToListAsync()];
} }
public async Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly = false) public async Task<List<ProductToAuctionMapping>> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly = false)
{ {
return new List<ProductToAuctionMapping>(await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId, activeProductOnly).ToListAsync()); return [..await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId, activeProductOnly).ToListAsync()];
} }
public async Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId) public async Task<ProductToAuctionMapping> AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)