Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi committed Sep 25, 2024
1 parent 192bb05 commit 8cf9ca6
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import net.jcip.annotations.ThreadSafe;

import java.util.AbstractMap;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
Expand All @@ -64,6 +66,8 @@ public class DataServlet {

private static final ObjectMapper JSON_MAPPER = new ObjectMapper();

private static final List<String> LANGUAGES = Arrays.asList("German", "Ancient Greek", "Latin");


/**
* Constructor for dependency injection.
Expand All @@ -86,9 +90,25 @@ public Response healthcheck() {
.build();
}

/**
* Get all vocabularies of a language
*
* @param language The language
*
* @return
* @throws JsonProcessingException
*/
@GET
@Path("/languages/{language}")
public Response getVocabularyByLanguage(@PathParam("language") String language) throws JsonProcessingException {
public Response getVocabularyByLanguage(@NotNull @PathParam("language") final String language)
throws JsonProcessingException {
if (!LANGUAGES.contains(language)) {
return Response
.status(Response.Status.BAD_REQUEST)
.entity(String.format("'language' path parameter has to be one of %s", String.join(", ", LANGUAGES)))
.build();
}

return query(
String.format(
"MATCH (t:Term WHERE t.language = %s)-[r]->(d:Definition) RETURN t.name, d.name", language
Expand Down

0 comments on commit 8cf9ca6

Please sign in to comment.