Skip to content

Commit

Permalink
[APP | Read] CommentEntity - [APP | CRUD] OrderGetDetail - [Front | H…
Browse files Browse the repository at this point in the history
…ub] FindCover (#52)

* Comment

* OrderGetDetail

* FindCover

* Detail

* User
  • Loading branch information
Aloento authored Oct 27, 2023
1 parent da6f418 commit a48c3a6
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 2,545 deletions.
27 changes: 27 additions & 0 deletions TSystems.LoveOTC/Hub/Order/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,31 @@ internal partial class ShopHub {
})
.SingleOrDefaultAsync();
}

/**
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.1.1
* </remarks>
*/
[Authorize]
public async Task<dynamic?> CommentEntity(uint key, uint? version) {
if (version is not null) {
var noChange = await this.Db.Comments
.AnyAsync(x => x.CommentId == key && x.Version == version);

if (noChange) return true;
}

return await this.Db.Comments
.Where(x => x.CommentId == key && x.Order.UserId == this.UserId)
.Select(x => new {
x.Content,
x.User!.Name,
x.CreateAt,
x.Version
})
.SingleOrDefaultAsync();
}
}
41 changes: 10 additions & 31 deletions TSystems.LoveOTC/Hub/Order/Get.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace TSystems.LoveOTC.Hub;

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

Expand All @@ -27,47 +26,27 @@ await this.Db.Orders
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.1.0
* @version 1.0.0
* </remarks>
*/
[Authorize]
public async Task<OrderDetail> OrderGetDetail(uint orderId) {
var cartDb = await this.Db.OrderCombos
public async Task<dynamic> OrderGetDetail(uint orderId) {
var items = await this.Db.OrderCombos
.Where(x => x.OrderId == orderId && x.Order.UserId == this.UserId)
.Select(x => new {
ProdId = x.Combo.ProductId,
Cover = x.Combo.Product.Photos
.Where(p => p.Cover == true)
.Select(p => p.ObjectId)
.Single(),
x.Combo.Product.Name,
Type = x.Combo.Types
.Select(t => KeyValuePair.Create(t.Variant.Name, t.Name))
.ToArray(),
x.Quantity
x.Quantity,
Types = x.Combo.Types.Select(t => t.TypeId).ToArray()
})
.ToArrayAsync();

var cmtDb = await this.Db.Comments
var cmts = await this.Db.Comments
.Where(x => x.OrderId == orderId && x.Order.UserId == this.UserId)
.Select(x => new OrderComment {
Content = x.Content,
Time = x.CreateAt,
User = x.User!.Name
})
.Select(x => x.CommentId)
.ToArrayAsync();

return new() {
ShopCart = cartDb
.Select(x => new CartItem {
ProdId = x.ProdId,
Cover = x.Cover,
Name = x.Name,
Type = x.Type.ToImmutableDictionary(k => k.Key, v => v.Value),
Quantity = x.Quantity
})
.ToImmutableArray(),
Comments = cmtDb
return new {
Items = items,
Comments = cmts
};
}
}
16 changes: 0 additions & 16 deletions TSystems.LoveOTC/Hub/Order/OrderExtension.cs

This file was deleted.

8 changes: 7 additions & 1 deletion TSystems.LoveOTC/Hub/Order/OrderItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ namespace TSystems.LoveOTC.Hub;
* @version 0.1.0
* </remarks>
*/
internal record OrderItem : OrderExtension {
internal record OrderItem {
public required uint OrderId { get; init; }

public required ICollection<string> Items { get; init; }

public required ushort Quantity { get; init; }

public required string Status { get; init; }

public string? TrackNumber { get; init; }

public required DateTime OrderDate { get; init; }
}
Loading

0 comments on commit a48c3a6

Please sign in to comment.