diff --git a/src/main/java/com/example/jerseyexercise/resources/SakodaRest.java b/src/main/java/com/example/jerseyexercise/resources/SakodaRest.java new file mode 100644 index 0000000..a9ce0e4 --- /dev/null +++ b/src/main/java/com/example/jerseyexercise/resources/SakodaRest.java @@ -0,0 +1,51 @@ +package com.example.jerseyexercise.resources; + +import jakarta.ws.rs.*; +import jakarta.ws.rs.core.MediaType; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Set; + +@Path("/sakoda") +@Component +public class SakodaRest { + + private HashMap accounts = new HashMap<>(); + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Set getAccounts(){ + return accounts.keySet(); + } + + @POST + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public void signup(@FormParam("id") String id, @FormParam("name") String name){ + if(accounts.containsKey(id)){ + return; + }else{ + accounts.put(id, name); + } + } + + @GET + @Path("/{id}") + @Produces(MediaType.TEXT_PLAIN) + public String getName(@PathParam("id") String id){ + return accounts.get(id); + } + + @PUT + @Path("/{id}") + @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + public void setName(@PathParam("id") String id, @FormParam("name") String name){ + if(accounts.containsKey(id)){ + accounts.put(id, name); + }else{ + return; + } + + } + +} \ No newline at end of file