diff --git a/src/main/java/org/ntlab/amaryllis/server/resources/CategoriesRest.java b/src/main/java/org/ntlab/amaryllis/server/resources/CategoriesRest.java new file mode 100644 index 0000000..5510785 --- /dev/null +++ b/src/main/java/org/ntlab/amaryllis/server/resources/CategoriesRest.java @@ -0,0 +1,40 @@ +package org.ntlab.amaryllis.server.resources; + +import org.ntlab.amaryllis.server.entities.Account; +import org.ntlab.amaryllis.server.entities.Category; +import org.ntlab.amaryllis.server.models.Categories; +import org.springframework.stereotype.Component; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.ArrayList; + +@Component +@Path("/categories") +public class CategoriesRest { + private Categories categories = Categories.getInstance(); + + CategoriesRest(){ + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + public ArrayList getCategories() { + return categories.getCategoryList(); + } + + + @Path("/{cid}") + @GET + @Produces(MediaType.APPLICATION_JSON) + public Category getCategory(@PathParam("cid") String cid) { + if (cid == null) { + throw new WebApplicationException(400); + } + Category category = categories.getCategory(cid); + if (category == null) { + throw new WebApplicationException(400); + } + return category; + } + +}