diff --git a/src/main/java/com/example/jerseyexercise/resources/HIwatani.java b/src/main/java/com/example/jerseyexercise/resources/HIwatani.java deleted file mode 100644 index 40db6b7..0000000 --- a/src/main/java/com/example/jerseyexercise/resources/HIwatani.java +++ /dev/null @@ -1,55 +0,0 @@ -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("hiwatani") -@Component -public class HIwatani { - 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; - } -} diff --git a/src/main/java/com/example/jerseyexercise/resources/HNishimura.java b/src/main/java/com/example/jerseyexercise/resources/HNishimura.java deleted file mode 100644 index 269ab7c..0000000 --- a/src/main/java/com/example/jerseyexercise/resources/HNishimura.java +++ /dev/null @@ -1,58 +0,0 @@ -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("hnishimura") -@Component -public class HNishimura { - 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); - } - - @GET - @Path("/tweets") - @Produces(MediaType.APPLICATION_JSON) - public ArrayList getTweets() { - return tweetList; - } - - @GET - @Path("/tweets/{no}") - public String getTweet(@PathParam("no") int n) { - int s = tweetList.size(); - if(n <= s-1 && 0 <= n) { - String t = tweetList.get(n); - return t; - } - else { - return "koko niha naiyo"; - } - } -} diff --git a/src/main/java/com/example/jerseyexercise/resources/NNitta.java b/src/main/java/com/example/jerseyexercise/resources/NNitta.java deleted file mode 100644 index 86e8575..0000000 --- a/src/main/java/com/example/jerseyexercise/resources/NNitta.java +++ /dev/null @@ -1,54 +0,0 @@ -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("nnitta") -@Component -public class NNitta { - 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); - } - - @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; - } - -} diff --git a/src/main/java/com/example/jerseyexercise/resources/SHatai.java b/src/main/java/com/example/jerseyexercise/resources/SHatai.java deleted file mode 100644 index 99a5425..0000000 --- a/src/main/java/com/example/jerseyexercise/resources/SHatai.java +++ /dev/null @@ -1,51 +0,0 @@ -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("shatai") -@Component -public class SHatai { - String name = "hatai"; - ArrayList tweetList = new ArrayList<>(); //左側はインスタンス add(x), get(idx), size(), remove(idx) - @GET - //@Produces(MediaType.TEXT_PLAIN) - 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) //送ったパラメーターが消費される post manのリクエストbodyと対応 - public void tweet(@FormParam("tweet") String tweet) { - tweetList.add(tweet); - } - @GET - @Path("/tweets") - @Produces(MediaType.APPLICATION_JSON) //戻り値をどういう形で返すのか 引数がvoidまたはstring以外なのでつけることができる - 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; - } -} diff --git a/src/main/java/com/example/jerseyexercise/resources/SRana.java b/src/main/java/com/example/jerseyexercise/resources/SRana.java deleted file mode 100644 index 0375833..0000000 --- a/src/main/java/com/example/jerseyexercise/resources/SRana.java +++ /dev/null @@ -1,65 +0,0 @@ -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("srana") -@Component//Jerseyの場合必須 - -public class SRana { - String name = "noname"; - - ArrayList tweetList = new ArrayList<>(); - // ↑の<>中にJerseyはいっているが省略できる - - //Jerseyの場合getメソッドと定義する必要がある - @GET//myaccountのGET - public String getMyAccount() { - return "Hello World!!";//localhost:8080/myaccount(URL)のwebページにHello World!!が表示される - } - @GET//myaccount/nameのGET - @Path("/name")//親リソースの続きの子リソース - public String getName() { - return name; - } - - //置き換え、入れ替えをするときPUTを使う - @PUT - @Path("/name")//←URLのname   ↓パラメータのname(Keyのnameと一致) - public void setName(@FormParam("name") String newName) { //nameをPostmanでPUTすることで変更できる。引数はnewName。 - name = newName;//nonameが上書きされる - ArrayList tweetList = new ArrayList<>(); - } - - @POST - @Path("/tweets") - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - public void tweet(@FormParam("tweet")String tweet) { - //tweets = 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;//このtweetListはArrayList - } - - @GET - @Path("/tweets/{no}") - @Produces(MediaType.APPLICATION_JSON) - public String getTweet(@PathParam("no") int n) { - String t = tweetList.get(n); - return t; - } - -} diff --git a/src/main/java/com/example/jerseyexercise/resources/SYamagiwa.java b/src/main/java/com/example/jerseyexercise/resources/SYamagiwa.java deleted file mode 100644 index 52abc55..0000000 --- a/src/main/java/com/example/jerseyexercise/resources/SYamagiwa.java +++ /dev/null @@ -1,152 +0,0 @@ -/** - * The MIT License (MIT) - *

- * Copyright @ 2024, Shohei Yamagiwa - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the “Software”), to deal - * in the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package com.example.jerseyexercise.resources; - -import jakarta.ws.rs.*; -import org.springframework.http.MediaType; - -import java.util.ArrayList; -import java.util.List; - -/** - * {@link SYamagiwa} represents my account resource - * - * @author Shohei Yamagiwa - * @since 1.0 - */ -@Path("/s-yamagiwa") -public class SYamagiwa { - /** - * First name of the account. - */ - private String firstName = "Shohei"; - - /** - * Last name of the account. - */ - private String lastName = "Yamagiwa"; - - /** - * All posts of the account - */ - private final List posts = new ArrayList<>(); - - /** - * Returns the full-name of the account. - * - * @return The name of the account - * @since 1.0 - */ - @GET() - @Path("/name") - public String getFullName() { - return firstName + " " + lastName; - } - - /** - * Returns the first-name of the account. - * - * @return The first name of the account - * @since 1.0 - */ - @GET() - @Path("/first-name") - public String getFirstName() { - return firstName; - } - - /** - * Returns the last-name of the account. - * - * @return The last name of the account - * @since 1.0 - */ - @GET() - @Path("/last-name") - public String getLastName() { - return lastName; - } - - /** - * Update the first name of the account. - * - * @param firstName The first name of the account. - * @since 1.0 - */ - @PUT - @Path("/first-name") - public void setFirstName(@FormParam("firstName") String firstName) { - this.firstName = firstName; - } - - /** - * Update the last name of the account. - * - * @param lastName The last name of the account. - * @since 1.0 - */ - @PUT - @Path("/last-name") - public void setLastName(@FormParam("lastName") String lastName) { - this.lastName = lastName; - } - - /** - * Returns all posts of the account. - * - * @return All posts of the account. - * @since 1.0 - */ - @GET - @Path("/posts") - @Produces(MediaType.APPLICATION_JSON_VALUE) - public List getPosts() { - return posts; - } - - /** - * Add new post of the account. - * - * @since 1.0 - */ - @POST - @Path("/posts") - public void addPost(@FormParam("content") String tweet) { - posts.add(tweet); - } - - /** - * Get the post of the account with given id. - * - * @return Specified post of the account. - * @since 1.0 - */ - @GET - @Path("/posts/{id}") - @Produces(MediaType.TEXT_PLAIN_VALUE) - public String getPost(@PathParam("id") int id) { - if (id >= posts.size()) { - return "The requested resource does not exist on the server!"; - } - return posts.get(id); - } -} diff --git a/src/main/java/com/example/jerseyexercise/resources/Yyoshimura.java b/src/main/java/com/example/jerseyexercise/resources/Yyoshimura.java deleted file mode 100644 index 2e18245..0000000 --- a/src/main/java/com/example/jerseyexercise/resources/Yyoshimura.java +++ /dev/null @@ -1,60 +0,0 @@ -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("Yyoshimura") -@Component -public class Yyoshimura { - 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}") - @FormParam(MediaType.APPLICATION_JSON) - public String getTweet(@PathParam("no") int n){ - String t; - t = tweetList.get(n); - return t; - } -} diff --git a/src/main/java/com/example/jerseyexercise/resources/himatsumto.java b/src/main/java/com/example/jerseyexercise/resources/himatsumto.java deleted file mode 100644 index 105a72f..0000000 --- a/src/main/java/com/example/jerseyexercise/resources/himatsumto.java +++ /dev/null @@ -1,60 +0,0 @@ -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; - } -} diff --git a/src/main/java/com/example/jerseyexercise/resources/natty.java b/src/main/java/com/example/jerseyexercise/resources/natty.java deleted file mode 100644 index 291a21a..0000000 --- a/src/main/java/com/example/jerseyexercise/resources/natty.java +++ /dev/null @@ -1,58 +0,0 @@ -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("natty")//クラス名MyAccountと全く違うものでも良い@はアノテーションっていうプログラムの目印 -@Component//ジャージでする時は絶対につける -public class natty { - String name = "NoName"; - ArrayList tweetList = new ArrayList<>();//AllayListのStringにしますよってするとストリングがたでリストを作れるArrayListはクラスで宣言するだけじゃなく、右辺でインスタンスを作成しないといけない - //ArrayListによく使うメソッドは4つある、 - // .add(tweet) listの末尾にtweetを追加 - // .get(index) listのindex番目の要素を取得 - // .size() listにいくつ要素が入っているのか取得 - //remove(index) listのindex番目の要素を削除 - - @GET//下にあるメソッドがGETメソッドっていうことが分かる - public String getHelloWorld(){ - return "Hello World!!"; - } - - @GET//myaccount/name のget - @Path("/name")//myaccountの子リソースができる - public String getName(){ - return name; - } - - @PUT - @Path("name/") - public void setName(@FormParam("name") String newName){ - name = newName; - }//パラーメータがname - - @POST - @Path("/tweets") - @Consumes(MediaType.APPLICATION_FORM_URLENCODED)//引数 - public void tweet(@FormParam("tweet") String tweet){ - tweetList.add(tweet); - }//tweetをリストに格納していく - - @GET - @Path("/tweets") - @Produces(MediaType.APPLICATION_JSON)//戻り値の受け取り方、文字列以外は返せない、 - public ArrayList getTweets(){ - return tweetList; - } - - @GET - @Path("/tweets/{no}")//noはパスパラメータで{}をつけることでパラメータになる - @Produces(MediaType.APPLICATION_JSON) - public String getTweet(@PathParam("no") int n){ - String t = tweetList.get(n);//tweetwListからn番目のtweetを取ってくる - return t; - } -} diff --git a/src/main/java/com/example/jerseyexercise/resources/yuna.java b/src/main/java/com/example/jerseyexercise/resources/yuna.java deleted file mode 100644 index 904e2d2..0000000 --- a/src/main/java/com/example/jerseyexercise/resources/yuna.java +++ /dev/null @@ -1,53 +0,0 @@ -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("yuna") -@Component -public class yuna { - 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); - } - - @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; - } -}