Skip to content

Commit 3a30989

Browse files
committed
Feature: order history
1 parent 525199d commit 3a30989

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

frontend/public/app.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ async function placeOrder() {
2323
method: "POST",
2424
headers: {
2525
"Content-Type": "application/json",
26-
"Authorization": "Bearer " + token
26+
"Authorization": "Bearer" + token
2727
},
2828
body: JSON.stringify({ productId, quantity }),
2929
});
3030

3131
const text = await res.text();
3232
document.getElementById("output").textContent = text;
3333
}
34+
35+
//TODO add order history

frontend/public/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ <h1>Order</h1>
1616
<button onclick="placeOrder()">Place Order</button>
1717

1818
<pre id="output"></pre>
19+
20+
<!-- TODO add order history -->
1921
</body>
2022
</html>

services/auth-python/app/auth.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
USER_DB = {
88
"alice": "password123",
9-
"bob": "hunter2",
10-
"admin": "admin"
9+
"bob": "hunter2"
1110
}
1211

1312
SESSIONS = {}

services/billing-csharp/Controllers/BillingController.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Text.Json.Serialization;
44
using System.Threading.Tasks;
55
using System;
6+
using System.Collections.Generic;
67

78
public class ChargeRequest
89
{
@@ -14,12 +15,17 @@ public class ChargeRequest
1415

1516
[JsonPropertyName("quantity")]
1617
public int Quantity { get; set; }
18+
19+
// ISO-8601 timestamp of when the charge was requested
20+
[JsonPropertyName("date")]
21+
public DateTime Date { get; set; }
1722
}
1823

1924
[ApiController]
2025
[Route("billing")]
2126
public class BillingController : ControllerBase
2227
{
28+
private static readonly List<object> responseHistory = new List<object>();
2329
private readonly string EXPECTED_SECRET = Environment.GetEnvironmentVariable("BILLING_SECRET");
2430

2531
[HttpPost("charge")]
@@ -37,9 +43,12 @@ public async Task<IActionResult> Charge([FromBody] ChargeRequest request)
3743
status = "charged",
3844
user = request.Username,
3945
product = request.ProductId,
40-
quantity = request.Quantity
46+
quantity = request.Quantity,
47+
data = request.Date.ToString("o") // ISO-8601 format
4148
};
4249

50+
responseHistory.Add(responsePayload);
51+
4352
return Ok(JsonSerializer.Serialize(responsePayload));
4453
}
4554
}

services/orders-java/src/main/java/com/example/orders/controller/OrderController.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.example.orders.controller;
22

3+
import java.time.Instant;
34
import org.springframework.beans.factory.annotation.Value;
45
import com.example.orders.model.OrderRequest;
56
import org.json.JSONObject;
@@ -49,6 +50,7 @@ protected String validateToken(String token) {
4950
String body = authResponse.getBody();
5051
return body.contains("username") ? body.split(":")[1].replaceAll("[\"{} ]", "") : null;
5152
} catch (Exception e) {
53+
e.printStackTrace();
5254
return null;
5355
}
5456
}
@@ -62,13 +64,15 @@ protected boolean charge(String username, String productId, int quantity) {
6264
payload.put("username", username);
6365
payload.put("productId", productId);
6466
payload.put("quantity", quantity);
67+
payload.put("dats", Instant.now().toString());
6568

6669
HttpEntity<String> entity = new HttpEntity<>(payload.toString(), headers);
6770
try {
6871
ResponseEntity<String> billingResponse = restTemplate.postForEntity(
6972
billingServiceUrl + "/billing/charge", entity, String.class);
7073
return billingResponse.getStatusCode().is2xxSuccessful();
7174
} catch (Exception e) {
75+
e.printStackTrace();
7276
return false;
7377
}
7478
}

0 commit comments

Comments
 (0)