Skip to content

Commit

Permalink
[APP | CRUD] ProductGetList - [Front | Hub] ProductGetVariants / Name…
Browse files Browse the repository at this point in the history
… / Category (#53)

* 1

* GalleryGet

* EnsureConnected

* List

* Variants

* 1
  • Loading branch information
Aloento authored Oct 27, 2023
1 parent a48c3a6 commit 2e65b3a
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 169 deletions.
67 changes: 10 additions & 57 deletions TSystems.LoveOTC/AdminHub/Product/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,79 +7,32 @@ internal partial class AdminHub {
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 0.2.2
* @version 1.0.0
* </remarks>
*/
public async Task<ProductItem[]> ProductGetList() {
var raw = await this.Db.Products
public async Task<dynamic[]> ProductGetList() =>
await this.Db.Products
.Select(x => new {
x.ProductId,
Cover = x.Photos
.Where(p => p.Cover == true)
.Select(p => p.ObjectId)
.SingleOrDefault(),
x.Name,
x.Category,
Variant = (byte)x.Variants.Count,
Combo = (byte)x.Combos.Count,
Variant = x.Variants.Count,
Combo = x.Combos.Count,
Stock = x.Combos.Sum(s => s.Stock)
})
.ToArrayAsync();

return raw.Select(x => new ProductItem {
ProductId = x.ProductId,
Cover = x.Cover,
Name = x.Name,
Category = x.Category?.Name ?? "Pending",
Variant = x.Variant,
Combo = x.Combo,
Stock = (uint)x.Stock
}).ToArray();
}

/**
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 0.2.0
* </remarks>
*/
public async Task<string> ProductGetName(uint prodId) =>
await this.Db.Products
.Where(x => x.ProductId == prodId)
.Select(x => x.Name)
.SingleAsync();

/**
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 0.2.0
* @version 1.0.0
* </remarks>
*/
public async Task<string> ProductGetCategory(uint prodId) {
var cate = await this.Db.Products
.Where(x => x.ProductId == prodId)
.Select(x => x.Category)
.SingleAsync();

return cate?.Name ?? "Pending";
}

/**
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 0.2.0
* </remarks>
*/
public async Task<VariantItem[]> ProductGetVariants(uint prodId) =>
public async Task<dynamic[]> ProductGetVariants(uint prodId) =>
await this.Db.Variants
.Where(x => x.ProductId == prodId)
.Select(x => new VariantItem {
VariantId = x.VariantId,
Name = x.Name,
Types = x.Types.Select(t => t.Name).ToArray()
.Select(x => new {
x.VariantId,
Types = x.Types.Select(t => t.TypeId).ToArray()
})
.ToArrayAsync();
}
16 changes: 0 additions & 16 deletions TSystems.LoveOTC/Hub/Order/OrderComment.cs

This file was deleted.

14 changes: 0 additions & 14 deletions TSystems.LoveOTC/Hub/Order/OrderDetail.cs

This file was deleted.

2 changes: 1 addition & 1 deletion TSystems.LoveOTC/Hub/Product/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal partial class ShopHub {
.Where(x => x.ProductId == key)
.Select(x => new {
x.Name,
x.CategoryId,
Category = x.Category!.Name,
x.Description,
x.Version
})
Expand Down
2 changes: 1 addition & 1 deletion TSystems.LoveOTC/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
x.HandshakeTimeout = TimeSpan.FromSeconds(5);
x.SupportedProtocols = new[] { "messagepack" };
x.EnableDetailedErrors = Shared.Dev;
x.MaximumParallelInvocationsPerClient = sbyte.MaxValue;
x.MaximumParallelInvocationsPerClient = sbyte.MaxValue / 2;
}).AddMessagePackProtocol(x => {
x.SerializerOptions = MessagePackSerializerOptions.Standard
.WithSecurity(MessagePackSecurity.UntrustedData)
Expand Down
7 changes: 4 additions & 3 deletions src/Pages/Admin/Product/Category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { AdminHub } from "~/ShopNet/Admin";
* @version 0.1.0
*/
export function AdminProductCategory({ ProdId }: { ProdId: number; }) {
const [cate, setCate] = useState("");
const [cate, setCate] = useState<string>();
const [edit, { setTrue, setFalse }] = useBoolean();

useRequest(AdminHub.Product.Get.Category.bind(AdminHub.Product.Get), {
defaultParams: [ProdId],
onSuccess(data) {
setCate(data);
data && setCate(data);
}
});

Expand Down Expand Up @@ -49,11 +49,12 @@ export function AdminProductCategory({ ProdId }: { ProdId: number; }) {
size="large"
value={cate}
disabled={!edit}
placeholder="Pending"
appearance="underline"
onChange={(_, v) => setCate(v.value)}
contentBefore={<Subtitle2>Category</Subtitle2>}
contentAfter={edit
? <Button appearance="subtle" icon={<SendRegular />} onClick={() => run(ProdId, cate)} />
? <Button appearance="subtle" icon={<SendRegular />} onClick={() => cate && run(ProdId, cate)} />
: <Button appearance="subtle" icon={<EditRegular />} onClick={setTrue} />}
/>
);
Expand Down
10 changes: 0 additions & 10 deletions src/ShopNet/Admin/AdminNet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,4 @@ export abstract class AdminNet extends SignalR {
.withHubProtocol(new MessagePackHubProtocol())
.configureLogging(import.meta.env.DEV ? LogLevel.Debug : LogLevel.Information)
.build();

/**
* @author Aloento
* @since 1.0.0
* @version 0.1.0
*/
public static async EnsureAdmin() {
this.EnsureLogin();
await this.EnsureConnected();
}
}
2 changes: 1 addition & 1 deletion src/ShopNet/Admin/Order/Get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class AdminOrderGet extends AdminNet {
* @version 0.1.0
*/
public static async List(): Promise<IOrderItem[]> {
await this.EnsureAdmin();
await this.EnsureConnected();
const res = await this.Hub.invoke<Omit<IOrderItem & { OrderId: number }, "Id">[]>("OrderGetList");

return res.map(x => {
Expand Down
6 changes: 3 additions & 3 deletions src/ShopNet/Admin/Order/Post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class AdminOrderPost extends AdminNet {
* @version 0.1.0
*/
public static async Append(orderId: number, cmt: string): Promise<true> {
await this.EnsureAdmin();
await this.EnsureConnected();
const res = await this.Hub.invoke<true>("OrderPostAppend", orderId, cmt);
return res;
}
Expand All @@ -23,7 +23,7 @@ export class AdminOrderPost extends AdminNet {
* @version 0.1.0
*/
public static async Close(orderId: number, reason: string): Promise<true> {
await this.EnsureAdmin();
await this.EnsureConnected();
const res = await this.Hub.invoke<true>("OrderPostClose", orderId, reason);
return res;
}
Expand All @@ -34,7 +34,7 @@ export class AdminOrderPost extends AdminNet {
* @version 0.1.0
*/
public static async Ship(orderId: number, track?: string): Promise<true> {
await this.EnsureAdmin();
await this.EnsureConnected();
const res = await this.Hub.invoke<true>("OrderPostShip", orderId, track);
return res;
}
Expand Down
10 changes: 5 additions & 5 deletions src/ShopNet/Admin/Product/Delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class AdminProductDelete extends AdminNet {
* @version 0.1.0
*/
public static async Photo(photoId: number): Promise<true> {
await this.EnsureAdmin();
await this.EnsureConnected();
const res = await this.Hub.invoke<true>("ProductDeletePhoto", photoId);
return res;
}
Expand All @@ -23,7 +23,7 @@ export class AdminProductDelete extends AdminNet {
* @version 0.1.0
*/
public static async Variant(variantId: number): Promise<true> {
await this.EnsureAdmin();
await this.EnsureConnected();
const res = await this.Hub.invoke<true>("ProductDeleteVariant", variantId);
return res;
}
Expand All @@ -34,7 +34,7 @@ export class AdminProductDelete extends AdminNet {
* @version 0.1.0
*/
public static async Type(variantId: number, type: string): Promise<true> {
await this.EnsureAdmin();
await this.EnsureConnected();
const res = await this.Hub.invoke<true>("ProductDeleteType", variantId, type);
return res;
}
Expand All @@ -45,7 +45,7 @@ export class AdminProductDelete extends AdminNet {
* @version 0.1.0
*/
public static async Combo(comboId: number): Promise<true> {
await this.EnsureAdmin();
await this.EnsureConnected();
const res = await this.Hub.invoke<true>("ProductDeleteCombo", comboId);
return res;
}
Expand All @@ -56,7 +56,7 @@ export class AdminProductDelete extends AdminNet {
* @version 0.1.0
*/
public static async Product(prodId: number): Promise<true> {
await this.EnsureAdmin();
await this.EnsureConnected();
const res = await this.Hub.invoke<true>("ProductDeleteProduct", prodId);
return res;
}
Expand Down
Loading

0 comments on commit 2e65b3a

Please sign in to comment.