Skip to content

Commit 6215944

Browse files
committed
refactor(server): moved the state page template to WebPages class
Refs: #47
1 parent eafc80a commit 6215944

File tree

4 files changed

+26
-80
lines changed

4 files changed

+26
-80
lines changed

src/main/java/ru/ewc/checklogic/server/AllEndpoints.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,25 @@ public void register(final WebFramework web) {
5454
web.registerPartialPath(GET, "static", AllEndpoints::staticResource);
5555
web.registerPath(GET, "", this::getRequestDispatcher);
5656
web.registerPath(GET, "test", this::getRequestDispatcher);
57+
web.registerPath(GET, "state", this::getRequestDispatcher);
5758
}
5859

5960
@SuppressWarnings("PMD.UnusedFormalParameter")
6061
private Response getRequestDispatcher(final Request request) {
6162
final Response result;
6263
if (this.context.isEmpty()) {
6364
result = this.pages.uninitializedPage();
64-
} else if (request.requestLine().getPathDetails().getIsolatedPath().isEmpty()) {
65-
result = this.pages.indexPage();
66-
} else if ("test".equals(request.requestLine().getPathDetails().getIsolatedPath())) {
67-
result = this.pages.testPage();
6865
} else {
69-
result = new Response(NOT_FOUND, "", PLAIN_TEXT);
66+
final String address = request.requestLine().getPathDetails().getIsolatedPath();
67+
if (address.isEmpty()) {
68+
result = this.pages.indexPage();
69+
} else if ("test".equals(address)) {
70+
result = this.pages.testPage();
71+
} else if ("state".equals(address)) {
72+
result = this.pages.statePage(this.context);
73+
} else {
74+
result = new Response(NOT_FOUND, "", PLAIN_TEXT);
75+
}
7076
}
7177
return result;
7278
}

src/main/java/ru/ewc/checklogic/server/StatePage.java

-73
This file was deleted.

src/main/java/ru/ewc/checklogic/server/WebPages.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,25 @@ public Response testPage() {
7575
);
7676
}
7777

78+
public Response statePage(final ServerContext context) {
79+
final StoredState stored = new StoredState(context.storedState());
80+
return Response.htmlOk(
81+
this.templateNamed(
82+
"templates/state.html",
83+
Map.of(
84+
"state", stored.asHtmlList(),
85+
"available", context.cached("available"),
86+
"request", context.cached("request")
87+
)
88+
)
89+
);
90+
}
91+
7892
private String templateNamed(final String template, final Map<String, String> values) {
7993
return this.processors.forTemplate(template).renderTemplate(values);
8094
}
8195

96+
// @todo #47 Move performTest method to dedicated test runner
8297
@SneakyThrows
8398
private TestResult performTest(final TestData test) {
8499
final SoftAssertions softly = new SoftAssertions();
@@ -102,5 +117,4 @@ private TestResult performTest(final TestData test) {
102117
}
103118
return result;
104119
}
105-
106120
}

src/main/java/ru/ewc/checklogic/server/WebServer.java

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public WebServer(final ServerContext context) {
5151
public void start() {
5252
final FullSystem minum = FullSystem.initialize();
5353
final WebFramework web = minum.getWebFramework();
54-
registerEndpoints(web, new StatePage(this.context));
5554
registerEndpoints(web, new CommandPage(this.context));
5655
registerEndpoints(web, new ContextPage(this.context));
5756
registerEndpoints(web, new AllEndpoints(this.context));

0 commit comments

Comments
 (0)