| | package com.example.cosmos_serversb.resources; |
---|
| | |
---|
| | import javax.ws.rs.GET; |
---|
| | import javax.ws.rs.Path; |
---|
| | import com.fasterxml.jackson.core.JsonProcessingException; |
---|
| | import com.fasterxml.jackson.databind.ObjectMapper; |
---|
| | import org.springframework.stereotype.Component; |
---|
| | |
---|
| | import org.springframework.stereotype.Component; |
---|
| | import com.fasterxml.jackson.databind.ObjectMapper; |
---|
| | import com.fasterxml.jackson.core.JsonProcessingException; |
---|
| | |
---|
| | class Info { |
---|
| | public String name; |
---|
| | public String email; |
---|
| | } |
---|
| | import javax.ws.rs.*; |
---|
| | import com.example.cosmos_serversb.models.*; |
---|
| | |
---|
| | @Component |
---|
| | |
---|
| | @Path("/users") |
---|
| | public class UsersRest { |
---|
| | @GET |
---|
| | public String index() throws JsonProcessingException { |
---|
| | Info info = new Info(); |
---|
| | info.name = "tiger"; |
---|
| | info.email = "tiger@gmail.com"; |
---|
| | @POST |
---|
| | public String createUsers( |
---|
| | @FormParam("name") String name, |
---|
| | @FormParam("pw") String pw, |
---|
| | @FormParam("iconImage") String iconImage) throws JsonProcessingException { |
---|
| | ObjectMapper mapper = new ObjectMapper(); |
---|
| | String json = mapper.writeValueAsString(info); |
---|
| | String json = mapper.writeValueAsString(Users.createUser(name,pw,iconImage)); |
---|
| | |
---|
| | return json; |
---|
| | } |
---|
| | |
---|
| | @Path("/{uId}") |
---|
| | @GET |
---|
| | public String getUsersInfo( |
---|
| | @PathParam("uId") String uId, |
---|
| | @QueryParam("token") String token) throws JsonProcessingException { |
---|
| | ObjectMapper mapper = new ObjectMapper(); |
---|
| | String json = mapper.writeValueAsString(Users.getUserById("1234")); |
---|
| | |
---|
| | return json; |
---|
| | } |
---|
| | |
---|
| | @Path("/{uId}") |
---|
| | @PUT |
---|
| | public String putUsersInfo( |
---|
| | @PathParam("uId") String uId, |
---|
| | @FormParam("token") String token, |
---|
| | @FormParam("name") String name, |
---|
| | @FormParam("pw") String pw, |
---|
| | @FormParam("iconImage") String iconImage) throws JsonProcessingException { |
---|
| | ObjectMapper mapper = new ObjectMapper(); |
---|
| | String json = mapper.writeValueAsString(Users.setUser("1234","1234","1234","1234")); |
---|
| | |
---|
| | return json; |
---|
| | } |
---|
| | |
---|
| | @Path("/{uId}") |
---|
| | @DELETE |
---|
| | public String deleteUsersInfo( |
---|
| | @PathParam("uId") String uId, |
---|
| | @FormParam("token") String token) throws JsonProcessingException { |
---|
| | ObjectMapper mapper = new ObjectMapper(); |
---|
| | String json = mapper.writeValueAsString(Users.deleteUser("1234")); |
---|
| | |
---|
| | return json; |
---|
| | } |
---|
| | |
---|
| | @Path("/{uId}/login") |
---|
| | @POST |
---|
| | public String login( |
---|
| | @PathParam("uId") String uId, |
---|
| | @FormParam("pw") String pw) throws JsonProcessingException { |
---|
| | ObjectMapper mapper = new ObjectMapper(); |
---|
| | String json = mapper.writeValueAsString(Users.login("1234")); |
---|
| | |
---|
| | return json; |
---|
| | } |
---|
| | |
---|
| | @Path("/{uId}/logout") |
---|
| | @DELETE |
---|
| | public String logout( |
---|
| | @PathParam("uId") String uId, |
---|
| | @FormParam("token") String token) throws JsonProcessingException { |
---|
| | ObjectMapper mapper = new ObjectMapper(); |
---|
| | String json = mapper.writeValueAsString(Users.logout("1234")); |
---|
| | |
---|
| | return json; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |