improvements, fixes, etc...

This commit is contained in:
Loretta 2025-09-09 04:38:39 +02:00
parent fbad15e02f
commit 3abfc03d1e
9 changed files with 128 additions and 17 deletions

View File

@ -7,12 +7,15 @@ using FruitBank.Common.Loggers;
using FruitBank.Common.Models;
using FruitBank.Common.SignalRs;
using Microsoft.AspNetCore.Mvc;
using Nop.Core;
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
using Nop.Services.Customers;
using Nop.Web.Framework.Controllers;
namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
{
//https://linq2db.github.io/articles/sql/Join-Operators.html
public class FruitBankDataController(FruitBankDbContext ctx, IEnumerable<IAcLogWriterBase> logWriters): Controller, IFruitBankDataControllerServer
public class FruitBankDataController(FruitBankDbContext ctx, IWorkContext workContext, ICustomerService customerService, IEnumerable<IAcLogWriterBase> logWriters): BasePluginController, IFruitBankDataControllerServer
{
private readonly ILogger _logger = new Logger<FruitBankDataController>(logWriters.ToArray());
@ -26,7 +29,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
[SignalR(SignalRTags.GetMeasuringModelByShippingId)]
public async Task<MeasuringModel> GetMeasuringModelByShippingId(int shippingId)
{
return await ctx.GetMeasuringModelByShippingId(shippingId);
return await ctx.GetMeasuringModelByShippingId(shippingId).FirstOrDefaultAsync();
}
[SignalR(SignalRTags.GetPartners)]
@ -34,7 +37,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
{
_logger.Detail($"GetPartners invoked");
return await ctx.Partners.Table.ToListAsync();
return await ctx.Partners.GetAll().ToListAsync();
}
[SignalR(SignalRTags.GetPartnerById)]
@ -42,15 +45,30 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
{
_logger.Detail($"GetPartnerById invoked; id: {id}");
var customers = await ctx.GetCustormersBySystemRoleName("Measuring").ToListAsync();
_logger.Error($"COUNT: {customers.Count}");
return await ctx.Partners.GetByIdAsync(id);
}
[SignalR(SignalRTags.UpdatePartner)]
public async Task<Partner> UpdatePartner(Partner partner)
{
ArgumentNullException.ThrowIfNull(partner);
_logger.Detail($"UpdatePartner invoked; id: {partner.Id}");
await ctx.Partners.UpdateAsync(partner);
return partner;
}
[SignalR(SignalRTags.GetShippings)]
public async Task<List<Shipping>> GetShippings()
{
_logger.Detail($"GetShippings invoked");
return await ctx.Shippings.Table.ToListAsync();
return await ctx.Shippings.GetAll().ToListAsync();
}
[SignalR(SignalRTags.GetShippingById)]
@ -61,24 +79,36 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
return await ctx.Shippings.GetByIdAsync(id);
}
public async Task<List<ShippingItem>> GetShippingItem()
[SignalR(SignalRTags.GetShippingItems)]
public async Task<List<ShippingItem>> GetShippingItems()
{
throw new NotImplementedException();
_logger.Detail($"GetShippingItems invoked");
return await ctx.ShippingItems.GetAll().ToListAsync();
}
[SignalR(SignalRTags.GetShippingItemById)]
public async Task<ShippingItem> GetShippingItemById(int id)
{
throw new NotImplementedException();
_logger.Detail($"GetShippingItemById invoked; id: {id}");
return await ctx.ShippingItems.GetByIdAsync(id);
}
[SignalR(SignalRTags.GetShippingDocuments)]
public async Task<List<ShippingDocument>> GetShippingDocuments()
{
throw new NotImplementedException();
_logger.Detail($"GetShippingDocuments invoked");
return await ctx.ShippingDocuments.GetAll().ToListAsync();
}
[SignalR(SignalRTags.GetShippingDocumentById)]
public async Task<ShippingDocument> GetShippingDocumentById(int id)
{
throw new NotImplementedException();
_logger.Detail($"GetShippingDocumentById invoked; id: {id}");
return await ctx.ShippingDocuments.GetByIdAsync(id);
}
}
}

View File

