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:
16
src/.idea/checkstyle-idea.xml
generated
16
src/.idea/checkstyle-idea.xml
generated
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CheckStyle-IDEA">
|
|
||||||
<option name="configuration">
|
|
||||||
<map>
|
|
||||||
<entry key="checkstyle-version" value="8.16" />
|
|
||||||
<entry key="copy-libs" value="true" />
|
|
||||||
<entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
|
|
||||||
<entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
|
|
||||||
<entry key="scan-before-checkin" value="false" />
|
|
||||||
<entry key="scanscope" value="JavaOnly" />
|
|
||||||
<entry key="suppress-errors" value="false" />
|
|
||||||
</map>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
src/.idea/checkstyleidea-libs/readme.txt
generated
6
src/.idea/checkstyleidea-libs/readme.txt
generated
@@ -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.
|
|
||||||
8
src/.idea/compiler.xml
generated
8
src/.idea/compiler.xml
generated
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<annotationProcessing>
|
|
||||||
<profile default="true" name="Default" enabled="true" />
|
|
||||||
</annotationProcessing>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
4
src/.idea/encodings.xml
generated
4
src/.idea/encodings.xml
generated
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
|
|
||||||
</project>
|
|
||||||
23
src/.idea/gradle.xml
generated
23
src/.idea/gradle.xml
generated
@@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="GradleSettings">
|
|
||||||
<option name="linkedExternalProjectsSettings">
|
|
||||||
<GradleProjectSettings>
|
|
||||||
<option name="distributionType" value="LOCAL" />
|
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
||||||
<option name="gradleHome" value="$USER_HOME$/scoop/apps/gradle/current" />
|
|
||||||
<option name="modules">
|
|
||||||
<set>
|
|
||||||
<option value="$PROJECT_DIR$/.." />
|
|
||||||
<option value="$PROJECT_DIR$" />
|
|
||||||
<option value="$PROJECT_DIR$/Client" />
|
|
||||||
<option value="$PROJECT_DIR$/Common" />
|
|
||||||
<option value="$PROJECT_DIR$/Server" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
<option name="useAutoImport" value="true" />
|
|
||||||
<option name="useQualifiedModuleNames" value="true" />
|
|
||||||
</GradleProjectSettings>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
7
src/.idea/misc.xml
generated
7
src/.idea/misc.xml
generated
@@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
124
src/.idea/uiDesigner.xml
generated
124
src/.idea/uiDesigner.xml
generated
@@ -1,124 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Palette2">
|
|
||||||
<group name="Swing">
|
|
||||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
|
||||||
</item>
|
|
||||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
|
||||||
<initial-values>
|
|
||||||
<property name="text" value="Button" />
|
|
||||||
</initial-values>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
|
||||||
<initial-values>
|
|
||||||
<property name="text" value="RadioButton" />
|
|
||||||
</initial-values>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
|
||||||
<initial-values>
|
|
||||||
<property name="text" value="CheckBox" />
|
|
||||||
</initial-values>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
|
||||||
<initial-values>
|
|
||||||
<property name="text" value="Label" />
|
|
||||||
</initial-values>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
|
||||||
<preferred-size width="150" height="-1" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
|
||||||
<preferred-size width="150" height="-1" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
|
||||||
<preferred-size width="150" height="-1" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
|
||||||
<preferred-size width="150" height="50" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
|
||||||
<preferred-size width="150" height="50" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
|
||||||
<preferred-size width="150" height="50" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
|
||||||
<preferred-size width="150" height="50" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
|
||||||
<preferred-size width="150" height="50" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
|
||||||
<preferred-size width="150" height="50" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
|
||||||
<preferred-size width="200" height="200" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
|
||||||
<preferred-size width="200" height="200" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
|
||||||
<preferred-size width="-1" height="20" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
|
||||||
</item>
|
|
||||||
</group>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
src/.idea/vcs.xml
generated
6
src/.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
@@ -6,13 +6,10 @@ import javafx.fxml.FXML;
|
|||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class DashBoardController {
|
public class DashBoardController {
|
||||||
@Autowired
|
|
||||||
UserService userService;
|
|
||||||
|
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
|
|
||||||
@@ -25,19 +22,41 @@ public class DashBoardController {
|
|||||||
public Button dashboardButton;
|
public Button dashboardButton;
|
||||||
public Button activitiesButton;
|
public Button activitiesButton;
|
||||||
public Button userButton;
|
public Button userButton;
|
||||||
public Button veganMealButton;
|
|
||||||
public Label counter;
|
|
||||||
public Label scoreField;
|
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.
|
* displays the dashboard pane.
|
||||||
* @param event the event (clicking the button)
|
* @param event the event (clicking the button)
|
||||||
*/
|
*/
|
||||||
public void displayDashboard(ActionEvent event) {
|
public void displayDashboard(ActionEvent event) {
|
||||||
System.out.println("display dashboard");
|
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);
|
dashboardPane.setVisible(true);
|
||||||
userPane.setVisible(false);
|
userPane.setVisible(false);
|
||||||
activitiesPane.setVisible(false);
|
activitiesPane.setVisible(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,9 +87,10 @@ public class DashBoardController {
|
|||||||
*/
|
*/
|
||||||
public void addVeganMeal(ActionEvent event) {
|
public void addVeganMeal(ActionEvent event) {
|
||||||
count++;
|
count++;
|
||||||
counter.setText("Count: " + count);
|
veganMealCounter.setText("Count: " + count);
|
||||||
System.out.println(userService);
|
UserService service = new UserService();
|
||||||
userService.addVeganMeal(userService.currentUser.getId(), userService.currentUser.getName());
|
service.addVeganMeal(null, null);
|
||||||
System.out.println("Vegetarian meal is added");
|
System.out.println("Vegetarian meal is added");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class RegisterWindowController {
|
|||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
public void handleSignUpButton(ActionEvent event) {
|
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();
|
Window owner = signupButton.getScene().getWindow();
|
||||||
//check if the username field is empty
|
//check if the username field is empty
|
||||||
if (userNameText.getText().isEmpty()) {
|
if (userNameText.getText().isEmpty()) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package greenify.client.controller;
|
package greenify.client.controller;
|
||||||
|
|
||||||
import greenify.client.Application;
|
|
||||||
import greenify.client.rest.UserService;
|
import greenify.client.rest.UserService;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
@@ -65,9 +64,13 @@ public class UserController {
|
|||||||
* @author sem
|
* @author sem
|
||||||
*/
|
*/
|
||||||
public void openDashboard() throws IOException {
|
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 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();
|
Stage appStage = new Stage();
|
||||||
appStage.setScene(scene);
|
appStage.setScene(scene);
|
||||||
appStage.show();
|
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
|
//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
|
//make the window use the scene
|
||||||
Scene registerScene = new Scene(registerWindow);
|
Scene registerscene = new Scene(registerWindow);
|
||||||
Stage registerStage = new Stage();
|
Stage registerStage = new Stage();
|
||||||
//open the window
|
//open the window
|
||||||
registerStage.setScene(registerScene);
|
registerStage.setScene(registerscene);
|
||||||
registerStage.setTitle("Enter register credentials");
|
registerStage.setTitle("Enter register credentials");
|
||||||
registerStage.show();
|
registerStage.show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,19 @@ 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;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Service;
|
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;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
public class UserService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
RestTemplate restTemplate;
|
RestTemplate restTemplate;
|
||||||
|
|
||||||
public UserDTO currentUser;
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
RestTemplate restTemplate(RestTemplateBuilder builder) {
|
RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
@@ -26,8 +26,9 @@ public class UserService {
|
|||||||
* registers the user.
|
* registers the user.
|
||||||
* @param name the username of the user
|
* @param name the username of the user
|
||||||
* @param password the password 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) {
|
public UserDTO registerUser(String name, String password) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
@@ -36,17 +37,16 @@ public class UserService {
|
|||||||
.queryParam("password", password);
|
.queryParam("password", password);
|
||||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||||
System.out.println(builder.build().encode().toUri());
|
System.out.println(builder.build().encode().toUri());
|
||||||
UserDTO result = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||||
this.currentUser = result;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sign ins the user.
|
* logd the user in.
|
||||||
* @param name the username of the user
|
* @param name the username of the user
|
||||||
* @param password the password 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) {
|
public UserDTO loginUser(String name, String password) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
@@ -55,17 +55,16 @@ public class UserService {
|
|||||||
.queryParam("password", password);
|
.queryParam("password", password);
|
||||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||||
System.out.println(builder.build().encode().toUri());
|
System.out.println(builder.build().encode().toUri());
|
||||||
UserDTO result = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||||
this.currentUser = result;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a user adds vegan meal.
|
* adds a vegetarian meal to the user.
|
||||||
* @param id the id of the user
|
* @param id the id of the user
|
||||||
* @param name the username 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) {
|
public UserDTO addVeganMeal(Long id, String name) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
@@ -76,4 +75,20 @@ public class UserService {
|
|||||||
System.out.println(builder.build().encode().toUri());
|
System.out.println(builder.build().encode().toUri());
|
||||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import javafx.scene.image.*?>
|
||||||
|
<?import javafx.scene.shape.*?>
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
<?import javafx.scene.image.Image?>
|
<?import javafx.scene.image.Image?>
|
||||||
<?import javafx.scene.image.ImageView?>
|
<?import javafx.scene.image.ImageView?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
<?import javafx.scene.shape.Line?>
|
<?import javafx.scene.shape.Line?>
|
||||||
<?import javafx.scene.text.*?>
|
<?import javafx.scene.text.*?>
|
||||||
|
|
||||||
<AnchorPane prefHeight="602.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
<AnchorPane prefHeight="602.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||||
<children>
|
<children>
|
||||||
<AnchorPane fx:id="menuBar" prefHeight="603.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
<AnchorPane fx:id="menuBar" prefHeight="603.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||||
@@ -35,21 +39,84 @@
|
|||||||
</children></AnchorPane>
|
</children></AnchorPane>
|
||||||
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="603.0" prefWidth="711.0" visible="false">
|
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="603.0" prefWidth="711.0" visible="false">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutX="101.0" layoutY="74.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Available Activities" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
|
<Text fill="#002c0c" layoutX="101.0" layoutY="74.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Available Activities" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="30.0" />
|
<Font size="30.0" />
|
||||||
</font>
|
</font>
|
||||||
</Text>
|
</Text>
|
||||||
<Button fx:id="veganMealButton" layoutX="60.0" layoutY="116.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" onAction="#addVeganMeal" text="Add a vegetarian meal" textFill="#e0ffe1">
|
<Pane layoutX="60.0" layoutY="93.0" prefHeight="471.0" prefWidth="291.0" style="-fx-background-color: #f4fff4;">
|
||||||
<font>
|
<children>
|
||||||
<Font size="14.0" />
|
<Button fx:id="veganMealButton" layoutX="60.0" layoutY="55.0" mnemonicParsing="false" onAction="#addVeganMeal" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Eating a vegetarian meal" textFill="#e0ffe1">
|
||||||
</font>
|
<font>
|
||||||
</Button>
|
<Font size="14.0" />
|
||||||
<Label fx:id="counter" layoutX="288.0" layoutY="110.0" prefHeight="44.0" prefWidth="115.0" text="Count: ">
|
</font>
|
||||||
<font>
|
</Button>
|
||||||
<Font size="25.0" />
|
<Button fx:id="localProduceButton" layoutX="71.0" layoutY="100.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Buying local produce" textFill="#e0ffe1">
|
||||||
</font>
|
<font>
|
||||||
</Label>
|
<Font size="14.0" />
|
||||||
|
</font>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="bikeButton" layoutX="48.0" layoutY="145.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Using a bike instead of a car" textFill="#e0ffe1">
|
||||||
|
<font>
|
||||||
|
<Font size="14.0" />
|
||||||
|
</font>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="publicTransportButton" layoutX="18.0" layoutY="190.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Using public transport instead of a car" textFill="#e0ffe1">
|
||||||
|
<font>
|
||||||
|
<Font size="14.0" />
|
||||||
|
</font>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="temperatureButton" layoutX="31.0" layoutY="235.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Lowering your home temperature" textFill="#e0ffe1">
|
||||||
|
<font>
|
||||||
|
<Font size="14.0" />
|
||||||
|
</font>
|
||||||
|
</Button>
|
||||||
|
<Button fx:id="solarPanelButton" layoutX="68.0" layoutY="280.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Installing solar panels" textFill="#e0ffe1">
|
||||||
|
<font>
|
||||||
|
<Font size="14.0" />
|
||||||
|
</font>
|
||||||
|
</Button>
|
||||||
|
</children>
|
||||||
|
</Pane>
|
||||||
|
<Pane layoutX="372.0" layoutY="93.0" prefHeight="471.0" prefWidth="291.0" style="-fx-background-color: #f4fff4;">
|
||||||
|
<children>
|
||||||
|
<Text layoutX="78.0" layoutY="37.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Activities done">
|
||||||
|
<font>
|
||||||
|
<Font size="21.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Label fx:id="veganMealCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="88.0" layoutY="55.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="localProduceCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="88.0" layoutY="100.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="bikeCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="88.0" layoutY="145.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="publicTransportCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="88.0" layoutY="190.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="temperatureCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="88.0" layoutY="235.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="solarPanelCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="88.0" layoutY="280.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
</children>
|
||||||
|
</Pane>
|
||||||
</children></AnchorPane>
|
</children></AnchorPane>
|
||||||
<AnchorPane fx:id="userPane" layoutX="215.0" layoutY="-1.0" prefHeight="603.0" prefWidth="711.0" visible="false">
|
<AnchorPane fx:id="userPane" layoutX="215.0" layoutY="-1.0" prefHeight="603.0" prefWidth="711.0" visible="false">
|
||||||
<children>
|
<children>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
@Entity
|
@Entity
|
||||||
@@ -49,7 +48,9 @@ public class User {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(Long id) { this.id = id; }
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the name.
|
* gets the name.
|
||||||
@@ -59,7 +60,9 @@ public class User {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) { this.name = name; }
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the password.
|
* gets the password.
|
||||||
@@ -69,7 +72,9 @@ public class User {
|
|||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) { this.password = password; }
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gets the number of vegan meal.
|
* gets the number of vegan meal.
|
||||||
@@ -79,58 +84,7 @@ public class User {
|
|||||||
return veganMeal;
|
return veganMeal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVeganMeal(int veganMeal) { this.veganMeal = veganMeal; }
|
public void setVeganMeal(int veganMeal) {
|
||||||
|
this.veganMeal = veganMeal;
|
||||||
/**
|
|
||||||
* checks if two users are equal.
|
|
||||||
* @param other the object to compare the user with
|
|
||||||
* @return a boolean value of true if the user is equal to the object
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object other) {
|
|
||||||
|
|
||||||
if (this == other) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (other == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (getClass() != other.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (other instanceof User) {
|
|
||||||
User that = (User) other;
|
|
||||||
return this.getName().equals(that.getName())
|
|
||||||
&& this.getId().equals(that.getId())
|
|
||||||
&& this.getPassword().equals(that.getPassword())
|
|
||||||
&& this.getVeganMeal() == that.getVeganMeal();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* creates a string of the user object.
|
|
||||||
* in the form of: User(id=, name=, password=, veganMeal=)
|
|
||||||
* @return a string of the user object
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "User(id="
|
|
||||||
+ this.id
|
|
||||||
+ ", name="
|
|
||||||
+ this.name
|
|
||||||
+ ", password="
|
|
||||||
+ this.password
|
|
||||||
+ ", veganMeal="
|
|
||||||
+ this.veganMeal + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* hashes the User object.
|
|
||||||
* @return a hashcode for the user object
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(id, name, password, veganMeal);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package greenify.server.data.repository;
|
package greenify.server.data.repository;
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
import greenify.server.data.model.User;
|
import greenify.server.data.model.User;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
public interface UserRepository extends CrudRepository<User, Integer> {
|
public interface UserRepository extends CrudRepository<User, Integer> {
|
||||||
|
// User findByName(@Param("name") String name);
|
||||||
User findByName(String name);
|
User findByName(String name);
|
||||||
|
|
||||||
|
User findById(Long id);
|
||||||
|
|
||||||
<T extends User> T save(T user);
|
<T extends User> T save(T user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,26 +11,32 @@ import greenify.server.data.model.User;
|
|||||||
import greenify.server.data.repository.UserRepository;
|
import greenify.server.data.repository.UserRepository;
|
||||||
|
|
||||||
@Controller // This means that this class is a Controller
|
@Controller // This means that this class is a Controller
|
||||||
@RequestMapping(path="/demo") // This means URL's start with /demo (after Application path)
|
@RequestMapping(path = "/demo") // This means URL's start with /demo (after Application path)
|
||||||
public class MainController {
|
public class MainController {
|
||||||
@Autowired // This means to get the bean called userRepository
|
@Autowired // This means to get the bean called userRepository
|
||||||
// Which is auto-generated by Spring, we will use it to handle the data
|
// Which is auto-generated by Spring, we will use it to handle the data
|
||||||
private UserRepository userRepository;
|
private UserRepository userRepository;
|
||||||
|
|
||||||
@GetMapping(path="/add") // Map ONLY GET Requests
|
/**
|
||||||
public @ResponseBody String addNewUser (@RequestParam String name
|
* getmapping for adding a user.
|
||||||
, @RequestParam String password) {
|
* @param name the username of the user
|
||||||
|
* @param password the password of the user
|
||||||
|
* @return a response for adding the user, "saved", if it succeeded
|
||||||
|
*/
|
||||||
|
@GetMapping(path = "/add") // Map ONLY GET Requests
|
||||||
|
public @ResponseBody String addNewUser(@RequestParam String name,
|
||||||
|
@RequestParam String password) {
|
||||||
// @ResponseBody means the returned String is the response, not a view name
|
// @ResponseBody means the returned String is the response, not a view name
|
||||||
// @RequestParam means it is a parameter from the GET or POST request
|
// @RequestParam means it is a parameter from the GET or POST request
|
||||||
|
|
||||||
User n = new User();
|
User newuser = new User();
|
||||||
n.setName(name);
|
newuser.setName(name);
|
||||||
n.setPassword(password);
|
newuser.setPassword(password);
|
||||||
userRepository.save(n);
|
userRepository.save(newuser);
|
||||||
return "Saved";
|
return "Saved";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(path="/all")
|
@GetMapping(path = "/all")
|
||||||
public @ResponseBody Iterable<User> getAllUsers() {
|
public @ResponseBody Iterable<User> getAllUsers() {
|
||||||
// This returns a JSON or XML with the users
|
// This returns a JSON or XML with the users
|
||||||
return userRepository.findAll();
|
return userRepository.findAll();
|
||||||
|
|||||||
@@ -1,21 +1,18 @@
|
|||||||
package greenify.server.rest;
|
package greenify.server.rest;
|
||||||
|
|
||||||
import greenify.common.UserDTO;
|
import greenify.common.UserDTO;
|
||||||
import greenify.server.data.model.User;
|
|
||||||
import greenify.server.data.repository.UserRepository;
|
|
||||||
import greenify.server.service.UserService;
|
import greenify.server.service.UserService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class UserController {
|
public class UserController {
|
||||||
@Autowired
|
@Autowired
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
@Autowired // This means to get the bean called userRepository
|
|
||||||
// Which is auto-generated by Spring, we will use it to handle the data
|
|
||||||
UserRepository userRepository;
|
|
||||||
|
|
||||||
@RequestMapping("/registerUser")
|
@RequestMapping("/registerUser")
|
||||||
public UserDTO registerUser(@RequestParam(value = "name") String name,
|
public UserDTO registerUser(@RequestParam(value = "name") String name,
|
||||||
@RequestParam(value = "password") String password) {
|
@RequestParam(value = "password") String password) {
|
||||||
@@ -28,16 +25,14 @@ public class UserController {
|
|||||||
return userService.loginUser(name, password);
|
return userService.loginUser(name, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(path="/all")
|
|
||||||
public @ResponseBody
|
|
||||||
Iterable<User> getAllUsers() {
|
|
||||||
// This returns a JSON or XML with the users
|
|
||||||
return userRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping("/addVeganMeal")
|
@RequestMapping("/addVeganMeal")
|
||||||
public void addVeganMeal(@RequestParam(value = "id") Long id,
|
public void addVeganMeal(@RequestParam(value = "id") Long id,
|
||||||
@RequestParam(value = "name") String name) {
|
@RequestParam(value = "name") String name) {
|
||||||
userService.addVeganMeal(id, name);
|
userService.addVeganMeal(id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getUsername")
|
||||||
|
public void getUsername(@RequestParam(value = "id") Long id) {
|
||||||
|
userService.getUsername(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -23,15 +23,16 @@ public class UserService {
|
|||||||
*/
|
*/
|
||||||
public UserDTO registerUser(String name, String password) {
|
public UserDTO registerUser(String name, String password) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
if (user == null) {
|
if (user != null) {
|
||||||
user = userRepository.save(new User(null, name, password, 0));
|
|
||||||
} else {
|
|
||||||
throw new ApplicationException("User already exists");
|
throw new ApplicationException("User already exists");
|
||||||
|
} else {
|
||||||
|
user = userRepository.save(new User(null, name, password, 0));
|
||||||
}
|
}
|
||||||
logger.info("Created user id=" + user.getId() + ", name=" + user.getName());
|
logger.info("Created user id=" + user.getId() + ", name=" + user.getName());
|
||||||
return new UserDTO(user.getId(), user.getName());
|
return new UserDTO(user.getId(), user.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* logs the user in.
|
* logs the user in.
|
||||||
* @param name the username of the user
|
* @param name the username of the user
|
||||||
@@ -54,15 +55,26 @@ public class UserService {
|
|||||||
* add vegan meal to the user.
|
* add vegan meal to the user.
|
||||||
* @param id the id of the user
|
* @param id the id of the user
|
||||||
* @param name the name of the user
|
* @param name the name of the user
|
||||||
* @return a userDTO of the user added vegan meal
|
|
||||||
*/
|
*/
|
||||||
public void addVeganMeal(Long id, String name) {
|
public void addVeganMeal(Long id, String name) {
|
||||||
User user = userRepository.findByName(name);
|
User user = userRepository.findByName(name);
|
||||||
int count = user.getVeganMeal();
|
int count = user.getVeganMeal();
|
||||||
count++;
|
count++;
|
||||||
user.setVeganMeal(count);
|
user.setVeganMeal(count);
|
||||||
userRepository.save(user);
|
logger.info("Added vegan meal to user(id="
|
||||||
logger.info("Added vegan meal to user(id=" + user.getId() + ", name=" + user.getName() + ")");
|
+ user.getId() + ", name=" + user.getName() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the username of the user with the specified id.
|
||||||
|
* @param id the id of the user
|
||||||
|
* @return the username of the user
|
||||||
|
*/
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user