Skip to content

Commit a44682c

Browse files
committed
Feature: order history
1 parent 20780fb commit a44682c

File tree

7 files changed

+70
-4
lines changed

7 files changed

+70
-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
}

workflows/gitstream.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Code generated by gitStream GitHub app - DO NOT EDIT
2+
3+
name: gitStream workflow automation
4+
run-name: |
5+
/:\ gitStream: PR #${{ fromJSON(fromJSON(github.event.inputs.client_payload)).pullRequestNumber }} from ${{ github.event.inputs.full_repository }}
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
client_payload:
11+
description: The Client payload
12+
required: true
13+
full_repository:
14+
description: the repository name include the owner in `owner/repo_name` format
15+
required: true
16+
head_ref:
17+
description: the head sha
18+
required: true
19+
base_ref:
20+
description: the base ref
21+
required: true
22+
installation_id:
23+
description: the installation id
24+
required: false
25+
resolver_url:
26+
description: the resolver url to pass results to
27+
required: true
28+
resolver_token:
29+
description: Optional resolver token for resolver service
30+
required: false
31+
default: ''
32+
33+
jobs:
34+
gitStream:
35+
timeout-minutes: 5
36+
runs-on: ubuntu-latest
37+
name: gitStream workflow automation
38+
steps:
39+
- name: Evaluate Rules
40+
uses: linear-b/gitstream-github-action@v2
41+
id: rules-engine
42+
with:
43+
full_repository: ${{ github.event.inputs.full_repository }}
44+
head_ref: ${{ github.event.inputs.head_ref }}
45+
base_ref: ${{ github.event.inputs.base_ref }}
46+
client_payload: ${{ github.event.inputs.client_payload }}
47+
installation_id: ${{ github.event.inputs.installation_id }}
48+
resolver_url: ${{ github.event.inputs.resolver_url }}
49+
resolver_token: ${{ github.event.inputs.resolver_token }}
50+
debug_mode: true

workflows/rebuild-demo.yaml

Whitespace-only changes.

0 commit comments

Comments
 (0)