Skip to content

Commit 68bcb70

Browse files
Added OrderItem features and moved queries to the OrderingQueries class
1 parent 1ba7087 commit 68bcb70

14 files changed

Lines changed: 546 additions & 94 deletions

File tree

src/Services/Ordering/Ordering.API/Controllers/OrderingController.cs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,16 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Controllers
1515
[Route("api/[controller]")]
1616
public class OrderingController : Controller
1717
{
18-
private OrderingDbContext _context;
1918
private IOrderRepository _orderRepository;
2019
private OrderingQueries _queries;
2120

2221
public OrderingController(IOrderRepository orderRepository,
23-
OrderingQueries orderingQueries,
24-
OrderingDbContext context)
22+
OrderingQueries orderingQueries
23+
)
2524
{
2625
//Injected objects from the IoC container
2726
_orderRepository = orderRepository;
2827
_queries = orderingQueries;
29-
30-
_context = context;
3128
}
3229

3330

@@ -42,28 +39,9 @@ public async Task<IActionResult> GetAllOrders()
4239

4340
// GET api/ordering/orders/xxxGUIDxxxx
4441
[HttpGet("orders/{orderId:Guid}")]
45-
public async Task<IActionResult> GetOrderByGuid(Guid orderId)
42+
public async Task<IActionResult> GetOrderById(Guid orderId)
4643
{
47-
//var order = await _orderRepository.Get(orderId);
48-
49-
var order = await _context.Orders
50-
.Include(o => o.ShippingAddress)
51-
.Include(o => o.BillingAddress)
52-
.Where(o => o.Id == orderId)
53-
.SingleOrDefaultAsync<Order>();
54-
55-
// Dynamically generated a Response-Model that includes only the fields you need in the response.
56-
// This keeps the JSON response minimal.
57-
// Could also use var
58-
dynamic response = new
59-
{
60-
id = order.Id,
61-
orderDate = order.OrderDate,
62-
shippingAddress = order.ShippingAddress,
63-
billingAddress = order.BillingAddress,
64-
//items = order.Items.Select(i => i.Content)
65-
};
66-
44+
dynamic response = await _queries.GetOrderById(orderId);
6745
return Ok(response);
6846
}
6947

src/Services/Ordering/Ordering.API/Migrations/20160913052800_Migration4.Designer.cs

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.EntityFrameworkCore.Migrations;
4+
5+
namespace Ordering.API.Migrations
6+
{
7+
public partial class Migration4 : Migration
8+
{
9+
protected override void Up(MigrationBuilder migrationBuilder)
10+
{
11+
migrationBuilder.EnsureSchema(
12+
name: "shared");
13+
14+
migrationBuilder.CreateSequence<int>(
15+
name: "OrderSequences",
16+
schema: "shared",
17+
startValue: 1001L);
18+
19+
migrationBuilder.AddColumn<int>(
20+
name: "SequenceNumber",
21+
table: "Orders",
22+
nullable: false,
23+
defaultValueSql: "NEXT VALUE FOR shared.OrderSequences");
24+
}
25+
26+
protected override void Down(MigrationBuilder migrationBuilder)
27+
{
28+
migrationBuilder.DropSequence(
29+
name: "OrderSequences",
30+
schema: "shared");
31+
32+
migrationBuilder.DropColumn(
33+
name: "SequenceNumber",
34+
table: "Orders");
35+
}
36+
}
37+
}

src/Services/Ordering/Ordering.API/Migrations/20160913061710_Migration5.Designer.cs

Lines changed: 121 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Microsoft.EntityFrameworkCore.Migrations;
4+
5+
namespace Ordering.API.Migrations
6+
{
7+
public partial class Migration5 : Migration
8+
{
9+
protected override void Up(MigrationBuilder migrationBuilder)
10+
{
11+
migrationBuilder.CreateTable(
12+
name: "OrderItem",
13+
columns: table => new
14+
{
15+
Id = table.Column<Guid>(nullable: false),
16+
Discount = table.Column<decimal>(nullable: false),
17+
FulfillmentRemaining = table.Column<int>(nullable: false),
18+
OrderId = table.Column<Guid>(nullable: false),
19+
ProductId = table.Column<Guid>(nullable: false),
20+
Quantity = table.Column<int>(nullable: false),
21+
UnitPrice = table.Column<decimal>(nullable: false)
22+
},
23+
constraints: table =>
24+
{
25+
table.PrimaryKey("PK_OrderItem", x => x.Id);
26+
table.ForeignKey(
27+
name: "FK_OrderItem_Orders_OrderId",
28+
column: x => x.OrderId,
29+
principalTable: "Orders",
30+
principalColumn: "Id",
31+
onDelete: ReferentialAction.Cascade);
32+
});
33+
34+
migrationBuilder.CreateIndex(
35+
name: "IX_OrderItem_OrderId",
36+
table: "OrderItem",
37+
column: "OrderId");
38+
}
39+
40+
protected override void Down(MigrationBuilder migrationBuilder)
41+
{
42+
migrationBuilder.DropTable(
43+
name: "OrderItem");
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)