imrpovements, fixes

This commit is contained in:
Loretta 2024-11-26 09:10:58 +01:00
parent 85b520d6c3
commit f8bc35cf05
5 changed files with 73 additions and 54 deletions

View File

@ -9,7 +9,8 @@
SecondWarning: 4,
Pause: 8,
Sold: 16,
NotSold: 32
NotSold: 32,
TEST: 64
});
// HUF Formatter

View File

@ -6,6 +6,7 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer.Interfaces;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Services.Catalog;
using System;
using Nop.Plugin.Misc.AuctionPlugin.Services;
using Nop.Services.Logging;
namespace Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
@ -13,6 +14,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Domains.DataLayer;
public class AuctionDbContext : MgDbContextBase, IAuctionDbSet<AuctionDbTable>, IProductToAuctionDbSet<ProductToAuctionDbTable>, IAuctionBidDbSet<AuctionBidDbTable>
{
private readonly IProductService _productService;
private readonly IStaticCacheManager _staticCacheManager;
public AuctionDbTable Auctions { get; set; }
public ProductToAuctionDbTable ProductToAuctions { get; set; }
@ -23,9 +25,10 @@ public class AuctionDbContext : MgDbContextBase, IAuctionDbSet<AuctionDbTable>,
//public IRepository<AuctionBid> AuctionBids2 { get; set; }
public AuctionDbContext(INopDataProvider dataProvider, AuctionDbTable auctionDbTable, ProductToAuctionDbTable productToAuctionDbTable, AuctionBidDbTable auctionBidDbTable, IProductService productService, ILogger logger) : base(dataProvider, logger)
public AuctionDbContext(INopDataProvider dataProvider, AuctionDbTable auctionDbTable, ProductToAuctionDbTable productToAuctionDbTable, AuctionBidDbTable auctionBidDbTable, IProductService productService, IStaticCacheManager staticCacheManager, ILogger logger) : base(dataProvider, logger)
{
_productService = productService;
_staticCacheManager = staticCacheManager;
Auctions = auctionDbTable;
ProductToAuctions = productToAuctionDbTable;
@ -84,9 +87,16 @@ public class AuctionDbContext : MgDbContextBase, IAuctionDbSet<AuctionDbTable>,
}
if (basePrice <= 0) basePrice = product.Price;
else product.Price = basePrice;
else
{
product.Price = basePrice;
await _productService.UpdateProductAsync(product);
}
await ProductToAuctions.ResetAsync(productToAuction, basePrice);
await AuctionBids.DeleteAllByProductToAuctionIdAsync(productToAuction.Id);
await _staticCacheManager.ClearAsync();
//await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
}
}

View File

