Skip to content
This repository was archived by the owner on Mar 10, 2023. It is now read-only.

Commit c5d0a99

Browse files
author
Tim Hess
committed
checkpoint
1 parent c717344 commit c5d0a99

30 files changed

+358
-139
lines changed

src/funstore.service.cart/Controllers/CartController.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ type CartController () =
4040
// DELETE api/cart/5
4141
[<HttpDelete("{id}")>]
4242
member this.Delete(id:Guid) =
43-
Carts.Remove(Carts.Find(fun i -> i.GetId() = id))
43+
let c = Carts.Find(fun _i -> _i.GetId() = id)
44+
c.Clear()
4445

src/funstore.service.cart/Program.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open Microsoft.Extensions.Logging
66
open Pivotal.Extensions.Configuration.ConfigServer
77
open Steeltoe.Extensions.Logging
88
open System
9+
open System.IO
910

1011
module Program =
1112
let exitCode = 0
@@ -14,10 +15,11 @@ module Program =
1415
(new WebHostBuilder())
1516
.UseKestrel()
1617
.UseCloudFoundryHosting()
18+
.UseContentRoot(Directory.GetCurrentDirectory())
1719
.ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder>(fun _builder config ->
1820
let env = _builder.HostingEnvironment
1921
config.SetBasePath(env.ContentRootPath)
20-
.AddJsonFile("appsettings.json", true, true)
22+
.AddJsonFile("appsettings.json", false, true)
2123
.AddJsonFile("appsettings.Development.json", true)
2224
.AddEnvironmentVariables()
2325
.AddConfigServer() |> ignore

src/funstore.service.cart/appsettings.Development.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"Default": "Debug",
55
"Funstore": "Trace",
66
"System": "Information",
7-
"Microsoft": "Information"
7+
"Microsoft": "Information",
8+
"Steeltoe": "Trace"
89
}
910
},
1011
"eureka": {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace Funstore.Service.Order.Controllers
7+
{
8+
[Route("[controller]")]
9+
[ApiController]
10+
public class OrderController : Controller
11+
{
12+
private static List<Shared.csharp.Order> Orders = new List<Shared.csharp.Order>();
13+
14+
// GET api/values
15+
[HttpGet("history/{cartId}")]
16+
public IEnumerable<Shared.csharp.Order> History(Guid cartId)
17+
{
18+
return Orders.Where(o => o.CartId == cartId);
19+
}
20+
21+
// GET api/values/5
22+
[HttpGet("{id}")]
23+
public Shared.csharp.Order Get(int id)
24+
{
25+
return Orders.Find(o => o.Id == id);
26+
}
27+
28+
// POST api/values
29+
[HttpPost]
30+
public ActionResult Post([FromBody] Shared.csharp.Order request)
31+
{
32+
var newOrder = new Shared.csharp.Order { CartId = request.CartId, Items = request.Items, OrderPlaced = DateTime.Now, Id = Orders.Count + 1 };
33+
Orders.Add(newOrder);
34+
return Json(newOrder);
35+
}
36+
37+
// PUT api/values/5
38+
[HttpPut("{id}")]
39+
public void Put(int id, [FromBody] string value)
40+
{
41+
}
42+
43+
// DELETE api/values/5
44+
[HttpDelete("{id}")]
45+
public void Delete(int id)
46+
{
47+
}
48+
}
49+
}

src/funstore.service.order/funstore.service.order.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@
2121
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.1.0-preview1-final" />
2222
</ItemGroup>
2323

24+
<ItemGroup>
25+
<ProjectReference Include="..\funstore.shared.csharp\funstore.shared.csharp.csproj" />
26+
<ProjectReference Include="..\funstore.shared.fsharp\funstore.shared.fsharp.fsproj" />
27+
</ItemGroup>
28+
2429
</Project>

src/funstore.shared.csharp/CartItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ public class CartItem
1313
public int Count { get; set; } = 1;
1414

1515
public DateTime DateCreated { get; set; }
16+
17+
public InventoryItem Item { get; set; }
1618
}
1719
}

src/funstore.shared.csharp/InventoryItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class InventoryItem
66

77
public string Name { get; set; }
88

9+
public string FontAwesomeIcon { get; set; }
10+
911
public string Description { get; set; }
1012
}
1113
}

src/funstore.shared.csharp/Order.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Funstore.Shared.csharp
5+
{
6+
public class Order
7+
{
8+
public int Id { get; set; }
9+
10+
public Guid CartId { get; set; }
11+
12+
public List<CartItem> Items { get; set; }
13+
14+
public DateTime OrderPlaced { get; set; }
15+
16+
public string Status { get; set; }
17+
18+
public DateTime LastUpdate { get; set; }
19+
}
20+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Microsoft.Extensions.Logging;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using System.Net.Http;
7+
using Steeltoe.Common.Discovery;
8+
9+
namespace Funstore.Shared.csharp
10+
{
11+
public class OrderProcessingService : BaseDiscoveryService
12+
{
13+
private const string ORDER_URL = "http://funstore-orders/order";
14+
15+
public OrderProcessingService(IDiscoveryClient client, ILoggerFactory logFactory) : base(client, logFactory.CreateLogger<OrderProcessingService>())
16+
{
17+
}
18+
19+
public async Task<int> AddOrderAsync(Order order)
20+
{
21+
var request = new HttpRequestMessage(HttpMethod.Post, ORDER_URL);
22+
var result = await Invoke<Order>(request, order);
23+
return result.Id;
24+
}
25+
26+
public async Task<Order> GetOrderAsync(int id)
27+
{
28+
var orderUrl = ORDER_URL + "/" + id;
29+
30+
var request = new HttpRequestMessage(HttpMethod.Get, orderUrl);
31+
var result = await Invoke<Order>(request);
32+
return result;
33+
}
34+
35+
public async Task<List<Order>> GetOrderHistory(Guid cartId)
36+
{
37+
var orderUrl = ORDER_URL + "/history/" + cartId;
38+
39+
var request = new HttpRequestMessage(HttpMethod.Get, orderUrl);
40+
var result = await Invoke<List<Order>>(request);
41+
return result;
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)