Merge branch 'add_veganMealCounter' into 'master'
Merge branch add_veganMealCounter into master See merge request cse1105/2018-2019/oopp-group-43/template!32
This commit is contained in:
@@ -3,7 +3,6 @@ package greenify.client.controller;
|
|||||||
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;
|
||||||
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.beans.factory.annotation.Autowired;
|
||||||
@@ -16,31 +15,21 @@ public class DashBoardController {
|
|||||||
|
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
|
|
||||||
@FXML
|
|
||||||
private AnchorPane menuBar;
|
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane dashboardPane;
|
private AnchorPane dashboardPane;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane userPane;
|
private AnchorPane userPane;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane activitiesPane;
|
private AnchorPane activitiesPane;
|
||||||
@FXML
|
|
||||||
private Label welcomebacktext;
|
|
||||||
@FXML
|
|
||||||
private Button dashboardButton;
|
|
||||||
@FXML
|
|
||||||
private Button activitiesButton;
|
|
||||||
@FXML
|
|
||||||
private Button userButton;
|
|
||||||
@FXML
|
|
||||||
private Button veganMealButton;
|
|
||||||
@FXML
|
|
||||||
private Label counter;
|
|
||||||
@FXML
|
|
||||||
private Label scoreField;
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label veganMealCounter;
|
private Label veganMealCounter;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label totalVeganMealCounter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* displays the dashboard pane.
|
* displays the dashboard pane.
|
||||||
* @param event the event (clicking the button)
|
* @param event the event (clicking the button)
|
||||||
@@ -57,6 +46,7 @@ public class DashBoardController {
|
|||||||
* @param event the event (clicking the button)
|
* @param event the event (clicking the button)
|
||||||
*/
|
*/
|
||||||
public void displayActivities(ActionEvent event) {
|
public void displayActivities(ActionEvent event) {
|
||||||
|
totalVeganMealCounter.setText("" + userService.currentUser.getVeganMeal());
|
||||||
System.out.println("display activities");
|
System.out.println("display activities");
|
||||||
dashboardPane.setVisible(false);
|
dashboardPane.setVisible(false);
|
||||||
userPane.setVisible(false);
|
userPane.setVisible(false);
|
||||||
@@ -80,7 +70,9 @@ public class DashBoardController {
|
|||||||
*/
|
*/
|
||||||
public void addVeganMeal(ActionEvent event) {
|
public void addVeganMeal(ActionEvent event) {
|
||||||
count++;
|
count++;
|
||||||
veganMealCounter.setText("Count: " + count);
|
int net = userService.currentUser.getVeganMeal() + count;
|
||||||
|
totalVeganMealCounter.setText("" + net);
|
||||||
|
veganMealCounter.setText("" + count);
|
||||||
System.out.println(userService);
|
System.out.println(userService);
|
||||||
userService.addVeganMeal(userService.currentUser.getId(),
|
userService.addVeganMeal(userService.currentUser.getId(),
|
||||||
userService.currentUser.getName());
|
userService.currentUser.getName());
|
||||||
|
|||||||
@@ -24,10 +24,13 @@ public class UserController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField usernameField;
|
private TextField usernameField;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private PasswordField passwordField;
|
private PasswordField passwordField;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button loginButton;
|
private Button loginButton;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button signupButton;
|
private Button signupButton;
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import org.springframework.http.HttpEntity;
|
|||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
|
|
||||||
@@ -79,4 +81,9 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping("/userData")
|
||||||
|
public int getVeganData(@RequestParam(value = "veganMeal") int veganMeal) {
|
||||||
|
return veganMeal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import java.lang.*?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.image.*?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.shape.*?>
|
|
||||||
<?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.AnchorPane?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
|
<?import javafx.scene.layout.Pane?>
|
||||||
|
<?import javafx.scene.layout.VBox?>
|
||||||
<?import javafx.scene.shape.Line?>
|
<?import javafx.scene.shape.Line?>
|
||||||
<?import javafx.scene.text.*?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
<?import javafx.scene.text.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/10.0.1" 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;">
|
||||||
<children>
|
<children>
|
||||||
@@ -44,7 +46,7 @@
|
|||||||
<Font size="30.0" />
|
<Font size="30.0" />
|
||||||
</font>
|
</font>
|
||||||
</Text>
|
</Text>
|
||||||
<Pane layoutX="60.0" layoutY="93.0" prefHeight="471.0" prefWidth="291.0" style="-fx-background-color: #f4fff4;">
|
<Pane layoutX="20.0" layoutY="93.0" prefHeight="471.0" prefWidth="280.0" style="-fx-background-color: #f4fff4;">
|
||||||
<children>
|
<children>
|
||||||
<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">
|
<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>
|
||||||
@@ -78,39 +80,78 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</children>
|
</children>
|
||||||
</Pane>
|
</Pane>
|
||||||
<Pane layoutX="372.0" layoutY="93.0" prefHeight="471.0" prefWidth="291.0" style="-fx-background-color: #f4fff4;">
|
<Pane layoutX="310.0" layoutY="93.0" prefHeight="471.0" prefWidth="150.0" style="-fx-background-color: #f4fff4;">
|
||||||
<children>
|
<children>
|
||||||
<Text layoutX="78.0" layoutY="37.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Activities done">
|
<Text layoutX="48.0" layoutY="37.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Count" textAlignment="CENTER">
|
||||||
<font>
|
<font>
|
||||||
<Font size="21.0" />
|
<Font size="21.0" />
|
||||||
</font>
|
</font>
|
||||||
</Text>
|
</Text>
|
||||||
<Label fx:id="veganMealCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="88.0" layoutY="55.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
<Label fx:id="veganMealCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="55.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Label fx:id="localProduceCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="88.0" layoutY="100.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
<Label fx:id="localProduceCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="100.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Label fx:id="bikeCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="88.0" layoutY="145.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
<Label fx:id="bikeCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="145.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Label fx:id="publicTransportCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="88.0" layoutY="190.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
<Label fx:id="publicTransportCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="190.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Label fx:id="temperatureCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="88.0" layoutY="235.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
<Label fx:id="temperatureCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="235.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<Label fx:id="solarPanelCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="88.0" layoutY="280.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
<Label fx:id="solarPanelCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="280.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
</children>
|
||||||
|
</Pane>
|
||||||
|
<Pane layoutX="470.0" layoutY="93.0" prefHeight="471.0" prefWidth="150.0" style="-fx-background-color: #f4fff4;">
|
||||||
|
<children>
|
||||||
|
<Text layoutX="7.0" layoutY="37.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Activities done">
|
||||||
|
<font>
|
||||||
|
<Font size="21.0" />
|
||||||
|
</font>
|
||||||
|
</Text>
|
||||||
|
<Label fx:id="totalVeganMealCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="55.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="totalLocalProduceCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="100.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="totalBikeCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="145.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="totalPublicTransportCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="190.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="totalTemperatureCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="235.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
|
<font>
|
||||||
|
<Font size="18.0" />
|
||||||
|
</font>
|
||||||
|
</Label>
|
||||||
|
<Label fx:id="totalSolarPanelCounter" alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="280.0" prefHeight="30.0" prefWidth="115.0" text="0">
|
||||||
<font>
|
<font>
|
||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void userRegisterTest() throws Exception {
|
public void userRegisterTest() throws Exception {
|
||||||
UserDto testUser = new UserDto(1L, "Eric");
|
UserDto testUser = new UserDto(1L, "Eric", 0);
|
||||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/registerUser?name=Eric&password=password"),
|
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/registerUser?name=Eric&password=password"),
|
||||||
UserDto.class))
|
UserDto.class))
|
||||||
.thenReturn(testUser);
|
.thenReturn(testUser);
|
||||||
@@ -36,7 +36,7 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void userLoginTest() throws Exception {
|
public void userLoginTest() throws Exception {
|
||||||
UserDto testUser = new UserDto(1L, "Eric");
|
UserDto testUser = new UserDto(1L, "Eric", 0);
|
||||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/loginUser?name=Eric&password=password"),
|
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/loginUser?name=Eric&password=password"),
|
||||||
UserDto.class))
|
UserDto.class))
|
||||||
.thenReturn(testUser);
|
.thenReturn(testUser);
|
||||||
@@ -46,7 +46,7 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addVeganMealTest() throws Exception {
|
public void addVeganMealTest() throws Exception {
|
||||||
UserDto testUser = new UserDto(1L, "Eric");
|
UserDto testUser = new UserDto(1L, "Eric", 0);
|
||||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/addVeganMeal?id=1&name=Eric"),
|
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/addVeganMeal?id=1&name=Eric"),
|
||||||
UserDto.class))
|
UserDto.class))
|
||||||
.thenReturn(testUser);
|
.thenReturn(testUser);
|
||||||
|
|||||||
@@ -7,13 +7,21 @@ package greenify.common;
|
|||||||
public class UserDto {
|
public class UserDto {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String name;
|
private String name;
|
||||||
|
private int veganMeal;
|
||||||
|
|
||||||
public UserDto() {
|
public UserDto() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserDto(Long id, String name) {
|
/**
|
||||||
|
* The constructor method of UserDto.
|
||||||
|
* @param id of the user
|
||||||
|
* @param name of the user
|
||||||
|
* @param veganMeal the number of vegetarian meals eaten
|
||||||
|
*/
|
||||||
|
public UserDto(Long id, String name, int veganMeal) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.veganMeal = veganMeal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -31,4 +39,12 @@ public class UserDto {
|
|||||||
public void setId(Long id) {
|
public void setId(Long id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getVeganMeal() {
|
||||||
|
return veganMeal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVeganMeal(int veganMeal) {
|
||||||
|
this.veganMeal = veganMeal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,18 +7,20 @@ import org.junit.Test;
|
|||||||
public class UserDtoTest {
|
public class UserDtoTest {
|
||||||
@Test
|
@Test
|
||||||
public void setAndGetTest() {
|
public void setAndGetTest() {
|
||||||
UserDto user = new UserDto(1L, "greenify");
|
|
||||||
UserDto testUser = new UserDto();
|
UserDto testUser = new UserDto();
|
||||||
testUser.setId(1L);
|
testUser.setId(1L);
|
||||||
testUser.setName("greenify");
|
testUser.setName("greenify");
|
||||||
|
testUser.setVeganMeal(0);
|
||||||
|
UserDto user = new UserDto(1L, "greenify", 0);
|
||||||
assertTrue(user.getId() == 1L);
|
assertTrue(user.getId() == 1L);
|
||||||
assertEquals(user.getName(), "greenify");
|
assertEquals(user.getName(), "greenify");
|
||||||
|
assertTrue(user.getVeganMeal() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void equalsTest() {
|
public void equalsTest() {
|
||||||
UserDto first = new UserDto(1L, "greenify");
|
UserDto first = new UserDto(1L, "greenify", 0);
|
||||||
UserDto second = new UserDto(1L, "greenify");
|
UserDto second = new UserDto(1L, "greenify", 0);
|
||||||
assertEquals(first.getId(), second.getId());
|
assertEquals(first.getId(), second.getId());
|
||||||
assertEquals(first.getName(), second.getName());
|
assertEquals(first.getName(), second.getName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
package greenify.server.data.model;
|
package greenify.server.data.model;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import javax.persistence.*;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
@Table(name = "activities")
|
@Table(name = "activities")
|
||||||
|
|
||||||
public class Activity {
|
public class Activity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@@ -107,23 +107,19 @@ public class Activity {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Activity(id=" + this.id + ", name=" + this.name + ", description=" + this.description + ", score=" + this.score + ")";
|
return "Activity(id=" + this.id + ", name=" + this.name + ", description="
|
||||||
|
+ this.description + ", score=" + this.score + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (other instanceof Activity) {
|
if (other instanceof Activity) {
|
||||||
Activity that = (Activity)other;
|
Activity that = (Activity)other;
|
||||||
if(that.id != this.id)
|
if (that.id == this.id && that.name.equals(this.name)
|
||||||
return false;
|
&& that.description.equals(this.description) && that.score == this.score) {
|
||||||
if(!that.name.equals(this.name))
|
|
||||||
return false;
|
|
||||||
if(!that.description.equals(this.description))
|
|
||||||
return false;
|
|
||||||
if(that.score != this.score)
|
|
||||||
return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package greenify.server.data.model;
|
package greenify.server.data.model;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.GeneratedValue;
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import javax.persistence.GenerationType;
|
||||||
@@ -10,7 +10,6 @@ import javax.persistence.Id;
|
|||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
@EnableAutoConfiguration
|
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
@Table(name = "users")
|
@Table(name = "users")
|
||||||
@@ -92,20 +91,31 @@ public class User {
|
|||||||
this.veganMeal = veganMeal;
|
this.veganMeal = veganMeal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a human readable object. It's in JSON.
|
||||||
|
* @return the JSON form of the object.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User(id=" + this.id + ", name=" + this.name + ", password="
|
||||||
|
+ this.password + ", veganMeal=" + this.veganMeal + ")";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (other instanceof User) {
|
if (other instanceof User) {
|
||||||
User that = (User)other;
|
User that = (User)other;
|
||||||
if(that.id != this.id)
|
if (that.id == this.id && that.name.equals(this.name)
|
||||||
return false;
|
&& that.password.equals(this.password) && that.veganMeal == this.veganMeal) {
|
||||||
if(!that.name.equals(this.name))
|
|
||||||
return false;
|
|
||||||
if(!that.password.equals(this.password))
|
|
||||||
return false;
|
|
||||||
if(that.veganMeal != this.veganMeal)
|
|
||||||
return false;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, name, password, veganMeal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
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.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class UserService {
|
|||||||
throw new ApplicationException("User already exists");
|
throw new ApplicationException("User already exists");
|
||||||
}
|
}
|
||||||
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(), user.getVeganMeal());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +50,7 @@ public class UserService {
|
|||||||
throw new ApplicationException("Wrong password");
|
throw new ApplicationException("Wrong password");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new UserDto(user.getId(), user.getName());
|
return new UserDto(user.getId(), user.getName(), user.getVeganMeal());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package greenify.server.data.model;
|
package greenify.server.data.model;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -39,6 +40,13 @@ public class ActivityTest {
|
|||||||
assertTrue(first.equals(second));
|
assertTrue(first.equals(second));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void notEqualsTest() {
|
||||||
|
Activity first = new Activity(1, "Solar panels", "Installed", 10000);
|
||||||
|
Activity second = new Activity(2, "Solar panels", "Installed", 10000);
|
||||||
|
assertFalse(first.equals(second));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hashCodeTest() {
|
public void hashCodeTest() {
|
||||||
Activity first = new Activity(1, "Solar panels", "Installed", 10000);
|
Activity first = new Activity(1, "Solar panels", "Installed", 10000);
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ public class UserTest {
|
|||||||
assertTrue(first.equals(second));
|
assertTrue(first.equals(second));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void notEqualsTest() {
|
||||||
|
User first = new User(1L, "greenify", "password", 3);
|
||||||
|
User second = new User(1L, "greenify", "password", 7);
|
||||||
|
assertFalse(first.equals(second));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void instanceOfTest() {
|
public void instanceOfTest() {
|
||||||
User first = new User();
|
User first = new User();
|
||||||
@@ -50,8 +57,8 @@ public class UserTest {
|
|||||||
public void hashCodeTest() {
|
public void hashCodeTest() {
|
||||||
User first = new User(1L, "greenify", "password", 3);
|
User first = new User(1L, "greenify", "password", 3);
|
||||||
User second = new User(1L, "greenify", "password", 3);
|
User second = new User(1L, "greenify", "password", 3);
|
||||||
assertTrue(first.equals(second) && second.equals(first));
|
|
||||||
assertEquals(first, second);
|
assertEquals(first, second);
|
||||||
|
assertEquals(first.hashCode(), second.hashCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class UserControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void registerUserTest() throws Exception {
|
public void registerUserTest() throws Exception {
|
||||||
given(this.userService.registerUser("name", "password"))
|
given(this.userService.registerUser("name", "password"))
|
||||||
.willReturn(new UserDto(1L, "name"));
|
.willReturn(new UserDto(1L, "name", 0));
|
||||||
mvc.perform(get("/registerUser")
|
mvc.perform(get("/registerUser")
|
||||||
.param("name", "name")
|
.param("name", "name")
|
||||||
.param("password", "password")
|
.param("password", "password")
|
||||||
@@ -46,7 +46,7 @@ public class UserControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void loginUserTest() throws Exception {
|
public void loginUserTest() throws Exception {
|
||||||
given(this.userService.loginUser("ceren", "password"))
|
given(this.userService.loginUser("ceren", "password"))
|
||||||
.willReturn(new UserDto(1L, "ceren"));
|
.willReturn(new UserDto(1L, "ceren", 0));
|
||||||
mvc.perform(get("/loginUser")
|
mvc.perform(get("/loginUser")
|
||||||
.param("name", "ceren")
|
.param("name", "ceren")
|
||||||
.param("password", "password")
|
.param("password", "password")
|
||||||
|
|||||||
@@ -56,25 +56,6 @@ public class UserServiceTest {
|
|||||||
assertEquals(userRepository.findAll(), userService.getAllUsers());
|
assertEquals(userRepository.findAll(), userService.getAllUsers());
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void validRegisterTest() {
|
|
||||||
// String name = "new";
|
|
||||||
// String password = "user";
|
|
||||||
// if(userRepository.findByName(name) == null) {
|
|
||||||
// UserDto found = userService.registerUser(name, password);
|
|
||||||
// assertEquals(found.getName(), name);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void addVeganMealTest() {
|
|
||||||
// User user = new User(1L, "name", "password", 0);
|
|
||||||
// User user = userRepository.findByName("x");
|
|
||||||
// int veganMeal = user.getVeganMeal();
|
|
||||||
// userService.addVeganMeal(user.getId(), user.getName());
|
|
||||||
// assertEquals(user.getVeganMeal(), veganMeal++);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invalidLoginTest() {
|
public void invalidLoginTest() {
|
||||||
User user = null;
|
User user = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user