-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add route for getting voting sites URLs
- Loading branch information
1 parent
fb87f53
commit bea695b
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/net/laboulangerie/api/controllers/VoteController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |