This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
326a87e
commit 4d6d5b4
Showing
12 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace RookieShop.Storefront.Areas.Product.Models.Products; | ||
|
||
public sealed class ProductPrice | ||
{ | ||
public decimal Price { get; set; } | ||
public decimal? PriceSale { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RookieShop.Storefront.Models.Report; | ||
|
||
public class BestSellerProduct | ||
{ | ||
[JsonPropertyName("productId")] public Guid ProductId { get; set; } | ||
|
||
[JsonPropertyName("productName")] public string? ProductName { get; set; } | ||
|
||
[JsonPropertyName("totalSoldQuantity")] | ||
public int TotalSoldQuantity { get; set; } | ||
|
||
[JsonPropertyName("imageUrl")] public string? ImageUrl { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Refit; | ||
|
||
namespace RookieShop.Storefront.Models.Report; | ||
|
||
public sealed class BestSellerProductFilterParams | ||
{ | ||
[AliasAs("top")] public int Top { get; set; } = 4; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RookieShop.Storefront.Models.Report; | ||
|
||
public sealed class BestSellerProductResponse : BestSellerProduct | ||
{ | ||
[JsonPropertyName("price")] | ||
public string Price { get; set; } = string.Empty; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using RookieShop.Storefront.Areas.Product.Models.Products; | ||
|
||
namespace RookieShop.Storefront.Models.Report; | ||
|
||
public sealed class BestSellerProductViewModel : BestSellerProduct | ||
{ | ||
public ProductPrice? Price { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Refit; | ||
using RookieShop.Storefront.Models.Report; | ||
|
||
namespace RookieShop.Storefront.Services; | ||
|
||
public interface IReportService | ||
{ | ||
[Get("/reports/best-seller-products")] | ||
Task <List<BestSellerProductResponse>> GetBestSellerProductsAsync([Query] BestSellerProductFilterParams filterParams); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
ui/storefront/Views/Shared/Components/FeatureProducts/Default.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@model List<RookieShop.Storefront.Models.Report.BestSellerProductViewModel> | ||
|
||
@if (Model.Count == 0) | ||
{ | ||
<div class="text-center text-red-500"> | ||
<strong>Warning!</strong> There are no products to show. | ||
</div> | ||
} | ||
else | ||
{ | ||
@foreach (var item in Model) | ||
{ | ||
<div class="group relative"> | ||
<div class="aspect-h-1 aspect-w-1 w-full overflow-hidden rounded-md bg-gray-200 lg:aspect-none group-hover:opacity-75"> | ||
<img loading="lazy" | ||
src="@(item.ImageUrl ?? "~/imgs/product/default-preview-image.png")" | ||
alt="@item.ProductName" | ||
class="h-full w-full" | ||
asp-append-version="true" /> | ||
</div> | ||
<div class="mt-4 flex justify-between"> | ||
<div> | ||
<h3 class="text-sm text-gray-700"> | ||
<span class="font-medium hover:text-gray-800"> | ||
<span aria-hidden="true" class="absolute inset-0"></span> | ||
@item.ProductName | ||
</span> | ||
</h3> | ||
</div> | ||
<a asp-area="Product" | ||
asp-controller="Product" | ||
asp-action="Detail" | ||
asp-route-id="@item.ProductId" | ||
class="text-sm font-medium text-gray-900 text-red-900"> | ||
Purchase | ||
</a> | ||
</div> | ||
</div> | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
ui/storefront/Views/Shared/Components/FeatureProducts/FeatureProductsViewComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Text.Json; | ||
using Microsoft.AspNetCore.Mvc; | ||
using RookieShop.Storefront.Areas.Product.Models.Products; | ||
using RookieShop.Storefront.Models.Report; | ||
using RookieShop.Storefront.Services; | ||
|
||
namespace RookieShop.Storefront.Views.Shared.Components.FeatureProducts; | ||
|
||
[ViewComponent] | ||
public sealed class FeatureProductsViewComponent(IReportService reportService) : ViewComponent | ||
{ | ||
public async Task<IViewComponentResult> InvokeAsync() | ||
{ | ||
var data = await reportService.GetBestSellerProductsAsync(new()); | ||
|
||
var result = data.Select(x => new BestSellerProductViewModel | ||
{ | ||
ProductId = x.ProductId, | ||
ProductName = x.ProductName, | ||
TotalSoldQuantity = x.TotalSoldQuantity, | ||
Price = JsonSerializer.Deserialize<ProductPrice>(x.Price), | ||
ImageUrl = x.ImageUrl | ||
}).ToList(); | ||
|
||
return View(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters