diff --git a/src/main/java/com/example/jerseyexercise/resources/PocchamaRest.java b/src/main/java/com/example/jerseyexercise/resources/PocchamaRest.java new file mode 100644 index 0000000..88325d1 --- /dev/null +++ b/src/main/java/com/example/jerseyexercise/resources/PocchamaRest.java @@ -0,0 +1,50 @@ +package com.example.jerseyexercise.resources; +//import jakarta.annotation.PostConstruct; +import jakarta.ws.rs.*; +import jakarta.ws.rs.core.MediaType; +import org.springframework.stereotype.Component; +import java.util.HashMap; +import java.util.Set; +//import javax.print.attribute.standard.Media; + +//get: /monaka ->全アカウントの一覧 +//post: /monaka ->新規アカウント登録 + +//get: /monaka/{id} ->idで指定したaccountの名前を返す +//put: /monaka/{id} ->idで指定したaccountの名前をnameに変更する + + +@Path("/pocchama") +@Component + +public class PocchamaRest { + private HashMap accounts = new HashMap<>(); + @GET + @Produces(MediaType.APPLICATION_JSON)//returnの形をどうするか + public Set getAccounts(){ + return accounts.keySet(); + } + + + @POST + @Consumes(MediaType.APPLICATION_FORM_URLENCODED)//こっちよく使う + public void signup(@FormParam("id") String id, @FormParam("name") String name) { + accounts.put(id, name);//nameは同じことがある + } + + + @Path("/{id}") + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getName(@PathParam("id") String id) { + return accounts.get(id); + } + + @Path("/{id}") + @PUT + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public void setName(@PathParam("id") String id, @FormParam("name") String name) { + if(accounts.get(id) == null) return; + accounts.put(id, name); + } +}