Skip to content

Commit

Permalink
[APP | Read] OrderEntity - [APP | CRUD] OrderGetList - [Front | DB] C…
Browse files Browse the repository at this point in the history
…ommon & AccessToken (#51)

* 1

* Common

* AccessToken

* OrderGetList

* remove OrderGetExtension
  • Loading branch information
Aloento authored Oct 27, 2023
1 parent 0771745 commit da6f418
Show file tree
Hide file tree
Showing 19 changed files with 600 additions and 495 deletions.
32 changes: 32 additions & 0 deletions TSystems.LoveOTC/AdminHub/Order/Entity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace TSystems.LoveOTC.AdminHub;

using Microsoft.EntityFrameworkCore;

internal partial class AdminHub {
/**
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.1.0
* </remarks>
*/
public async Task<dynamic?> OrderEntity(uint key, uint? version) {
if (version is not null) {
var noChange = await this.Db.Orders
.AnyAsync(x => x.OrderId == key && x.Version == version);

if (noChange) return true;
}

return await this.Db.Orders
.Where(x => x.OrderId == key)
.Select(x => new {
x.UserId,
Status = Enum.GetName(x.Status)!,
x.CreateAt,
x.TrackingNumber,
x.Version
})
.SingleOrDefaultAsync();
}
}
33 changes: 33 additions & 0 deletions TSystems.LoveOTC/Hub/Order/Entity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace TSystems.LoveOTC.Hub;

using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;

internal partial class ShopHub {
/**
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.1.0
* </remarks>
*/
[Authorize]
public async Task<dynamic?> OrderEntity(uint key, uint? version) {
if (version is not null) {
var noChange = await this.Db.Orders
.AnyAsync(x => x.OrderId == key && x.Version == version);

if (noChange) return true;
}

return await this.Db.Orders
.Where(x => x.OrderId == key && x.UserId == this.UserId)
.Select(x => new {
Status = Enum.GetName(x.Status)!,
x.CreateAt,
x.TrackingNumber,
x.Version
})
.SingleOrDefaultAsync();
}
}
32 changes: 6 additions & 26 deletions TSystems.LoveOTC/Hub/Order/Get.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace TSystems.LoveOTC.Hub;

using System.Collections.Immutable;
using Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;

Expand All @@ -10,20 +9,17 @@ internal partial class ShopHub {
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 0.2.0
* @version 1.0.0
* </remarks>
*/
[Authorize]
public async Task<OrderItem[]> OrderGetList() =>
public async Task<dynamic[]> OrderGetList() =>
await this.Db.Orders
.Where(x => x.UserId == this.UserId)
.Select(x => new OrderItem {
OrderId = x.OrderId,
Items = x.Combos.Select(c => c.Product.Name).ToArray(),
Quantity = (ushort)x.OrderCombos.Sum(o => o.Quantity),
OrderDate = x.CreateAt,
TrackNumber = x.TrackingNumber,
Status = Enum.GetName(x.Status)!
.Select(x => new {
x.OrderId,
Products = x.Combos.Select(c => c.ProductId).ToArray(),
Quantity = (ushort)x.OrderCombos.Sum(o => o.Quantity)
})
.ToArrayAsync();

Expand Down Expand Up @@ -74,20 +70,4 @@ public async Task<OrderDetail> OrderGetDetail(uint orderId) {
Comments = cmtDb
};
}

/**
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 0.1.0
* </remarks>
*/
[Authorize]
public async Task<OrderExtension> OrderGetExtension(uint orderId) {
return new() {
OrderDate = DateTime.Now,
TrackNumber = "Number123456789",
Status = Enum.GetName(OrderStatus.Finished)!
};
}
}
1 change: 1 addition & 0 deletions TSystems.LoveOTC/Hub/Product/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ internal partial class ShopHub {
.Where(x => x.VariantId == key)
.Select(x => new {
x.Name,
x.ProductId,
x.Version
})
.SingleOrDefaultAsync();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"devDependencies": {
"@types/lodash-es": "^4.17.10",
"@types/react": "^18.2.32",
"@types/react": "^18.2.33",
"@types/react-dom": "^18.2.14",
"@vitejs/plugin-react-swc": "^3.4.0",
"typescript": "^5.2.2",
Expand Down
Loading

0 comments on commit da6f418

Please sign in to comment.