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
e46f73e
commit 22f2f07
Showing
13 changed files
with
83 additions
and
60 deletions.
There are no files selected for viewing
14 changes: 8 additions & 6 deletions
14
src/RookieShop.ApiService/Endpoints/Reports/BestSellerProducts.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 |
---|---|---|
@@ -1,31 +1,33 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Http.HttpResults; | ||
using RookieShop.Application.Reports.DTOs; | ||
using RookieShop.ApiService.ViewModels.Reports; | ||
using RookieShop.Application.Reports.Queries.BestSellerProducts; | ||
using RookieShop.Infrastructure.Endpoints.Abstractions; | ||
using RookieShop.Infrastructure.RateLimiter; | ||
|
||
namespace RookieShop.ApiService.Endpoints.Reports; | ||
|
||
public sealed class BestSellerProducts(ISender sender) | ||
: IEndpoint<Ok<List<BestSellerProductsDto>>, BestSellerProductsRequest> | ||
: IEndpoint<Ok<List<BestSellerProductsVm>>, BestSellerProductsRequest> | ||
{ | ||
public void MapEndpoint(IEndpointRouteBuilder app) => | ||
app.MapGet("/reports/best-seller-products", | ||
async (int top) => await HandleAsync(new(top))) | ||
.Produces<Ok<List<BestSellerProductsDto>>>() | ||
.Produces<Ok<List<BestSellerProductsVm>>>() | ||
.WithTags(nameof(Reports)) | ||
.WithName("Best Seller Products") | ||
.MapToApiVersion(new(1, 0)) | ||
.RequirePerUserRateLimit(); | ||
|
||
public async Task<Ok<List<BestSellerProductsDto>>> HandleAsync(BestSellerProductsRequest request, | ||
public async Task<Ok<List<BestSellerProductsVm>>> HandleAsync(BestSellerProductsRequest request, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
BestSellerProductsQuery query = new(request.Top); | ||
|
||
var result = await sender.Send(query, cancellationToken); | ||
var data = await sender.Send(query, cancellationToken); | ||
|
||
return TypedResults.Ok(result.Value.ToList()); | ||
var result = data.Value.ToBestSellerProductsVm(); | ||
|
||
return TypedResults.Ok(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
11 changes: 11 additions & 0 deletions
11
src/RookieShop.ApiService/ViewModels/Reports/BestSellerProductsVm.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,11 @@ | ||
using RookieShop.Domain.Entities.ProductAggregator.ValueObjects; | ||
|
||
namespace RookieShop.ApiService.ViewModels.Reports; | ||
|
||
public sealed record BestSellerProductsVm( | ||
Guid ProductId, | ||
string? ProductName, | ||
int TotalSoldQuantity, | ||
ProductPrice? Price, | ||
string? ImageUrl | ||
); |
24 changes: 24 additions & 0 deletions
24
src/RookieShop.ApiService/ViewModels/Reports/DtoToViewModelMapper.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,24 @@ | ||
using System.Text.Json; | ||
using RookieShop.Application.Reports.DTOs; | ||
using RookieShop.Domain.Entities.ProductAggregator.ValueObjects; | ||
|
||
namespace RookieShop.ApiService.ViewModels.Reports; | ||
|
||
public static class DtoToViewModelMapper | ||
{ | ||
public static BestSellerProductsVm ToBestSellerProductsVm(this BestSellerProductsDto bestSellerProductsDto) | ||
{ | ||
var price = JsonSerializer.Deserialize<ProductPrice>(bestSellerProductsDto.Price); | ||
|
||
return new( | ||
bestSellerProductsDto.ProductId, | ||
bestSellerProductsDto.ProductName, | ||
bestSellerProductsDto.TotalSoldQuantity, | ||
price, | ||
bestSellerProductsDto.ImageUrl | ||
); | ||
} | ||
|
||
public static List<BestSellerProductsVm> ToBestSellerProductsVm(this IEnumerable<BestSellerProductsDto> bestSellerProductsDtos) => | ||
bestSellerProductsDtos.Select(ToBestSellerProductsVm).ToList(); | ||
} |
5 changes: 4 additions & 1 deletion
5
src/RookieShop.Application/Reports/DTOs/BestSellerProductsDto.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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
namespace RookieShop.Application.Reports.DTOs; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RookieShop.Application.Reports.DTOs; | ||
|
||
public sealed class BestSellerProductsDto | ||
{ | ||
public Guid ProductId { get; set; } | ||
public string? ProductName { get; set; } | ||
public int TotalSoldQuantity { get; set; } | ||
[JsonRequired] | ||
public string Price { get; set; } = string.Empty; | ||
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
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
namespace RookieShop.Storefront.Areas.Product.Models.Products; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RookieShop.Storefront.Areas.Product.Models.Products; | ||
|
||
public sealed class ProductPrice | ||
{ | ||
[JsonPropertyName("price")] | ||
public decimal Price { get; set; } | ||
|
||
[JsonPropertyName("priceSale")] | ||
public decimal? PriceSale { get; set; } | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,19 @@ | ||
using RookieShop.Storefront.Areas.Product.Models.Products; | ||
using System.Text.Json.Serialization; | ||
using RookieShop.Storefront.Areas.Product.Models.Products; | ||
|
||
namespace RookieShop.Storefront.Models.Report; | ||
|
||
public sealed class BestSellerProductViewModel : BestSellerProduct | ||
public sealed class BestSellerProductViewModel | ||
{ | ||
[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; } | ||
|
||
[JsonPropertyName("price")] | ||
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
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