Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/org/llschall/control/board/UiRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api")
public class UiRestController {
private final CounterViewModel viewModel;
private final AtomicInteger echoCallCount = new AtomicInteger(0);

public UiRestController(CounterViewModel viewModel) {
this.viewModel = viewModel;
Expand Down Expand Up @@ -43,6 +45,17 @@ public List<MeasurementDto> getMeasurements() {
return toDtoList(viewModel.getAllMeasurements());
}

@GetMapping("/echo")
public ResponseEntity<?> echo() {
int i = echoCallCount.incrementAndGet();
return ResponseEntity.ok(new EchoDto(i));
}

@GetMapping("/echo-count")
public ResponseEntity<?> getEchoCount() {
return ResponseEntity.ok(new EchoCountDto(echoCallCount.get()));
}

private List<MeasurementDto> toDtoList(Iterable<Measurement> measurements) {
return ((List<Measurement>) ((measurements instanceof List) ? measurements : toList(measurements)))
.stream()
Expand All @@ -51,32 +64,19 @@ private List<MeasurementDto> toDtoList(Iterable<Measurement> measurements) {
}

private List<Measurement> toList(Iterable<Measurement> iterable) {
return (List<Measurement>) ((List<?>)
java.util.stream.StreamSupport.stream(iterable.spliterator(), false).collect(Collectors.toList()));
return java.util.stream.StreamSupport.stream(iterable.spliterator(), false).collect(Collectors.toList());
}

static class CounterDto {
public final int value;
public final String display;
public final boolean switchOn;
record CounterDto(int value, String display, boolean switchOn) {
}

public CounterDto(int value, String display, boolean switchOn) {
this.value = value;
this.display = display;
this.switchOn = switchOn;
}
record MeasurementDto(Long id, int value, String timestamp) {
}

static class MeasurementDto {
public final Long id;
public final int value;
public final String timestamp;
record EchoDto(int count) {
}

public MeasurementDto(Long id, int value, String timestamp) {
this.id = id;
this.value = value;
this.timestamp = timestamp;
}
record EchoCountDto(int count) {
}
}

9 changes: 9 additions & 0 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<button id="inc">Increment</button>
<label>Led <input type="checkbox" id="led" /></label>
<button id="refreshDb">Refresh DB</button>
<span id="echoCount">Echo Calls: 0</span>
</div>

<div id="chart"></div>
Expand Down Expand Up @@ -55,11 +56,19 @@ <h3>Measurements</h3>
return res.json();
}

async function fetchEchoCount() {
const res = await fetch('/api/echo-count');
return res.json();
}

async function refreshUi() {
const counter = await fetchCounter();
document.getElementById('display').textContent = counter.display;
document.getElementById('led').checked = counter.switchOn;

const echoCounter = await fetchEchoCount();
document.getElementById('echoCount').textContent = 'Echo Calls: ' + echoCounter.count;

const measurements = await fetchMeasurements();
const series = measurements.map((m, idx) => m.value);
const x = measurements.map((m, idx) => idx);
Expand Down
Loading