Add new methods for getInputMap from database
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package greenify.client.rest;
|
package greenify.client.rest;
|
||||||
|
|
||||||
|
import com.sun.javafx.collections.MappingChange;
|
||||||
import greenify.common.UserDto;
|
import greenify.common.UserDto;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
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.client.RestTemplate;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
public class UserService {
|
||||||
@@ -173,6 +177,23 @@ public class UserService {
|
|||||||
.encode().toUri(), String.class);
|
.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.
|
* Gets the list of all users.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -10,8 +10,13 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
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;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class UserController {
|
public class UserController {
|
||||||
@@ -102,6 +103,14 @@ public class UserController {
|
|||||||
return users;
|
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.
|
* This method adds friend for a user.
|
||||||
* @param name name of the user
|
* @param name name of the user
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
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.
|
* This method saves the footprint of a user.
|
||||||
* @param name name of the user
|
* @param name name of the user
|
||||||
|
|||||||
Reference in New Issue
Block a user