From 637d5c1dc83be039bbb3f2e9c421a21523fc683d Mon Sep 17 00:00:00 2001 From: Loretta Date: Thu, 21 Nov 2024 12:28:53 +0100 Subject: [PATCH] improvements, fixes, etc... --- .../Domains/Dtos/ProductToAuctionDto.cs | 1 + .../Hubs/SignalRMessageHandler.cs | 33 ++++++++++++------- .../Services/AuctionService.cs | 31 ++++++++--------- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs index f43c70b..346d48a 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Domains/Dtos/ProductToAuctionDto.cs @@ -17,6 +17,7 @@ public class ProductToAuctionDto : IProductToAuctionDto public List AuctionBidDtos { get; } = []; + public bool IsActiveItem => AuctionStatus is AuctionStatus.Active or AuctionStatus.FirstWarning or AuctionStatus.SecondWarning; public ProductToAuctionDto() { diff --git a/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs b/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs index ac6c58b..6c2e99b 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Hubs/SignalRMessageHandler.cs @@ -1,27 +1,36 @@ using System.Globalization; using AyCode.Core.Extensions; using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages; -using Newtonsoft.Json.Linq; using Nop.Plugin.Misc.AuctionPlugin.Models; using Nop.Plugin.Misc.AuctionPlugin.Services; using Nop.Services.Catalog; -using Newtonsoft.Json; using Nop.Services.Logging; -using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; -using Newtonsoft.Json.Serialization; using Microsoft.AspNetCore.SignalR; using Nop.Core; using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums; -using Nop.Services.Customers; 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 { - protected readonly ILogger _logger; - protected readonly IProductService _productService; - protected readonly AuctionService _auctionService; - private IHubContext _hubContext; + private readonly ILogger _logger; + private readonly IProductService _productService; + private readonly AuctionService _auctionService; + private readonly IHubContext _hubContext; private readonly IWorkContext _workContext; public SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext hubContext, IWorkContext workContext) @@ -114,7 +123,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs await _auctionService.UpdateProductToAuctionMappingAsync(productToAuction); - var bid = new MessageWrapper + var productToauctionChangedNotification = new MessageWrapper { MessageType = nameof(ProductToAuctionStatusNotification), SenderId = senderId, @@ -124,7 +133,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs }.ToJson() }; - await _hubContext.Clients.All.SendAsync("send", bid.ToJson()); + await _hubContext.Clients.All.SendAsync("send", productToauctionChangedNotification.ToJson()); } catch (Exception ex) { @@ -204,7 +213,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs { ProductName = auctionBid.ProductId.ToString(), BidPrice = auctionBid.BidPrice.ToString(CultureInfo.InvariantCulture), - NextStepAmount = "50000", + NextStepAmount = "50000", //TODO: - J. ToasterMessage = string.Empty, //TODO: - J. }.ToJson() }; diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs index cfe47c8..8e1a50a 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionService.cs @@ -1,9 +1,5 @@ -using AyCode.Core.Extensions; -using Nop.Core; +using Nop.Core; 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.Dtos; using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities; @@ -25,21 +21,18 @@ public class AuctionService : IAuctionService /// /// {0} : current store ID /// - protected readonly CacheKey _auctionAllKey = new("Nop.auction.all-{0}", AUCTION_PATTERN_KEY); - protected const string AUCTION_PATTERN_KEY = "Nop.auction."; + private readonly CacheKey _auctionAllKey = new("Nop.auction.all-{0}", AUCTION_PATTERN_KEY); //nem ezt használjuk a kódban, nem gond?! - J. + private const string AUCTION_PATTERN_KEY = "Nop.auction."; #endregion #region Fields - protected readonly AuctionDbContext _ctx; - //protected readonly IRepository _customerBidRepository; - //protected readonly IRepository _auctionRepository; - //protected readonly IRepository _productToAuctionRepository; - protected readonly IShortTermCacheManager _shortTermCacheManager; - protected readonly IStaticCacheManager _staticCacheManager; - protected readonly IWorkContext _workContext; - protected readonly ILogger _logger; + private readonly AuctionDbContext _ctx; + private readonly IShortTermCacheManager _shortTermCacheManager; + private readonly IStaticCacheManager _staticCacheManager; + private readonly IWorkContext _workContext; + private readonly ILogger _logger; #endregion #region Ctor @@ -50,6 +43,8 @@ public class AuctionService : IAuctionService /// /// Short term cache manager /// Cache manager + /// + /// public AuctionService( AuctionDbContext ctx, //IRepository auctionRepository, @@ -93,6 +88,8 @@ public class AuctionService : IAuctionService /// public async Task> GetAllBidsAsync(int customerId = 0, int pageIndex = 0, int pageSize = int.MaxValue) { + //TODO: megcsinálni! - J. + var rez = new List(); //var rez = await _shortTermCacheManager.GetAsync(async () => await _customerBidRepository.GetAllAsync(query => //{ @@ -209,12 +206,12 @@ public class AuctionService : IAuctionService public async Task> GetProductToAuctionsByProductIdAsync(int productId) { - return new List(await _ctx.ProductToAuctions.GetByProductId(productId).ToListAsync()); + return [..await _ctx.ProductToAuctions.GetByProductId(productId).ToListAsync()]; } public async Task> GetProductToAuctionByAuctionIdAndProductIdAsync(int auctionId, int productId, bool activeProductOnly = false) { - return new List(await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId, activeProductOnly).ToListAsync()); + return [..await _ctx.ProductToAuctions.GetByAuctionAndProductId(auctionId, productId, activeProductOnly).ToListAsync()]; } public async Task AssignProductToAuctionAsync(int productId, decimal startingPrice, decimal bidPrice, int auctionId)