Add new methods for getInputMap from database

This commit is contained in:
cugurlu
2019-03-31 15:25:40 +02:00
parent 9f45b1c8ac
commit 8e11ecbcf4
4 changed files with 48 additions and 2 deletions

View File

@@ -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<String, String> 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<String, String> result = this.restTemplate.getForObject(builder.build()
.encode().toUri(), Map.class);
return result;
}
/**
* Gets the list of all users.
*/

View File

@@ -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

View File

@@ -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<String, String> getInputs(@RequestParam(value = "name") String name) {
return userService.getInputMap(name);
}
/**
* This method adds friend for a user.
* @param name name of the user

View File

@@ -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<String, String> 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