Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
The most significant changes involve modifications to the handling of…
Browse files Browse the repository at this point in the history
… product combos in the code. The `Entity.cs` file now filters out archived products, types, variants, and combos in the `ShopHub` class, and a new method `ComboEntity` has been added. The `ProductGetComboList` method in `Get.cs` has been altered to return a list of combo IDs instead of combo details, and it now also filters out archived combos. In `index.tsx` and `RadioList.tsx`, the method `Hub.Product.Get.Combo` has been replaced with `Hub.Product.Get.ComboItem`. New type `Combo` and a new method `Combo` have been added to the `ProductData` class in `Data.ts`. The `Combo` method in `ProductGet` class in `Get.ts` has been renamed to `ComboItem` and modified to fetch combo details using the new `Combo` method in `ProductData` class. The method now also handles errors when a type or variant is not found. The `ComboList` method in `ProductGet` class in `Get.ts` has been modified to return a list of combo IDs instead of combo details. Lastly, the `GetTimeCache` method in `SignalR.ts` has been marked as deprecated.

List of changes:

1. `Entity.cs` now filters out archived products, types, variants, and combos in the `ShopHub` class, and a new method `ComboEntity` has been added.
2. `ProductGetComboList` method in `Get.cs` now returns a list of combo IDs and filters out archived combos.
3. `Hub.Product.Get.Combo` method has been replaced with `Hub.Product.Get.ComboItem` in `index.tsx` and `RadioList.tsx`.
4. New type `Combo` and a new method `Combo` have been added to the `ProductData` class in `Data.ts`.
5. `Combo` method in `ProductGet` class in `Get.ts` has been renamed to `ComboItem` and fetches combo details using the new `Combo` method in `ProductData` class. It also handles errors when a type or variant is not found.
6. `ComboList` method in `ProductGet` class in `Get.ts` now returns a list of combo IDs instead of combo details.
7. `GetTimeCache` method in `SignalR.ts` has been marked as deprecated.
  • Loading branch information
