From a817d9118a8f2cfcc97d230887d5eaf6771f655c Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Sun, 17 Mar 2019 14:16:29 +0100 Subject: [PATCH 1/3] ADD::added buttons and counters for the various activities they don't have functionality yet, but they are already placed ADD::added methods to get the name of the user --- .../controller/DashBoardController.java | 28 +++++- .../greenify/client/rest/UserService.java | 38 +++++++- .../src/main/resources/fxml/dashboard.fxml | 89 ++++++++++++++++--- .../data/repository/UserRepository.java | 6 +- .../greenify/server/rest/UserController.java | 6 ++ .../greenify/server/service/UserService.java | 7 ++ 6 files changed, 154 insertions(+), 20 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java index 3e4b76e..07b5392 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -22,19 +22,41 @@ public class DashBoardController { public Button dashboardButton; public Button activitiesButton; public Button userButton; - public Button veganMealButton; - public Label counter; public Label scoreField; + //activities buttons + @FXML + public Button veganMealButton; + public Button localProduceButton; + public Button bikeButton; + public Button publicTransportButton; + public Button temperatureButton; + public Button solarPanelButton; + + //activities counters + public Label veganMealCounter; + public Label localProduceCounter; + public Label bikeCounter; + public Label publicTransportCounter; + public Label temperatureCounter; + public Label solarPanelCounter; + /** * displays the dashboard pane. * @param event the event (clicking the button) */ public void displayDashboard(ActionEvent event) { System.out.println("display dashboard"); + +// UserService service = new UserService(); +// UserDTO user = service.getName(null); +// String name = user.getName(); +// welcomebacktext.setText("Welcome back, " + name); + dashboardPane.setVisible(true); userPane.setVisible(false); activitiesPane.setVisible(false); + } /** @@ -65,7 +87,7 @@ public class DashBoardController { */ public void addVeganMeal(ActionEvent event) { count++; - counter.setText("Count: " + count); + veganMealCounter.setText("Count: " + count); UserService service = new UserService(); service.addVeganMeal(null, null); System.out.println("Vegetarian meal is added"); 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 9ede326..e951973 100644 --- a/src/Client/src/main/java/greenify/client/rest/UserService.java +++ b/src/Client/src/main/java/greenify/client/rest/UserService.java @@ -4,8 +4,9 @@ import greenify.common.UserDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.context.annotation.Bean; -import org.springframework.http.*; -import org.springframework.stereotype.Component; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @@ -25,8 +26,9 @@ public class UserService { * registers the user. * @param name the username of the user * @param password the password of the user - * @return a userDTO + * @return a built userDTO with the required information */ + @SuppressWarnings("Duplicates") public UserDTO registerUser(String name, String password) { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); @@ -38,6 +40,13 @@ public class UserService { return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class); } + /** + * logd the user in. + * @param name the username of the user + * @param password the password of the user + * @return a built userDTO with the required information + */ + @SuppressWarnings("Duplicates") public UserDTO loginUser(String name, String password) { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); @@ -49,6 +58,13 @@ public class UserService { return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class); } + /** + * adds a vegetarian meal to the user. + * @param id the id of the user + * @param name the username of the user + * @return a built userDTO with the required information + */ + @SuppressWarnings("Duplicates") public UserDTO addVeganMeal(Long id, String name) { HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); @@ -59,4 +75,20 @@ public class UserService { System.out.println(builder.build().encode().toUri()); return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class); } + + /** + * gets the username from the user. + * @param id the id of the user + * @return a UserDTO with the required information + */ + @SuppressWarnings("Duplicates") + public UserDTO getName(Long id) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getUsername") + .queryParam("id", id); + HttpEntity entity = new HttpEntity<>(headers); + System.out.println(builder.build().encode().toUri()); + return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class); + } } diff --git a/src/Client/src/main/resources/fxml/dashboard.fxml b/src/Client/src/main/resources/fxml/dashboard.fxml index 43fd60d..36e3f76 100644 --- a/src/Client/src/main/resources/fxml/dashboard.fxml +++ b/src/Client/src/main/resources/fxml/dashboard.fxml @@ -1,11 +1,15 @@ + + + + @@ -35,21 +39,84 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Server/src/main/java/greenify/server/data/repository/UserRepository.java b/src/Server/src/main/java/greenify/server/data/repository/UserRepository.java index 377f7c8..af4c6b7 100644 --- a/src/Server/src/main/java/greenify/server/data/repository/UserRepository.java +++ b/src/Server/src/main/java/greenify/server/data/repository/UserRepository.java @@ -2,11 +2,11 @@ package greenify.server.data.repository; import greenify.server.data.model.User; import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.query.Param; public interface UserRepository extends CrudRepository { - User findByName(@Param("name") String name); - // User findByName(String name); + // User findByName(@Param("name") String name); + User findByName(String name); + User findById(Long id); T save(T user); } 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 27cd303..4db7703 100644 --- a/src/Server/src/main/java/greenify/server/rest/UserController.java +++ b/src/Server/src/main/java/greenify/server/rest/UserController.java @@ -3,6 +3,7 @@ package greenify.server.rest; import greenify.common.UserDTO; import greenify.server.service.UserService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -29,4 +30,9 @@ public class UserController { @RequestParam(value = "name") String name) { userService.addVeganMeal(id, name); } + + @GetMapping("/getUsername") + public void getUsername(@RequestParam(value = "id") Long id) { + userService.getUsername(id); + } } \ No newline at end of file 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 e305920..e8baf64 100644 --- a/src/Server/src/main/java/greenify/server/service/UserService.java +++ b/src/Server/src/main/java/greenify/server/service/UserService.java @@ -64,5 +64,12 @@ public class UserService { user.setVeganMeal(count); logger.info("Added vegan meal to user(id=" + user.getId() + ", name=" + user.getName() + ")"); } + + public String getUsername(Long id) { + User user = userRepository.findById(id); + String name = user.getName(); + logger.info("retrieved username from user with username=" + name + ", id=" + id); + return name; + } } From e718e3859b46555436117f10af6c066126c664c3 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Sun, 17 Mar 2019 14:32:57 +0100 Subject: [PATCH 2/3] removed .idea folder --- src/.idea/checkstyle-idea.xml | 16 - src/.idea/checkstyleidea-libs/readme.txt | 6 - src/.idea/compiler.xml | 8 - src/.idea/encodings.xml | 4 - src/.idea/gradle.xml | 23 - src/.idea/misc.xml | 7 - src/.idea/uiDesigner.xml | 124 --- src/.idea/vcs.xml | 6 - src/.idea/workspace.xml | 985 ----------------------- 9 files changed, 1179 deletions(-) delete mode 100644 src/.idea/checkstyle-idea.xml delete mode 100644 src/.idea/checkstyleidea-libs/readme.txt delete mode 100644 src/.idea/compiler.xml delete mode 100644 src/.idea/encodings.xml delete mode 100644 src/.idea/gradle.xml delete mode 100644 src/.idea/misc.xml delete mode 100644 src/.idea/uiDesigner.xml delete mode 100644 src/.idea/vcs.xml delete mode 100644 src/.idea/workspace.xml diff --git a/src/.idea/checkstyle-idea.xml b/src/.idea/checkstyle-idea.xml deleted file mode 100644 index ef7efd6..0000000 --- a/src/.idea/checkstyle-idea.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/.idea/checkstyleidea-libs/readme.txt b/src/.idea/checkstyleidea-libs/readme.txt deleted file mode 100644 index cd71e1b..0000000 --- a/src/.idea/checkstyleidea-libs/readme.txt +++ /dev/null @@ -1,6 +0,0 @@ -This folder contains libraries copied from the "OOPP" project. -It is managed by the CheckStyle-IDEA IDE plugin. -Do not modify this folder while the IDE is running. -When the IDE is stopped, you may delete this folder at any time. It will be recreated as needed. -In order to prevent the CheckStyle-IDEA IDE plugin from creating this folder, -uncheck the "Copy libraries from project directory" option in the CheckStyle-IDEA settings dialog. diff --git a/src/.idea/compiler.xml b/src/.idea/compiler.xml deleted file mode 100644 index a1757ae..0000000 --- a/src/.idea/compiler.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/.idea/encodings.xml b/src/.idea/encodings.xml deleted file mode 100644 index 15a15b2..0000000 --- a/src/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/.idea/gradle.xml b/src/.idea/gradle.xml deleted file mode 100644 index fb07249..0000000 --- a/src/.idea/gradle.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/.idea/misc.xml b/src/.idea/misc.xml deleted file mode 100644 index bc8d0a3..0000000 --- a/src/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/.idea/uiDesigner.xml b/src/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/src/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/.idea/vcs.xml b/src/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/src/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/.idea/workspace.xml b/src/.idea/workspace.xml deleted file mode 100644 index b69fda1..0000000 --- a/src/.idea/workspace.xml +++ /dev/null @@ -1,985 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - gogreen.server.rest.* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -