Skip to content

Commit

Permalink
Some more cleanups to the API
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianKirmaier committed Dec 15, 2023
1 parent 9504e15 commit dbae3a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
import one.jpro.platform.auth.example.login.page.SignedInPage;
import one.jpro.platform.auth.example.oauth.OAuthApp;
import one.jpro.platform.auth.routing.OAuth2Filter;
import one.jpro.platform.routing.Redirect;
import one.jpro.platform.routing.Response;
import one.jpro.platform.routing.Route;
import one.jpro.platform.routing.RouteApp;
import one.jpro.platform.routing.dev.DevFilter;
import one.jpro.platform.sessions.SessionManager;
import org.json.JSONObject;
import simplefx.experimental.parts.FXFuture;

import java.net.URL;
import java.util.List;
Expand Down Expand Up @@ -84,8 +82,8 @@ public Route createRoute() {
.filter(DevFilter.create())
.filter(OAuth2Filter.create(googleAuthProvider, googleCredentials, user -> {
setUser(user);
return FXFuture.unit(Response.redirect("/user/signed-in"));
}, error -> FXFuture.unit(Response.fromNode(new ErrorPage(error)))));
return Response.redirectFuture("/user/signed-in");
}, error -> Response.fromNodeFuture(new ErrorPage(error))));
}

public final User getUser() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package one.jpro.platform.routing

import simplefx.experimental.FXFuture

trait Response
object Response {
def empty(): Response = null
def emptyFuture(): FXFuture[Response] = FXFuture.unit(empty())
def redirect(to: String): Response = Redirect(to)
def redirectFuture(to: String): FXFuture[Response] = FXFuture.unit(Redirect(to))
def fromNode(node: javafx.scene.Node): Response = new Response {
RouteUtils.viewFromNode(node)
}
def fromNodeFuture(node: javafx.scene.Node): FXFuture[Response] = FXFuture.unit(fromNode(node))
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public Route createRoute() {
if(matcher.matches()) {
var colorStr = matcher.group(1);
var color = Color.web(colorStr);
return FXFuture.unit(viewFromNode(gen("#" + colorStr, r.resolve("/red"), color)));
return Response.fromNodeFuture(gen("#" + colorStr, r.resolve("/red"), color));
} else {
return FXFuture.unit(null);
return Response.emptyFuture();
}
})
.path("/colors",
Expand Down

0 comments on commit dbae3a4

Please sign in to comment.