Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
dev merge
Browse files Browse the repository at this point in the history
  • Loading branch information
fayderflorez committed Nov 1, 2013
1 parent 46fe744 commit 3c7f001
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/main/java/vaeke/restcountries/rest/CountryRest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ public Object getCountries() {
}
}

@GET
@Path("alpha/{alphacode}")
public Object getByAlpha(@PathParam("alphacode") String alpha) {
LOG.info("Getting by alpha " + alpha);
try {
List<Country> countries = getAll();
int alphaLength = alpha.length();
for(Country country : countries) {
if (alphaLength == 2) {
if (country.getCca2().toLowerCase().equals(alpha.toLowerCase())) {
return country;
}
} else if (alphaLength == 3) {
if (country.getCca3().toLowerCase().equals(alpha.toLowerCase())) {
return country;
}
}
}
return Response.status(Status.NOT_FOUND).entity("404: Not Found").build();
} catch (IOException e) {
LOG.error(e.getMessage(), e);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity("500: Internal Server Error").build();
}
}

@GET
@Path("alpha2/{alpha2code}")
@Deprecated
Expand Down

0 comments on commit 3c7f001

Please sign in to comment.