diff --git a/src/Client/src/main/java/greenify/client/rest/UserService.java b/src/Client/src/main/java/greenify/client/rest/UserService.java index f07534f..9cdd50f 100644 --- a/src/Client/src/main/java/greenify/client/rest/UserService.java +++ b/src/Client/src/main/java/greenify/client/rest/UserService.java @@ -1,5 +1,6 @@ package greenify.client.rest; +import com.sun.javafx.collections.MappingChange; import greenify.common.UserDto; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; @@ -12,7 +13,10 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; +import java.awt.*; +import java.util.HashMap; import java.util.List; +import java.util.Map; @Service public class UserService { @@ -173,6 +177,23 @@ public class UserService { .encode().toUri(), String.class); } + /** + * Gets the footprint inputs of the user. + * @param name the username of the current user. + */ + @SuppressWarnings("Duplicates") + public Map getInputs(String name) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getInputs") + .queryParam("name", name); + HttpEntity entity = new HttpEntity<>(headers); + System.out.println(builder.build().encode().toUri()); + Map result = this.restTemplate.getForObject(builder.build() + .encode().toUri(), Map.class); + return result; + } + /** * Gets the list of all users. */ diff --git a/src/Server/src/main/java/greenify/server/data/model/User.java b/src/Server/src/main/java/greenify/server/data/model/User.java index 3252ee7..70d92df 100644 --- a/src/Server/src/main/java/greenify/server/data/model/User.java +++ b/src/Server/src/main/java/greenify/server/data/model/User.java @@ -10,8 +10,13 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import javax.persistence.*; - +import javax.persistence.ElementCollection; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToMany; +import javax.persistence.Table; import javax.validation.constraints.NotNull; @Entity diff --git a/src/Server/src/main/java/greenify/server/rest/UserController.java b/src/Server/src/main/java/greenify/server/rest/UserController.java index 0dab152..fd2b933 100644 --- a/src/Server/src/main/java/greenify/server/rest/UserController.java +++ b/src/Server/src/main/java/greenify/server/rest/UserController.java @@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; +import java.util.Map; @RestController public class UserController { @@ -102,6 +103,14 @@ public class UserController { return users; } + /** + * This method gets the input map of the user. + */ + @RequestMapping("/getInputs") + public Map getInputs(@RequestParam(value = "name") String name) { + return userService.getInputMap(name); + } + /** * This method adds friend for a user. * @param name name of the user diff --git a/src/Server/src/main/java/greenify/server/service/UserService.java b/src/Server/src/main/java/greenify/server/service/UserService.java index 9b9c3fb..7989e8f 100644 --- a/src/Server/src/main/java/greenify/server/service/UserService.java +++ b/src/Server/src/main/java/greenify/server/service/UserService.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; +import java.util.Map; @Service public class UserService { @@ -114,6 +115,16 @@ public class UserService { } } + /** + * This method gets the map of the inputs. + * @param name of the user + * @return input map + */ + public Map getInputMap(String name) { + User user = userRepository.findByName(name); + return user.getFootPrintInputs(); + } + /** * This method saves the footprint of a user. * @param name name of the user