adding files 2

This commit is contained in:
Oracle Public Cloud User
2026-09-04 13:54:16 +00:00
parent b7ec9db2bc
commit 8b3cc8dd10
83 changed files with 5045 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package com.oracle.demo.inventory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class InventoryServiceApplication {
public static void main(String[] args) {
SpringApplication.run(InventoryServiceApplication.class, args);
}
}

View File

@@ -0,0 +1,40 @@
package com.oracle.demo.inventory.api;
import com.oracle.demo.inventory.model.InventoryResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/api/inventory")
public class InventoryController {
private final Map<String, Integer> stock = new HashMap<>();
private final boolean forceOutage;
public InventoryController(@Value("${demo.inventory.force-outage:false}") boolean forceOutage) {
this.forceOutage = forceOutage;
stock.put("LAPTOP-15", 25);
stock.put("MOUSE-WL", 100);
stock.put("MONITOR-27", 12);
}
@GetMapping("/{sku}")
public InventoryResponse getInventory(@PathVariable String sku, @RequestParam(defaultValue = "1") int quantity) {
if (forceOutage) {
return new InventoryResponse(sku, false, 0, "Inventory service is intentionally degraded for the demo.");
}
int available = stock.getOrDefault(sku, 0);
boolean reserved = available >= quantity;
String message = reserved ? "Stock reserved." : "Insufficient stock.";
return new InventoryResponse(sku, reserved, available, message);
}
}

View File

@@ -0,0 +1,5 @@
package com.oracle.demo.inventory.model;
public record InventoryResponse(String sku, boolean reserved, int availableUnits, String message) {
}

View File

@@ -0,0 +1,21 @@
spring:
application:
name: inventory-service
server:
port: 8081
management:
endpoints:
web:
exposure:
include: health,info,metrics,prometheus
endpoint:
health:
probes:
enabled: true
demo:
inventory:
force-outage: false