Aloento committed Feb 8, 2024
1 parent dc06cd1 commit dce40a1
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 22 deletions.
30 changes: 30 additions & 0 deletions SoarCraft.AwaiShop/Hub/Product/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal partial class ShopHub {

return await this.Db.Products
.Where(x => x.ProductId == key)
.Where(x => x.IsArchived != true)
.Select(x => new {
x.Name,
Category = x.Category!.Name,
Expand All @@ -45,6 +46,7 @@ internal partial class ShopHub {

return await this.Db.Products
.Where(x => x.ProductId == key)
.Where(x => x.IsArchived != true)
.Select(x => new {
x.Description,
x.Version
Expand Down Expand Up @@ -89,6 +91,7 @@ internal partial class ShopHub {

return await this.Db.Types
.Where(x => x.TypeId == key)
.Where(x => x.IsArchived != true)
.Select(x => new {
x.Name,
x.VariantId,
Expand All @@ -114,11 +117,38 @@ internal partial class ShopHub {

return await this.Db.Variants
.Where(x => x.VariantId == key)
.Where(x => x.IsArchived != true)
.Select(x => new {
x.Name,
x.ProductId,
x.Version
})
.SingleOrDefaultAsync();
}

/**
* <remarks>
* @author Aloento
* @since 1.3.0
* @version 0.1.0
* </remarks>
*/
public async Task<dynamic?> ComboEntity(uint key, uint? version) {
if (version is not null) {
var noChange = await this.Db.Combos
.AnyAsync(x => x.ComboId == key && x.Version == version);

if (noChange) return true;
}

return await this.Db.Combos
.Where(x => x.ComboId == key)
.Where(x => x.IsArchived != true)
.Select(x => new {
x.Stock,
Types = x.Types.Select(t => t.TypeId).ToArray(),
x.Version
})
.SingleOrDefaultAsync();
}
}
13 changes: 5 additions & 8 deletions SoarCraft.AwaiShop/Hub/Product/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ internal partial class ShopHub {
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 1.0.0
* @version 1.1.0
* </remarks>
*/
public async Task<dynamic[]> ProductGetComboList(uint prodId) =>
await this.Db.Combos
public Task<uint[]> ProductGetComboList(uint prodId) =>
this.Db.Combos
.Where(x => x.ProductId == prodId)
.Select(x => new {
x.ComboId,
x.Stock,
Types = x.Types.Select(t => t.TypeId).ToArray()
})
.Where(x => x.IsArchived != true)
.Select(x => x.ComboId)
.ToArrayAsync();

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Admin/Product/Combo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const columns: TableColumnDefinition<IDetailComboItem>[] = [
* @version 0.2.2
*/
export function AdminProductCombo({ ProdId }: { ProdId: number }) {
const { data, run } = useRequest(() => Hub.Product.Get.Combo(ProdId, log), {
const { data, run } = useRequest(() => Hub.Product.Get.ComboItem(ProdId, log), {
onError: log.error
});

Expand Down
2 changes: 1 addition & 1 deletion src/Pages/Product/RadioList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function ProductRadioList({ ProdId }: { ProdId: number }) {
const { Update, SetAll } = useRadioGroup();
const [variants, setVariants] = useState<[string, string[]][]>([]);

const { loading } = useRequest(() => Hub.Product.Get.Combo(ProdId, log), {
const { loading } = useRequest(() => Hub.Product.Get.ComboItem(ProdId, log), {
onError: log.error,
onSuccess(data) {
const variant: Record<string, Set<string>> = {};
Expand Down
15 changes: 15 additions & 0 deletions src/ShopNet/Product/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export namespace ProductData {
Name: string;
ProductId: number;
} & IConcurrency;

export type Combo = {
Stock: number;
Types: number[];
} & IConcurrency;
}

/**
Expand Down Expand Up @@ -94,4 +99,14 @@ export abstract class ProductData extends ShopNet {
public static Variant(key: number): Promise<ProductData.Variant> {
return this.GetVersionCache(key, "VariantEntity");
}

/**
* @author Aloento
* @since 1.3.5
* @version 0.1.0
* @liveSafe
*/
public static Combo(key: number): Promise<ProductData.Combo> {
return this.GetVersionCache(key, "ComboEntity");
}
}
22 changes: 10 additions & 12 deletions src/ShopNet/Product/Get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,38 +53,40 @@ export abstract class ProductGet extends ProductData {
/**
* @author Aloento
* @since 0.5.0
* @version 1.0.1
* @version 1.1.0
* @liveSafe
*/
public static async Combo(prodId: number, pLog: Logger): Promise<IComboItem[]> {
public static async ComboItem(prodId: number, pLog: Logger): Promise<IComboItem[]> {
const log = pLog.With(...this.Log, "Combo");

const list = await this.ComboList(prodId);
const items: IComboItem[] = [];

for (const combo of list) {
for (const comboId of list) {
const combo = await this.Combo(comboId);

const variType: Record<string, string> = {};

for (const typeId of combo.Types) {
const type = await this.Type(typeId);

if (!type) {
log.error(`[Mismatch] Type ${typeId} not found. Combo ${combo.ComboId} : Product ${prodId}`);
log.error(`[Mismatch] Type ${typeId} not found. Combo ${comboId} : Product ${prodId}`);
continue;
}

const vari = await this.Variant(type.VariantId);

if (!vari) {
log.error(`[Mismatch] Variant ${type.VariantId} not found. Combo ${combo.ComboId} : Type ${typeId} : Product ${prodId}`);
log.error(`[Mismatch] Variant ${type.VariantId} not found. Combo ${comboId} : Type ${typeId} : Product ${prodId}`);
continue;
}

variType[vari.Name] = type.Name;
}

items.push({
Id: combo.ComboId,
Id: comboId,
Stock: combo.Stock,
Combo: variType,
});
Expand All @@ -96,14 +98,10 @@ export abstract class ProductGet extends ProductData {
/**
* @author Aloento
* @since 1.0.0
* @version 0.1.0
* @version 1.0.0
* @liveSafe
*/
public static ComboList(prodId: number): Promise<{
ComboId: number;
Stock: number;
Types: number[];
}[]> {
public static ComboList(prodId: number): Promise<number[]> {
return this.GetTimeCache(prodId, "ProductGetComboList", (x) => x.add(1, "m"), prodId);
}

Expand Down
1 change: 1 addition & 0 deletions src/ShopNet/SignalR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export abstract class SignalR {
* @since 1.0.0
* @version 0.2.0
* @liveSafe
* @deprecated
*/
protected static async GetTimeCache<T>(
this: INet, key: string | number, methodName: string, exp: (now: Dayjs) => Dayjs, ...args: any[]
Expand Down

0 comments on commit dce40a1

Please sign in to comment.