Skip to content

Commit

Permalink
releaseb return char on error
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammers21 committed Dec 19, 2023
1 parent b103196 commit c361554
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/io/github/sammers/pla/http/Http.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,7 @@ public void start() {
VTHREAD_EXECUTOR.execute(() -> {
String realm = ctx.pathParam("realm");
String name = ctx.pathParam("name");
Optional<WowAPICharacter> charWithName = ladder.wowChar(ladder.realms.get().nameToSlug(realm), name);
Optional<WowAPICharacter> charWithSlug = ladder.wowChar(realm, name);
Optional<WowAPICharacter> res = Stream.of(charWithName, charWithSlug).filter(Optional::isPresent).findFirst().map(Optional::get);
if (res.isEmpty() || res.get().hidden()) {
ctx.response().setStatusCode(404).end(new JsonObject().put("error", "Character not found").encode());
} else {
ctx.response().end(wowCharToJson(res.get()).encode());
}
nameRealmLookupResponse(ctx, realm, name);
});
});
router.get("/api/:region/:realm/:name/update").handler(ctx -> {
Expand All @@ -149,7 +142,7 @@ public void start() {
} else {
ctx.response().end(wowCharToJson(wowAPICharacter.get()).encode());
}
});
}, err -> nameRealmLookupResponse(ctx, realm, name));
});
});
router.get("/:region/ladder/:bracket").handler(ctx -> ctx.response().sendFile("index.html"));
Expand All @@ -160,6 +153,17 @@ public void start() {
vertx.createHttpServer().requestHandler(router).listen(9000);
}

private void nameRealmLookupResponse(RoutingContext ctx, String realm, String name) {
Optional<WowAPICharacter> charWithName = ladder.wowChar(ladder.realms.get().nameToSlug(realm), name);
Optional<WowAPICharacter> charWithSlug = ladder.wowChar(realm, name);
Optional<WowAPICharacter> res = Stream.of(charWithName, charWithSlug).filter(Optional::isPresent).findFirst().map(Optional::get);
if (res.isEmpty() || res.get().hidden()) {
ctx.response().setStatusCode(404).end(new JsonObject().put("error", "Character not found").encode());
} else {
ctx.response().end(wowCharToJson(res.get()).encode());
}
}

private JsonObject wowCharToJson(WowAPICharacter character) {
Set<WowAPICharacter> alts = characterCache.altsFor(character);
JsonObject res = character.toJson();
Expand Down

0 comments on commit c361554

Please sign in to comment.