Merge branch 'features/net21rc1' of https://github.com/dotnet/eShopOnContainers into features/net21rc1
This commit is contained in:
commit
1da9832a54
@ -1,5 +1,6 @@
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -7,7 +8,7 @@
|
||||
{
|
||||
Task<Order> GetOrderAsync(int id);
|
||||
|
||||
Task<IEnumerable<OrderSummary>> GetOrdersAsync();
|
||||
Task<IEnumerable<OrderSummary>> GetOrdersFromUserAsync(Guid userId);
|
||||
|
||||
Task<IEnumerable<CardType>> GetCardTypesAsync();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class OrderQueries
|
||||
:IOrderQueries
|
||||
: IOrderQueries
|
||||
{
|
||||
private string _connectionString = string.Empty;
|
||||
|
||||
@ -42,18 +42,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<OrderSummary>> GetOrdersAsync()
|
||||
public async Task<IEnumerable<OrderSummary>> GetOrdersFromUserAsync(Guid userId)
|
||||
{
|
||||
using (var connection = new SqlConnection(_connectionString))
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
return await connection.QueryAsync<OrderSummary>(@"SELECT o.[Id] as ordernumber,o.[OrderDate] as [date],os.[Name] as [status],SUM(oi.units*oi.unitprice) as total
|
||||
return await connection.QueryAsync<OrderSummary>(@"SELECT o.[Id] as ordernumber,o.[OrderDate] as [date],os.[Name] as [status], SUM(oi.units*oi.unitprice) as total
|
||||
FROM [ordering].[Orders] o
|
||||
LEFT JOIN[ordering].[orderitems] oi ON o.Id = oi.orderid
|
||||
LEFT JOIN[ordering].[orderstatus] os on o.OrderStatusId = os.Id
|
||||
LEFT JOIN[ordering].[buyers] ob on o.BuyerId = ob.Id
|
||||
WHERE ob.IdentityGuid = @userId
|
||||
GROUP BY o.[Id], o.[OrderDate], os.[Name]
|
||||
ORDER BY o.[Id]");
|
||||
ORDER BY o.[Id]", new { userId });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,8 +87,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
|
||||
[ProducesResponseType(typeof(IEnumerable<OrderSummary>), (int)HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetOrders()
|
||||
{
|
||||
var orders = await _orderQueries.GetOrdersAsync();
|
||||
|
||||
var userid = _identityService.GetUserIdentity();
|
||||
var orders = await _orderQueries.GetOrdersFromUserAsync(Guid.Parse(userid));
|
||||
return Ok(orders);
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ namespace UnitTest.Ordering.Application
|
||||
{
|
||||
//Arrange
|
||||
var fakeDynamicResult = Enumerable.Empty<OrderSummary>();
|
||||
_orderQueriesMock.Setup(x => x.GetOrdersAsync())
|
||||
_orderQueriesMock.Setup(x => x.GetOrdersFromUserAsync(Guid.NewGuid()))
|
||||
.Returns(Task.FromResult(fakeDynamicResult));
|
||||
|
||||
//Act
|
||||
|
Loading…
x
Reference in New Issue
Block a user