@ -1,26 +1,41 @@
using FruitBank.Common.Models;
using DocumentFormat.OpenXml.Drawing;
using FruitBank.Common.Models;
using LinqToDB;
using Mango.Nop.Core.Repositories;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Nop.Core.Caching;
using Nop.Core.Domain.Customers;
using Nop.Data;
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
using Nop.Services.Catalog;
using Nop.Services.Logging;
using NUglify.Helpers;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>, IShippingDbSet<ShippingDbTable>, IShippingItemDbSet<ShippingItemDbTable>
public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>, IShippingDbSet<ShippingDbTable>, IShippingItemDbSet<ShippingItemDbTable>, IShippingDocumentDbSet<ShippingDocumentDbTable>
{
private readonly IProductService _productService;
private readonly IStaticCacheManager _staticCacheManager;
protected readonly IRepository<Customer> _customerRepository;
protected readonly IRepository<CustomerCustomerRoleMapping> _customerCustomerRoleMappingRepository;
protected readonly IRepository<CustomerRole> _customerRoleRepository;
public PartnerDbTable Partners { get; set; }
public ShippingDbTable Shippings { get; set; }
public ShippingItemDbTable ShippingItems { get; set; }
public ShippingDocumentDbTable ShippingDocuments { get; set; }
//public EntityRepository<Auction> Auctions2 { get; set; }
//public IRepository<AuctionBid> AuctionBids2 { get; set; }
public FruitBankDbContext(INopDataProvider dataProvider, PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingItemDbTable shippingItemDbTable, IProductService productService, IStaticCacheManager staticCacheManager, ILogger logger) : base(dataProvider, logger)
public FruitBankDbContext(INopDataProvider dataProvider, PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingItemDbTable shippingItemDbTable,
ShippingDocumentDbTable shippingDocumentDbTable, IProductService productService, IStaticCacheManager staticCacheManager,
IRepository<Customer> customerRepository,
IRepository<CustomerCustomerRoleMapping> customerCustomerRoleMappingRepository,
IRepository<CustomerRole> customerRoleRepository,
ILogger logger) : base(dataProvider, logger)
{
_productService = productService;
_staticCacheManager = staticCacheManager;
@ -28,12 +43,18 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
Partners = partnerDbTable;
Shippings = shippingDbTable;
ShippingItems = shippingItemDbTable;
ShippingDocuments = shippingDocumentDbTable;
_customerRepository = customerRepository;
_customerCustomerRoleMappingRepository = customerCustomerRoleMappingRepository;
_customerRoleRepository = customerRoleRepository;
//Auctions.Table
//var auctions = DataProvider.GetTable<Auction>().Where(x => x.Closed);
}
public async Task<MeasuringModel> GetMeasuringModelByShippingId(int shippingId)
public IQueryable<MeasuringModel> GetMeasuringModelByShippingId(int shippingId)
{
var query =
from p in Partners.Table
@ -41,7 +62,30 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
where s.Id == shippingId
select new MeasuringModel(p.Name);
return await query.FirstOrDefaultAsync();
return query;
}
public IQueryable<Customer> GetCustormersBySystemRoleName(string systemRoleName)
{
if (systemRoleName.IsNullOrWhiteSpace()) throw new ArgumentException("systemRoleName.IsNullOrWhiteSpace()", nameof(systemRoleName));
var query =
from c in _customerRepository.Table
join crm in _customerCustomerRoleMappingRepository.Table on c.Id equals crm.CustomerId
join cr in _customerRoleRepository.Table on crm.CustomerRoleId equals cr.Id
where c.Active && !c.Deleted && cr.SystemName == systemRoleName
select c;
return query.Distinct();
// query = query.Join(_customerCustomerRoleMappingRepository.Table, x => x.Id, y => y.CustomerId,
// (x, y) => new { Customer = x, Mapping = y })
// .Where(z => z.Mapping.CustomerRoleId == customerRoleId)
// .Select(z => z.Customer)
// .Distinct();
//});
//return customers;
}
////public AuctionDbContext(IRepository<Auction> _auctionRepository, IRepository<AuctionBid> _auctionBidRepository)

View File

@ -0,0 +1,11 @@
using FruitBank.Common.Entities;
using FruitBank.Common.Interfaces;
using Mango.Nop.Core.Interfaces;
using Nop.Data;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
public interface IShippingDocumentDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<ShippingDocument>
{
public TDbTable ShippingDocuments { get; set; }
}

View File

@ -15,6 +15,8 @@ public class PartnerDbTable : MgDbTableBase<Partner>
{
}
public IQueryable<Partner> GetAll() => Table;
//public IOrderedQueryable<AuctionBid> GetAllLastBidByAuctionId(int auctionId)
//{
// return GetAllByAuctionId(auctionId)
@ -27,7 +29,7 @@ public class PartnerDbTable : MgDbTableBase<Partner>
// => GetAllByProductToAuctionId(productToAuctionId).OrderByDescending(x => x.Id);
//public Task<int> GetBidsCountByProductToAuctionIdAsync(int productToAuctionId)
// => Table.CountAsync(x => x.ProductAuctionMappingId == productToAuctionId);
// => Table.CountAsync(x => x.ProductAuctionMappingId == productToAuctionId);
//public IQueryable<AuctionBid> GetAllByAuctionId(int auctionId)
// => Table.Where(x => x.AuctionId == auctionId);

View File

@ -14,4 +14,6 @@ public class ShippingDbTable : MgDbTableBase<Shipping>
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
{
}
public IQueryable<Shipping> GetAll() => Table;
}

View File

@ -0,0 +1,19 @@
using FruitBank.Common.Entities;
using Mango.Nop.Core.Repositories;
using Nop.Core.Caching;
using Nop.Core.Configuration;
using Nop.Core.Events;
using Nop.Data;
using Nop.Services.Logging;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class ShippingDocumentDbTable : MgDbTableBase<ShippingDocument>
{
public ShippingDocumentDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
{
}
public IQueryable<ShippingDocument> GetAll() => Table;
}

View File

@ -14,4 +14,6 @@ public class ShippingItemDbTable : MgDbTableBase<ShippingItem>
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
{
}
public IQueryable<ShippingItem> GetAll() => Table;
}

View File

@ -50,8 +50,8 @@ namespace Nop.Plugin.Misc.FruitBankPlugin
// --- INSTALL ---
public override async Task InstallAsync()
{
// TODO: Add "NeedsToBeMeasured" product attribute if not exists
//TODO: Add "Measuring" role
//TODO: Add "NeedsToBeMeasured" product attribute if not exists
// Default settings
var settings = new OpenAiSettings

View File

@ -45,6 +45,7 @@ public class PluginNopStartup : INopStartup
services.AddScoped<PartnerDbTable>();
services.AddScoped<ShippingDbTable>();
services.AddScoped<ShippingItemDbTable>();
services.AddScoped<ShippingDocumentDbTable>();
services.AddScoped<FruitBankDbContext>();
services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>();