Skip to content

Commit

Permalink
[Front] v1.3.0 (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aloento authored Jan 23, 2024
1 parent 6401263 commit d031c06
Show file tree
Hide file tree
Showing 21 changed files with 815 additions and 663 deletions.
28 changes: 27 additions & 1 deletion TSystems.LoveOTC/AdminHub/Product/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace TSystems.LoveOTC.AdminHub;

using Microsoft.EntityFrameworkCore;
using Models;
using Z.EntityFramework.Plus;

internal partial class AdminHub {
/**
Expand Down Expand Up @@ -104,7 +105,7 @@ public async Task<bool> ProductDeleteType(uint variantId, string reqType) {
await this.deleteType(
await this.Db.Types
.Where(x => x.VariantId == variantId && x.Name == reqType)
.Include(x => x.Combos)
.IncludeOptimized(x => x.Combos)
.SingleAsync()
);

Expand Down Expand Up @@ -179,4 +180,29 @@ public async Task<bool> ProductDeleteProduct(uint prodId) {

return await this.Db.SaveChangesAsync() > 0;
}

/**
* <remarks>
* @author Aloento
* @since 1.2.0
* @version 0.1.0
* </remarks>
*/
public async Task<bool> ProductDetachCategory(uint prodId) {
var prod = await this.Db.Products
.SingleAsync(x => x.ProductId == prodId);

if (prod.CategoryId is null)
return false;

await this.Db.Categories
.Where(x =>
x.CategoryId == prod.CategoryId &&
x.Products.Count == 0)
.ExecuteDeleteAsync();

prod.CategoryId = null;

return await this.Db.SaveChangesAsync() > 0;
}
}
48 changes: 30 additions & 18 deletions TSystems.LoveOTC/AdminHub/Product/Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace TSystems.LoveOTC.AdminHub;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Models;
using Z.EntityFramework.Plus;

internal partial class AdminHub {
/**
Expand Down Expand Up @@ -35,7 +36,7 @@ public async Task<bool> ProductPatchName(uint prodId, string name) {
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 1.0.0
* @version 1.1.1
* </remarks>
*/
public async Task<bool> ProductPatchCategory(uint prodId, string name) {
Expand All @@ -46,23 +47,35 @@ public async Task<bool> ProductPatchCategory(uint prodId, string name) {
if (!valid.IsValid(name))
throw new HubException(valid.FormatErrorMessage("Name"));

var newCate = await this.Db.Categories
.Where(x => x.Name == name)
.SingleOrDefaultAsync()
?? (await this.Db.Categories.AddAsync(new() {
Name = name
})).Entity;
Product prod;
Category? newCate;

var prod = await this.Db.Products
.Include(x => x.Category)
.SingleAsync(x => x.ProductId == prodId);
{
var defProd = this.Db.Products
.DeferredSingle(x => x.ProductId == prodId)
.FutureValue();

var inUse = await this.Db.Products
.Where(x => x.CategoryId == prod.CategoryId && x.ProductId != prod.ProductId)
.AnyAsync();
var defNewCate = this.Db.Categories
.DeferredSingleOrDefault(x => x.Name == name)
.FutureValue();

if (!inUse)
this.Db.Categories.Remove(prod.Category!);
prod = await defProd.ValueAsync();
newCate = await defNewCate.ValueAsync();
}

if (prod.CategoryId is not null)
await this.Db.Categories
.Where(x =>
x.CategoryId == prod.CategoryId &&
x.Products.Count == 0)
.ExecuteDeleteAsync();

if (newCate is null)
newCate = (await this.Db.Categories.AddAsync(new() {
Name = name
})).Entity;
else if (prod.CategoryId == newCate.CategoryId)
return true;

prod.Category = newCate;

Expand Down Expand Up @@ -118,7 +131,6 @@ public async Task<bool> ProductPatchCaption(uint photoId, string caption) {
* <summary>
* Include Combos
* </summary>
*
* <remarks>
* @author Aloento
* @since 0.5.0
Expand Down Expand Up @@ -236,7 +248,7 @@ public async Task<bool> ProductPatchType(uint variantId, string oldName, string

if (any) {
var oldType = await type
.Include(x => x.Combos)
.IncludeOptimized(x => x.Combos)
.SingleAsync();

oldType.IsArchived = true;
Expand Down Expand Up @@ -292,7 +304,7 @@ public async Task<bool> ProductPatchCombo(uint comboId, Dictionary<string, strin
.Where(x => x.ProductId == queryCombo
.Select(c => c.ProductId)
.Single())
.Include(x => x.Types)
.IncludeOptimized(x => x.Types)
.Select(x => new {
x.Name,
x.Types
Expand Down
4 changes: 3 additions & 1 deletion TSystems.LoveOTC/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using TSystems.LoveOTC;
using TSystems.LoveOTC.AdminHub;
using TSystems.LoveOTC.Hub;
using Z.EntityFramework.Extensions;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -27,12 +28,13 @@
});

builder.Services.AddDbContext<ShopContext>(x => {
EntityFrameworkManager.IsCommunity = true;
if (Shared.Dev) {
x.EnableSensitiveDataLogging();

Check warning on line 34 in TSystems.LoveOTC/Program.cs

View workflow job for this annotation

GitHub Actions / Build and Deploy

Unreachable code detected
x.EnableDetailedErrors();
}
x.UseLazyLoadingProxies();
x.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"));
});

Expand Down
1 change: 1 addition & 0 deletions TSystems.LoveOTC/TSystems.LoveOTC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="8.101.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"update": "npx npm-check-updates -u"
},
"dependencies": {
"@fluentui/react-components": "^9.44.4",
"@fluentui/react-hooks": "^8.6.35",
"@fluentui/react-components": "^9.46.0",
"@fluentui/react-hooks": "^8.6.36",
"@fluentui/react-icons": "^2.0.225",
"@griffel/react": "^1.5.20",
"@lexical/clipboard": "0.10.0",
Expand Down Expand Up @@ -55,6 +55,6 @@
"@types/react-dom": "^18.2.18",
"@vitejs/plugin-react-swc": "^3.5.0",
"typescript": "^5.3.3",
"vite": "^5.0.11"
"vite": "^5.0.12"
}
}
Loading

0 comments on commit d031c06

Please sign in to comment.