diff --git a/src/main/java/ru/ewc/checklogic/LogicChecker.java b/src/main/java/ru/ewc/checklogic/LogicChecker.java index f0ce9b3..dd45ec1 100644 --- a/src/main/java/ru/ewc/checklogic/LogicChecker.java +++ b/src/main/java/ru/ewc/checklogic/LogicChecker.java @@ -30,6 +30,7 @@ import ru.ewc.checklogic.server.CommandPage; import ru.ewc.checklogic.server.ContextPage; import ru.ewc.checklogic.server.Endpoints; +import ru.ewc.checklogic.server.StatePage; import ru.ewc.checklogic.server.config.ConfigPage; /** @@ -58,6 +59,7 @@ public static void main(final String[] args) { registerEndpoints(web, new CommandPage(context)); registerEndpoints(web, new ContextPage(context, factory.configuration())); registerEndpoints(web, new AllEndpoints(context, factory.configuration())); + registerEndpoints(web, new StatePage(context)); minum.block(); } diff --git a/src/main/java/ru/ewc/checklogic/server/Endpoints.java b/src/main/java/ru/ewc/checklogic/server/Endpoints.java index 781d335..eeb7cc8 100644 --- a/src/main/java/ru/ewc/checklogic/server/Endpoints.java +++ b/src/main/java/ru/ewc/checklogic/server/Endpoints.java @@ -44,6 +44,11 @@ public interface Endpoints { */ RequestLine.Method POST = RequestLine.Method.POST; + /** + * The shortcut to define an endpoint for a DELETE method. + */ + RequestLine.Method DELETE = RequestLine.Method.DELETE; + /** * Content type for CSS files. */ diff --git a/src/main/java/ru/ewc/checklogic/server/StatePage.java b/src/main/java/ru/ewc/checklogic/server/StatePage.java new file mode 100644 index 0000000..f16ca38 --- /dev/null +++ b/src/main/java/ru/ewc/checklogic/server/StatePage.java @@ -0,0 +1,58 @@ +/* + * MIT License + * + * Copyright (c) 2024 Decision-Driven Development + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package ru.ewc.checklogic.server; + +import com.renomad.minum.web.Request; +import com.renomad.minum.web.RequestLine; +import com.renomad.minum.web.Response; +import com.renomad.minum.web.WebFramework; +import java.util.Map; +import ru.ewc.checklogic.ServerInstance; + +/** + * I am a class providing access to the state page. + * + * @since 0.4.1 + */ +public final class StatePage implements Endpoints { + /** + * The context that stores the current state of the system. + */ + private final ServerInstance context; + + public StatePage(final ServerInstance context) { + this.context = context; + } + + @Override + public void register(final WebFramework web) { + web.registerPath(RequestLine.Method.DELETE, "state", this::resetState); + } + + private Response resetState(final Request request) { + assert request.requestLine().getMethod().equals(RequestLine.Method.DELETE); + this.context.initialize(); + return Response.htmlOk("OK", Map.of("HX-Redirect", "/state")); + } +} diff --git a/src/main/resources/templates/state.html b/src/main/resources/templates/state.html index 6523ab9..19ac022 100644 --- a/src/main/resources/templates/state.html +++ b/src/main/resources/templates/state.html @@ -24,11 +24,19 @@

State entities

- {{ state }} +
+
+ +
+
+
+ {{ state }} +

Context

-
+