Merge branch 'Develop_GUI_further' into master
# Conflicts: # src/.idea/workspace.xml # src/Client/src/main/java/greenify/client/controller/DashBoardController.java # src/Client/src/main/java/greenify/client/controller/UserController.java # src/Client/src/main/java/greenify/client/rest/UserService.java # src/Server/src/main/java/greenify/server/data/model/User.java # src/Server/src/main/java/greenify/server/data/repository/UserRepository.java # src/Server/src/main/java/greenify/server/rest/UserController.java # src/Server/src/main/java/greenify/server/service/UserService.java resolved conflicts manually, used the ones from 'Develop_GUI_further'
This commit is contained in:
@@ -6,13 +6,10 @@ import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class DashBoardController {
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
private int count = 0;
|
||||
|
||||
@@ -25,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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,9 +87,10 @@ public class DashBoardController {
|
||||
*/
|
||||
public void addVeganMeal(ActionEvent event) {
|
||||
count++;
|
||||
counter.setText("Count: " + count);
|
||||
System.out.println(userService);
|
||||
userService.addVeganMeal(userService.currentUser.getId(), userService.currentUser.getName());
|
||||
veganMealCounter.setText("Count: " + count);
|
||||
UserService service = new UserService();
|
||||
service.addVeganMeal(null, null);
|
||||
System.out.println("Vegetarian meal is added");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class RegisterWindowController {
|
||||
*/
|
||||
@FXML
|
||||
public void handleSignUpButton(ActionEvent event) {
|
||||
//set the window to the current window (for displaying the alerts)
|
||||
//set the window to the current window (for displaying the alerts)
|
||||
Window owner = signupButton.getScene().getWindow();
|
||||
//check if the username field is empty
|
||||
if (userNameText.getText().isEmpty()) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package greenify.client.controller;
|
||||
|
||||
import greenify.client.Application;
|
||||
import greenify.client.rest.UserService;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
@@ -65,9 +64,13 @@ public class UserController {
|
||||
* @author sem
|
||||
*/
|
||||
public void openDashboard() throws IOException {
|
||||
Parent dash = Application.load (this.getClass().getClassLoader().getResource("fxml/dashboard.fxml"));
|
||||
Parent dash = FXMLLoader.load(
|
||||
this.getClass().getClassLoader().getResource("fxml/dashboard.fxml")
|
||||
);
|
||||
Scene scene = new Scene(dash);
|
||||
scene.getStylesheets().add(getClass().getClassLoader().getResource("stylesheets/dashboardStyle.css").toExternalForm());
|
||||
scene.getStylesheets().add(getClass()
|
||||
.getClassLoader()
|
||||
.getResource("stylesheets/dashboardStyle.css").toExternalForm());
|
||||
Stage appStage = new Stage();
|
||||
appStage.setScene(scene);
|
||||
appStage.show();
|
||||
@@ -94,14 +97,22 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
|
||||
public void handleRegisterButtonAction(ActionEvent event) throws Exception{
|
||||
/**
|
||||
* handles the click of the 'sign up' button.
|
||||
* opens a new stage where the user can register.
|
||||
* @param event the click of the button
|
||||
* @throws Exception an exception if the fxml file is not found
|
||||
*/
|
||||
public void handleRegisterButtonAction(ActionEvent event) throws Exception {
|
||||
//load the fxml file
|
||||
Parent registerWindow = Application.load (this.getClass().getClassLoader().getResource("fxml/RegisterWindow.fxml"));
|
||||
Parent registerWindow = FXMLLoader.load(
|
||||
this.getClass().getClassLoader().getResource("fxml/RegisterWindow.fxml")
|
||||
);
|
||||
//make the window use the scene
|
||||
Scene registerScene = new Scene(registerWindow);
|
||||
Scene registerscene = new Scene(registerWindow);
|
||||
Stage registerStage = new Stage();
|
||||
//open the window
|
||||
registerStage.setScene(registerScene);
|
||||
registerStage.setScene(registerscene);
|
||||
registerStage.setTitle("Enter register credentials");
|
||||
registerStage.show();
|
||||
}
|
||||
|
||||
@@ -4,19 +4,19 @@ 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;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
public UserDTO currentUser;
|
||||
|
||||
@Bean
|
||||
RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||
return builder.build();
|
||||
@@ -26,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);
|
||||
@@ -36,17 +37,16 @@ public class UserService {
|
||||
.queryParam("password", password);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
UserDTO result = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
this.currentUser = result;
|
||||
return result;
|
||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* sign ins the user.
|
||||
* logd the user in.
|
||||
* @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 loginUser(String name, String password) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
@@ -55,17 +55,16 @@ public class UserService {
|
||||
.queryParam("password", password);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
UserDTO result = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
this.currentUser = result;
|
||||
return result;
|
||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* a user adds vegan meal.
|
||||
* adds a vegetarian meal to the user.
|
||||
* @param id the id of the user
|
||||
* @param name the username of the user
|
||||
* @return a userDTO
|
||||
* @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);
|
||||
@@ -76,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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user