diff --git a/src/main/java/com/example/jerseyexercise/resources/himatsumto.java b/src/main/java/com/example/jerseyexercise/resources/himatsumto.java new file mode 100644 index 0000000..105a72f --- /dev/null +++ b/src/main/java/com/example/jerseyexercise/resources/himatsumto.java @@ -0,0 +1,60 @@ +package com.example.jerseyexercise.resources; + +import jakarta.ws.rs.*; +import jakarta.ws.rs.core.MediaType; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; + +@Path("himatsumoto") +@Component +public class himatsumto { + + //Hellllllllllllllllllllllllllllllllllooooooooooooooooooooooooooooooo Hirokiですうううう + String name = "noname"; + ArrayList tweetList = new ArrayList<>(); + + @GET + public String getHelloWorld() { + return "Hello World!!"; + } + + @GET + @Path("/name") + public String getName() { + return name; + } + + @PUT + @Path("/name") + public void setName(@FormParam("name") String newName) { + name = newName; + } + + @POST + @Path("/tweets") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public void tweet(@FormParam("tweet") String tweet) { + tweetList.add(tweet); + // ArrayList のメソッド: + // add(x) --- リストの末尾に x を追加 + // get(idx) --- リストの idx 番目の要素を取得 + // size() --- リストに入っている要素の数を取得 + // remove(idx) --- リストの idx 番目の要素を削除 + } + + @GET + @Path("/tweets") + @Produces(MediaType.APPLICATION_JSON) + public ArrayList getTweets() { + return tweetList; + } + + @GET + @Path("/tweets/{no}") + @Produces(MediaType.APPLICATION_JSON) + public String getTweet(@PathParam("no") int n) { + String t = tweetList.get(n); + return t; + } +}