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

Commit

Permalink
restored CountryRest to latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
fayderflorez committed Nov 1, 2013
1 parent 2691485 commit 20f2c6a
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/main/java/vaeke/restcountries/rest/CountryRest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,14 @@ public Object getCountries() {
}

@GET
@Path("alpha/{alphacode}")
public Object getByAlpha(@PathParam("alphacode") String alpha) {
LOG.info("Getting by alpha " + alpha);
@Path("alpha2/{alpha2code}")
public Object getByAlpha2(@PathParam("alpha2code") String alpha2) {
LOG.info("Getting by alpha2 " + alpha2);
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;
}
if (country.getCca2().toLowerCase().equals(alpha2.toLowerCase())) {
return country;
}
}
return Response.status(Status.NOT_FOUND).entity("404: Not Found").build();
Expand All @@ -72,6 +65,24 @@ public Object getByAlpha(@PathParam("alphacode") String alpha) {

}

@GET
@Path("alpha3/{alpha3code}")
public Object getByAlpha3(@PathParam("alpha3code") String alpha3) {
LOG.info("Getting by alpha3 " + alpha3);
try {
List<Country> countries = getAll();
for(Country country : countries) {
if (country.getCca3().toLowerCase().equals(alpha3.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("currency/{currency}")
public Object getByCurrency(@PathParam("currency") String currency) {
Expand Down

0 comments on commit 20f2c6a

Please sign in to comment.