Skip to content

Commit

Permalink
Add route for getting voting sites URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
PainOchoco committed Apr 23, 2024
1 parent fb87f53 commit bea695b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>BenCodez Repo</id>
<url>https://nexus.bencodez.com/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -108,6 +112,12 @@
<version>2.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.bencodez</groupId>
<artifactId>votingplugin</artifactId>
<version>6.14.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin-bundle</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/laboulangerie/api/LaBoulangerieAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.laboulangerie.api.controllers.ServerController;
import net.laboulangerie.api.controllers.StaffController;
import net.laboulangerie.api.controllers.TownController;
import net.laboulangerie.api.controllers.VoteController;
import net.laboulangerie.api.jwt.JwtLevel;
import net.laboulangerie.api.jwt.JwtManager;
import net.laboulangerie.api.listeners.TownyListener;
Expand Down Expand Up @@ -147,6 +148,9 @@ public <T> T fromJsonString(@NotNull String json, @NotNull Type targetType) {
get(SearchController::search, JwtLevel.ANYONE);
});
});
path("vote", () -> {
get(VoteController::getVotes, JwtLevel.ANYONE);
});
});

app.ws("/ws/towny", ws -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.laboulangerie.api.controllers;

import java.util.List;
import java.util.stream.Collectors;

import com.bencodez.votingplugin.VotingPluginMain;
import com.bencodez.votingplugin.objects.VoteSite;
import io.javalin.http.Context;
import io.javalin.openapi.HttpMethod;
import io.javalin.openapi.OpenApi;
import io.javalin.openapi.OpenApiResponse;
import io.javalin.openapi.OpenApiContent;

public class VoteController {
public static List<String> getVotes() {
List<VoteSite> sites = VotingPluginMain.getPlugin().getVoteSites();
List<String> urls = sites.stream().filter(VoteSite::isEnabled).map(VoteSite::getVoteURL)
.collect(Collectors.toList());
return urls;
}

@OpenApi(description = "Get all vote sites", operationId = "getVotes", path = "/vote", methods = HttpMethod.GET, tags = {
"Vote" }, responses = {
@OpenApiResponse(status = "200", description = "Vote URLs", content = {
@OpenApiContent(from = String[].class) })
})
public static void getVotes(Context ctx) {
ctx.json(getVotes());
}
}

0 comments on commit bea695b

Please sign in to comment.