@ -13,6 +13,8 @@ using Nop.Core.Domain.Customers;
using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
using Nop.Services.Customers;
using DocumentFormat.OpenXml.Wordprocessing;
using Mango.Nop.Core.Repositories;
using Nop.Core.Caching;
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{
@ -91,7 +93,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
{
if (revertAuctionBidRequest == null)
{
logger.Error($"SignalRMessageHandler.HanldeRevertAuctionBidRequest(); auctionProductStatusRequest == null", null, customer);
logger.Error($"SignalRMessageHandler.HandleRevertAuctionBidRequest(); auctionProductStatusRequest == null", null, customer);
return;
}
@ -100,7 +102,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
var productToAuction = (await auctionService.GetProductToAuctionMappingByIdAsync(revertAuctionBidRequest.ProductToAuctionId));
if (productToAuction is not { AuctionStatus: AuctionStatus.Pause })
{
logger.Warning($"SignalRMessageHandler.HandleBidRequest(); (productToAuction is not {{ AuctionStatus: AuctionStatus.Pause }}); AuctionStatus: {productToAuction?.AuctionStatus}", null, customer);
logger.Warning($"SignalRMessageHandler.HandleRevertAuctionBidRequest(); (productToAuction is not {{ AuctionStatus: AuctionStatus.Pause }}); AuctionStatus: {productToAuction?.AuctionStatus}", null, customer);
return; //TODO: - J.
}
@ -111,6 +113,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
if (revertLastBid == null)
{
//TODO: NA ILYENKOR VAN A CUMI... - J.
logger.Warning($"SignalRMessageHandler.HandleRevertAuctionBidRequest(); revertLastBid == null", null, customer);
return;
}
@ -119,7 +122,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
}
catch (Exception ex)
{
logger.Error($"SignalRMessageHandler.HanldeRevertAuctionBidRequest(); Exception: {ex.Message}", ex, customer);
logger.Error($"SignalRMessageHandler.HandleRevertAuctionBidRequest(); Exception: {ex.Message}", ex, customer);
}
}
@ -234,9 +237,9 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
}
var activeProductAuction = (await auctionService.GetProductToAuctionByAuctionIdAndProductIdAsync(bidRequestMessage.AuctionId, bidRequestMessage.ProductId, true)).FirstOrDefault();
if (activeProductAuction is not { IsActiveItem: true } || activeProductAuction.WinnerCustomerId == customer.Id)
if (activeProductAuction is not { IsActiveItem: true } || (activeProductAuction.WinnerCustomerId == customer.Id && !await customerService.IsAdminAsync(customer)))
{
logger.Warning($"SignalRMessageHandler.HandleBidRequest(); (activeProductAuction is not {{ IsActiveItem: true }}); AuctionStatus: {activeProductAuction?.AuctionStatus};", null, customer);
logger.Warning($"SignalRMessageHandler.HandleBidRequest(); (activeProductAuction is not {{ IsActiveItem: true }} || activeProductAuction.WinnerCustomerId == customer.Id && !await customerService.IsAdminAsync(customer)); AuctionStatus: {activeProductAuction?.AuctionStatus}; WinnerCustomerId: {activeProductAuction?.WinnerCustomerId}", null, customer);
return; //TODO: - J.
}
@ -246,14 +249,13 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
var auctionBid = bidRequestMessage.CreateMainEntity();
auctionBid.ProductAuctionMappingId = activeProductAuction.Id;
//TODO: validate the bidprice amount
//TODO: Validálni, h a bejövő BidPrice valóban a következő licit lépcső! - J.
if (product.Price >= auctionBid.BidPrice || activeProductAuction.CurrentPrice >= auctionBid.BidPrice)
{
logger.Warning($"SignalRMessageHandler.HandleBidRequest(); (product.Price >= bidRequestMessage.BidPrice || activeProductAuction.CurrentPrice >= auctionBid.BidPrice); productPrice: {product.Price}; bidRequestPrice: {auctionBid.BidPrice}; activeProductAuctionPrice: {activeProductAuction.CurrentPrice}", null, customer);
return;
}
//save bid
await auctionService.InsertBidAsync(auctionBid);
activeProductAuction.AuctionStatus = AuctionStatus.Active;
@ -316,13 +318,13 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
switch (oldStatus)
{
case AuctionStatus.None:
return newStatus == AuctionStatus.Active;
return newStatus is AuctionStatus.Active or AuctionStatus.Pause;
case AuctionStatus.Active:
return newStatus is AuctionStatus.None or AuctionStatus.FirstWarning or AuctionStatus.Pause;
return newStatus is AuctionStatus.FirstWarning or AuctionStatus.Pause;
case AuctionStatus.FirstWarning:
return newStatus is AuctionStatus.None or AuctionStatus.SecondWarning or AuctionStatus.Pause;
return newStatus is AuctionStatus.SecondWarning or AuctionStatus.Pause;
case AuctionStatus.SecondWarning:
return newStatus is AuctionStatus.None or AuctionStatus.Sold or AuctionStatus.Pause;
return newStatus is AuctionStatus.Sold or AuctionStatus.Pause;
case AuctionStatus.Pause:
return newStatus is AuctionStatus.None or AuctionStatus.Active;
case AuctionStatus.Sold:

View File

@ -21,25 +21,10 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Services;
/// </summary>
public class AuctionService : IAuctionService
{
#region Constants
/// <summary>
/// Cache key for pickup points
/// </summary>
/// <remarks>
/// {0} : current store ID
/// </remarks>
private readonly CacheKey _auctionAllKey = new("Nop.auction.all-{0}", AUCTION_PATTERN_KEY);
private const string AUCTION_PATTERN_KEY = "Nop.auction.";
#endregion
#region Fields
private readonly AuctionDbContext _ctx;
private readonly IProductService _productService;
private readonly IShortTermCacheManager _shortTermCacheManager;
private readonly IStaticCacheManager _staticCacheManager;
private readonly IWorkContext _workContext;
private readonly IOrderProcessingService _orderProcessingService;
private readonly ILogger _logger;
@ -53,27 +38,13 @@ public class AuctionService : IAuctionService
/// <param name="ctx"></param>
/// <param name="shortTermCacheManager">Short term cache manager</param>
/// <param name="staticCacheManager">Cache manager</param>
/// <param name="productService"></param>
/// <param name="workContext"></param>
/// <param name="logger"></param>
public AuctionService(
AuctionDbContext ctx,
IProductService productService,
//IRepository<Auction> auctionRepository,
//IRepository<ProductToAuctionMapping> productToAuctionRepository,
IShortTermCacheManager shortTermCacheManager,
IStaticCacheManager staticCacheManager,
IWorkContext workContext,
IOrderProcessingService orderProcessingService,
ILogger logger)
public AuctionService(AuctionDbContext ctx, IProductService productService, IWorkContext workContext, IOrderProcessingService orderProcessingService, ILogger logger)
{
_ctx = ctx;
_productService = productService;
//_customerBidRepository = customerBidRepository;
//_auctionRepository = auctionRepository;
//_productToAuctionRepository = productToAuctionRepository;
_shortTermCacheManager = shortTermCacheManager;
_staticCacheManager = staticCacheManager;
_workContext = workContext;
_orderProcessingService = orderProcessingService;
_logger = logger;
@ -195,7 +166,6 @@ public class AuctionService : IAuctionService
if (await ValidateAuctionBid(auctionBid))
{
await _ctx.AuctionBids.InsertAsync(auctionBid, false);
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
}
}
@ -204,7 +174,6 @@ public class AuctionService : IAuctionService
if (await ValidateAuctionBid(auctionBid))
{
await _ctx.AuctionBids.UpdateAsync(auctionBid, false);
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
}
}
@ -216,7 +185,6 @@ public class AuctionService : IAuctionService
public async Task DeleteBidAsync(AuctionBid pickupPoint)
{
await _ctx.AuctionBids.DeleteAsync(pickupPoint, false);
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
}
public async Task CreateOrderForWinner(ProductToAuctionMapping auctionItem)
@ -230,13 +198,11 @@ public class AuctionService : IAuctionService
public async Task InsertAuctionAsync(Auction auction)
{
await _ctx.Auctions.InsertAsync(auction, false);
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
}
public async Task UpdateAuctionAsync(Auction auction)
{
await _ctx.Auctions.UpdateAsync(auction);
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
}
public async Task<IList<Auction>> GetAllAuctionsAsync()
@ -368,7 +334,6 @@ public class AuctionService : IAuctionService
public async Task UpdateProductToAuctionMappingAsync(ProductToAuctionMapping productToAuctionMapping)
{
await _ctx.ProductToAuctions.UpdateAsync(productToAuctionMapping);
await _staticCacheManager.RemoveByPrefixAsync(AUCTION_PATTERN_KEY);
}
#endregion Dtos

View File

@ -118,10 +118,12 @@
document.getElementById("signalRBidButton").disabled = true;
event.preventDefault();
if (!bidBoxPageViewModel) {
console.log("we need viewmodel data");
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
}
var bidMessage = {
ProductAuctionMappingId: bidBoxPageViewModel.ProductToAuctionId,
AuctionId: bidBoxPageViewModel.AuctionId,
@ -129,6 +131,7 @@
ProductId: bidBoxPageViewModel.ProductId,
CustomerId: bidBoxPageViewModel.CustomerId
};
var content = JSON.stringify(bidMessage);
console.log("WTF " + content);
sendMessageToServer("BidRequestMessage", bidBoxPageViewModel.CustomerId, content);
@ -150,7 +153,7 @@
document.getElementById("signalRCloseItemButton").disabled = true;
event.preventDefault();
sendAuctionStatusChange(AuctionStatus.Sold); //Itt SoldOut volt, átírtam Sold-ra! - J.
sendAuctionStatusChange(AuctionStatus.Sold);
return false;
});
@ -186,11 +189,30 @@
document.getElementById("signalRRevertBidButton").disabled = true;
event.preventDefault();
sendAuctionStatusChange(AuctionStatus.Revert);
if (!bidBoxPageViewModel) {
console.log("we need viewmodel data");
bidBoxPageViewModel = @Html.Raw(Json.Serialize(Model));
}
var revertMessage = {
ProductToAuctionId: bidBoxPageViewModel.ProductToAuctionId,
};
var content = JSON.stringify(revertMessage);
console.log("WTF " + content);
sendMessageToServer("RevertAuctionBidRequest", bidBoxPageViewModel.CustomerId, content);
return false;
});
$("#signalRResetItemButton").on("click", function () {
document.getElementById("signalRResetItemButton").disabled = true;
event.preventDefault();
sendAuctionStatusChange(AuctionStatus.None);
return false;
});
});
function sendAuctionStatusChange(auctionStatus) {
@ -231,7 +253,11 @@
console.log(data);
var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id;
console.log(productAuctionMappingId);
//TODO: TESZT STATUS!!! - JTEST.
var status = data.auctionDto.productToAuctionDtos[0].auctionStatus;
//var status = AuctionStatus.TEST;
//if (status == AuctionStatus.FirstWarning) {
setButtons(status);
//}
@ -274,9 +300,13 @@
function handleAuctionUpdate(data) {
var widgetPriceElement = document.getElementById("price-value-" + bidBoxPageViewModel.ProductId);
var productAuctionMappingId = data.auctionDto.productToAuctionDtos[0].id;
//TODO: TESZT STATUS!!! - JTEST.
var itemStatus = data.auctionDto.productToAuctionDtos[0].auctionStatus;
//var itemStatus = AuctionStatus.TEST;
console.log("handle auction update called" + productAuctionMappingId);
console.log("auction status:" + itemStatus)
console.log("auction status:" + itemStatus);
if (widgetPriceElement) {
if (productAuctionMappingId == bidBoxPageViewModel.ProductToAuctionId) {
@ -376,6 +406,17 @@
signalRRevertBidButton: false,
signalRResetItemButton: false,
},
[AuctionStatus.TEST]: {
signalRBidButton: false,
signalRFirstWarningButton: false,
signalRSecondWarningButton: false,
signalROpenItemButton: false,
signalRCloseItemButton: false,
signalRPauseItemButton: false,
signalRRevertBidButton: false,
signalRResetItemButton: false,
},
};
// Get the states for the given auctionStatus