diff --git a/src/main/java/org/ntlab/hellorest/resources/CommentsMiyazakiRest.java b/src/main/java/org/ntlab/hellorest/resources/CommentsMiyazakiRest.java new file mode 100644 index 0000000..1a48015 --- /dev/null +++ b/src/main/java/org/ntlab/hellorest/resources/CommentsMiyazakiRest.java @@ -0,0 +1,45 @@ +package org.ntlab.hellorest.resources; + +import org.springframework.stereotype.Component; + +import javax.ws.rs.*; +import java.util.ArrayList; + +@Component +@Path("/comments-miyazaki") +public class CommentsMiyazakiRest { + ArrayList comments = new ArrayList<>(); + + @GET + public String getcomments(){ + String result = ""; + for(String comment:comments){ + result = result + comment + "
"; + } + return result; + } + + @POST + public void addComment(@FormParam("comment")String comment){ + comments.add(comment); + } + + @DELETE + public void clesrCOmments(){comments.clear(); } + + @Path("/{cId}") + @GET + public String getComment(@PathParam("cId") String cId){ + int id = Integer.parseInt(cId); + return comments.get(id); + } + + @Path("/{cId}") + @PUT + public void addCommment(@PathParam("cId")String cId,@FormParam("comment")String comment){ + int id =Integer.parseInt(cId); + comments.set(id,comment); + } + + +}