Merge branch 'master' into 'Add_registering_GUI'
# Conflicts: # src/Client/src/main/java/greenify/client/Application.java # src/Client/src/main/java/greenify/client/controller/UserController.java # src/Client/src/main/resources/stylesheets/dashboardStyle.css
This commit is contained in:
34
build.gradle
34
build.gradle
@@ -21,11 +21,9 @@ apply plugin: 'checkstyle'
|
||||
apply plugin: 'application'
|
||||
|
||||
application {
|
||||
mainClassName = 'greenify.client.Application'
|
||||
mainClassName = 'greenify.server.Application'
|
||||
}
|
||||
|
||||
//apply plugin: 'org.openjfx.javafxplugin'
|
||||
|
||||
tasks.withType(Checkstyle) {
|
||||
reports {
|
||||
html.destination rootProject.file("build/reports/checkstyle.html")
|
||||
@@ -36,16 +34,32 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
//client bootjar
|
||||
bootJar {
|
||||
baseName = 'gs-consuming-rest'
|
||||
version = '0.1.0'
|
||||
allprojects {
|
||||
task hello {
|
||||
doLast { task ->
|
||||
println "I'm $task.project.name"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//server bootjar
|
||||
////client bootjar
|
||||
//bootJar {
|
||||
// baseName = 'gs-consuming-rest'
|
||||
// version = '0.1.0'
|
||||
//}
|
||||
//
|
||||
////server bootjar
|
||||
//bootJar {
|
||||
// baseName = 'gs-rest-service'
|
||||
// version = '0.1.0'
|
||||
//}
|
||||
|
||||
bootJar {
|
||||
baseName = 'gs-rest-service'
|
||||
version = '0.1.0'
|
||||
enabled = false
|
||||
}
|
||||
|
||||
jar {
|
||||
enabled = true
|
||||
}
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
|
||||
# Sprint Review
|
||||
|
||||
## Main problems Encountered
|
||||
|
||||
We have no problems so far. Everyone arrives on time and does the tasks assigned to them.
|
||||
|
||||
## Adjustments from previous sprints
|
||||
Since this is the first review, there are no previous sprints yet
|
||||
|
||||
## Adjustments for next sprint
|
||||
- Keep up the good work!
|
||||
@@ -1,14 +0,0 @@
|
||||
|
||||
# Sprint Review
|
||||
|
||||
## Main problems Encountered
|
||||
|
||||
### Problem 1: Kristin left the group
|
||||
Kristin does not continue CSE and left our group. We'll work with five people from now on.
|
||||
|
||||
## Adjustments from previous sprints
|
||||
We created the backlog before the sprint, which helps making clear what we're working on.
|
||||
|
||||
## Adjustments for next sprint
|
||||
- Group made out of five
|
||||
- Backlogs ready on time
|
||||
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 88 KiB |
1
src/.idea/gradle.xml
generated
1
src/.idea/gradle.xml
generated
@@ -8,6 +8,7 @@
|
||||
<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" />
|
||||
|
||||
6
src/.idea/vcs.xml
generated
Normal file
6
src/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
785
src/.idea/workspace.xml
generated
785
src/.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
@@ -21,11 +21,6 @@ public class Application extends javafx.application.Application {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// public RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||
// return builder.build();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
springContext = SpringApplication.run(Application.class);
|
||||
@@ -50,14 +45,4 @@ public class Application extends javafx.application.Application {
|
||||
public void stop() {
|
||||
springContext.stop();
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
|
||||
// return args -> {
|
||||
// User user = restTemplate.getForObject(
|
||||
// "http://localhost:8080/user", User.class);
|
||||
// log.info(user.toString());
|
||||
//
|
||||
// };
|
||||
// }
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.effect.DropShadow;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -26,8 +25,9 @@ public class DashBoardController {
|
||||
public Button dashboardButton;
|
||||
public Button activitiesButton;
|
||||
public Button userButton;
|
||||
public Label scoreField;
|
||||
|
||||
DropShadow shadow = new DropShadow();
|
||||
// DropShadow shadow = new DropShadow();
|
||||
|
||||
|
||||
/**
|
||||
@@ -35,10 +35,13 @@ public class DashBoardController {
|
||||
* @param event the event (clicking the button)
|
||||
*/
|
||||
public void displayDashboard(ActionEvent event) {
|
||||
|
||||
System.out.println("display dashboard");
|
||||
dashboardPane.setVisible(true);
|
||||
userPane.setVisible(false);
|
||||
activitiesPane.setVisible(false);
|
||||
|
||||
|
||||
// welcomebacktext.setText("Welcome back, " + UserController.getUsernameText() + "!");
|
||||
}
|
||||
|
||||
@@ -63,6 +66,8 @@ public class DashBoardController {
|
||||
userPane.setVisible(true);
|
||||
activitiesPane.setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
// public void addShadow(MouseEvent event) {
|
||||
// userButton.setEffect(shadow);
|
||||
// }
|
||||
|
||||
@@ -34,21 +34,6 @@ public class UserController {
|
||||
@FXML
|
||||
private Button signupButton;
|
||||
|
||||
|
||||
|
||||
|
||||
// @Value("${my.url}")
|
||||
// private String myUrl;
|
||||
|
||||
// @FXML
|
||||
// private void initialize(ActionEvent event) throws IOException {
|
||||
// Parent parent = FXMLLoader.load(getClass().getResource("sample.fxml"));
|
||||
// Scene scene = new Scene(parent);
|
||||
// Stage app_stage = (Stage)((Node) event.getSource()).getScene().getWindow();
|
||||
// app_stage.setScene(scene);
|
||||
// app_stage.show();
|
||||
// }
|
||||
|
||||
@FXML
|
||||
protected void handleLoginButtonAction(ActionEvent event) throws IOException {
|
||||
Window owner = loginButton.getScene().getWindow();
|
||||
@@ -94,22 +79,18 @@ public class UserController {
|
||||
* @author sem
|
||||
*/
|
||||
public void openDashboard() throws IOException {
|
||||
// Font.loadFont(getClass().getResourceAsStream("stylesheets/DesignioRegular.otf"), 21);
|
||||
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());
|
||||
Stage appStage = new Stage();
|
||||
appStage.setScene(scene);
|
||||
// app_stage.setFullScreen(true);
|
||||
appStage.show();
|
||||
}
|
||||
|
||||
// public final String getUsernameText() {
|
||||
//
|
||||
// return user.getName();
|
||||
// }
|
||||
|
||||
|
||||
public static class AlertHelper {
|
||||
/**
|
||||
* alerts for the login screen.
|
||||
|
||||
BIN
src/Client/src/main/resources/addActivity1.png
Normal file
BIN
src/Client/src/main/resources/addActivity1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.2 KiB |
BIN
src/Client/src/main/resources/addActivity2.png
Normal file
BIN
src/Client/src/main/resources/addActivity2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.2 KiB |
@@ -1,5 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.shape.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.collections.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import java.lang.*?>
|
||||
@@ -11,28 +13,30 @@
|
||||
|
||||
<AnchorPane prefHeight="602.0" prefWidth="926.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<children>
|
||||
<AnchorPane fx:id="menuBar" prefHeight="603.0" prefWidth="216.0" style="-fx-background-color: #545b4f;">
|
||||
<AnchorPane fx:id="menuBar" prefHeight="603.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||
<children>
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutY="-2.0" prefHeight="90.0" prefWidth="216.0" text="Go Green" textAlignment="CENTER" textFill="#07a11c">
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutY="-2.0" prefHeight="90.0" prefWidth="216.0" text="Go Green" textAlignment="CENTER" textFill="#71bc84">
|
||||
<font>
|
||||
<Font size="36.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Button fx:id="dashboardButton" layoutY="88.0" mnemonicParsing="false" onAction="#displayDashboard" prefHeight="45.0" prefWidth="216.0" style="-fx-background-color: #5a635c;" text="dashboard">
|
||||
<Button fx:id="dashboardButton" layoutY="88.0" mnemonicParsing="false" onAction="#displayDashboard" prefHeight="45.0" prefWidth="216.0" text="dashboard">
|
||||
<font>
|
||||
<Font size="21.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Button fx:id="activitiesButton" layoutY="133.0" mnemonicParsing="false" onAction="#displayActivities" prefHeight="45.0" prefWidth="216.0" style="-fx-background-color: #5a635c;" text="activities">
|
||||
<Button fx:id="activitiesButton" layoutY="133.0" mnemonicParsing="false" onAction="#displayActivities" prefHeight="45.0" prefWidth="216.0" text="activities">
|
||||
<font>
|
||||
<Font size="21.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Button fx:id="userButton" layoutY="178.0" mnemonicParsing="false" onAction="#displayUser" prefHeight="45.0" prefWidth="216.0" style="-fx-background-color: #5a635c;" text="you">
|
||||
<Button fx:id="userButton" layoutY="178.0" mnemonicParsing="false" onAction="#displayUser" prefHeight="45.0" prefWidth="216.0" text="you">
|
||||
<font>
|
||||
<Font size="21.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Line endX="104.0" layoutX="102.0" layoutY="133.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
|
||||
<Line endX="104.0" layoutX="105.0" layoutY="178.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="603.0" prefWidth="711.0" visible="false">
|
||||
<children>
|
||||
@@ -41,7 +45,7 @@
|
||||
<Font size="30.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Button layoutX="60.0" layoutY="173.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 50%;" text="Add a vegetarian meal!" textFill="#cce4ca">
|
||||
<Button layoutX="60.0" layoutY="116.0" mnemonicParsing="false" style="-fx-background-color: #009623; -fx-border-radius: 25px;" text="Add a vegetarian meal" textFill="#e0ffe1">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
@@ -54,6 +58,20 @@
|
||||
<Font size="30.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<VBox layoutX="517.0" layoutY="28.0" prefHeight="53.0" prefWidth="100.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
|
||||
<children>
|
||||
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="Score" textAlignment="CENTER" wrappingWidth="100.79296875">
|
||||
<font>
|
||||
<Font size="24.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Label fx:id="scoreField" alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="101.0" text="score" textAlignment="CENTER">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</VBox>
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="dashboardPane" layoutX="215.0" prefHeight="603.0" prefWidth="711.0">
|
||||
<children>
|
||||
@@ -63,11 +81,19 @@
|
||||
<Font size="30.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Button layoutX="583.0" layoutY="41.0" mnemonicParsing="false" onAction="#displayActivities" style="-fx-background-color: #167526;" text="+" textFill="#e0fcdb">
|
||||
<Button layoutX="567.0" layoutY="26.0" mnemonicParsing="false" onAction="#displayActivities" prefHeight="74.0" prefWidth="62.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" textFill="#e0fcdb">
|
||||
<font>
|
||||
<Font name="Eras Bold ITC" size="28.0" />
|
||||
</font>
|
||||
<graphic>
|
||||
<ImageView fitHeight="81.0" fitWidth="74.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
<Image url="@../addActivity1.png" />
|
||||
</image>
|
||||
</ImageView>
|
||||
</graphic>
|
||||
</Button>
|
||||
|
||||
<!--<ComboBox fx:id="addActivity" layoutX="532.0" layoutY="28.0" prefWidth="150.0" promptText="Add an Activity" style="-fx-background-color: #1f951f;">-->
|
||||
<!--<items>-->
|
||||
<!--<FXCollections fx:factory="observableArrayList">-->
|
||||
|
||||
BIN
src/Client/src/main/resources/stylesheets/Big Designer.ttf
Normal file
BIN
src/Client/src/main/resources/stylesheets/Big Designer.ttf
Normal file
Binary file not shown.
BIN
src/Client/src/main/resources/stylesheets/DesignioRegular.otf
Normal file
BIN
src/Client/src/main/resources/stylesheets/DesignioRegular.otf
Normal file
Binary file not shown.
@@ -2,4 +2,53 @@
|
||||
/*-fx-border-width: 0px 0px 1px 0px;*/
|
||||
/*-fx-border-color: #f9f9f9;*/
|
||||
/*-fx-border-radius: 0%;*/
|
||||
/*}*/
|
||||
/*}*/
|
||||
|
||||
/*@font-face {*/
|
||||
/*font-family: 'Nunito Sans';*/
|
||||
/*src: url('https://fonts.googleapis.com/css?family=Nunito+Sans:200');*/
|
||||
/*}*/
|
||||
|
||||
@font-face {
|
||||
font-family: 'Designio Regular ';
|
||||
src: url('stylesheets/DesignioRegular.otf');
|
||||
}
|
||||
|
||||
/*@font-face {*/
|
||||
/*font-family: 'Big Designer';*/
|
||||
/*src: url('Big Designer.ttf');*/
|
||||
/*}*/
|
||||
/*test if fonts work*/
|
||||
/*@font-face {*/
|
||||
/*font-family: 'ConcertOne';*/
|
||||
/*src: url('https://fonts.googleapis.com/css?family=Concert+One');*/
|
||||
/*}*/
|
||||
.root {
|
||||
-fx-background-color: #f9fffb;
|
||||
-fx-font-family: "Big Designer";
|
||||
/*-fx-font-family: Designio;*/
|
||||
/*-fx-font-family: "Nunito Sans";*/
|
||||
/*-fx-font-family: "Concert One";*/
|
||||
}
|
||||
|
||||
#dashboardButton {
|
||||
-fx-background-color: #5a635c;
|
||||
|
||||
}
|
||||
#dashboardButton:pressed {
|
||||
-fx-background-color: #b7e2c2;
|
||||
}
|
||||
|
||||
#userButton {
|
||||
-fx-background-color: #5a635c;
|
||||
}
|
||||
#userButton:pressed {
|
||||
-fx-background-color: #b7e2c2;
|
||||
}
|
||||
|
||||
#activitiesButton {
|
||||
-fx-background-color: #5a635c;
|
||||
}
|
||||
#activitiesButton:pressed {
|
||||
-fx-background-color: #b7e2c2;
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import greenify.client.Application;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
public class ApplicationTest {
|
||||
@Test
|
||||
public void applicationContextLoaded() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationContextTest() {
|
||||
Application.main(new String[] {});
|
||||
}
|
||||
}
|
||||
@@ -42,4 +42,4 @@ jacocoTestReport {
|
||||
csv.enabled false
|
||||
html.destination file("${buildDir}/jacocoHtml")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ public class ErrorResponse {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public ErrorResponse() { }
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
@@ -14,4 +16,4 @@ public class ErrorResponse {
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ package greenify.common;
|
||||
// The motivation for its use is that communication between processes is usually done
|
||||
// resorting to remote interfaces (e.g., web services), where each call is an expensive operation.
|
||||
public class UserDTO {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
@@ -20,7 +21,15 @@ public class UserDTO {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
23
src/Common/src/test/java/ErrorResponseTest.java
Normal file
23
src/Common/src/test/java/ErrorResponseTest.java
Normal file
@@ -0,0 +1,23 @@
|
||||
import greenify.common.ErrorResponse;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ErrorResponseTest {
|
||||
@Test
|
||||
public void setAndGetTest() {
|
||||
ErrorResponse response = new ErrorResponse("New error");
|
||||
ErrorResponse testResponse = new ErrorResponse();
|
||||
testResponse.setMessage("New error");
|
||||
assertTrue(response.getMessage().equals("New error"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsTest() {
|
||||
ErrorResponse first = new ErrorResponse("New error");
|
||||
ErrorResponse second = new ErrorResponse("New error");
|
||||
assertEquals(first.getMessage(), second.getMessage());
|
||||
assertTrue(first.getMessage().equals(second.getMessage()));
|
||||
}
|
||||
}
|
||||
25
src/Common/src/test/java/UserDTOTest.java
Normal file
25
src/Common/src/test/java/UserDTOTest.java
Normal file
@@ -0,0 +1,25 @@
|
||||
import greenify.common.UserDTO;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class UserDTOTest {
|
||||
@Test
|
||||
public void setAndGetTest() {
|
||||
UserDTO user = new UserDTO(1L, "greenify");
|
||||
UserDTO testUser = new UserDTO();
|
||||
testUser.setId(1L);
|
||||
testUser.setName("greenify");
|
||||
assertTrue(user.getId() == 1L);
|
||||
assertEquals(user.getName(), "greenify");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsTest() {
|
||||
UserDTO first = new UserDTO(1L, "greenify");
|
||||
UserDTO second = new UserDTO(1L, "greenify");
|
||||
assertEquals(first.getId(), second.getId());
|
||||
assertEquals(first.getName(), second.getName());
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,6 @@ apply plugin: 'idea'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'checkstyle'
|
||||
|
||||
|
||||
tasks.withType(Checkstyle) {
|
||||
reports {
|
||||
html.destination rootProject.file("build/reports/checkstyle.html")
|
||||
}
|
||||
}
|
||||
|
||||
bootJar {
|
||||
baseName = 'gs-rest-service'
|
||||
@@ -47,6 +39,7 @@ dependencies {
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.6'
|
||||
compile("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||
compile("com.h2database:h2")
|
||||
compile("org.springframework.boot:spring-boot-starter-actuator")
|
||||
testCompile(
|
||||
'junit:junit:4.12',
|
||||
'org.junit.jupiter:junit-jupiter-api:5.4.0'
|
||||
@@ -55,6 +48,7 @@ dependencies {
|
||||
'org.junit.jupiter:junit-jupiter-engine:5.4.0',
|
||||
'org.junit.vintage:junit-vintage-engine:5.4.0'
|
||||
)
|
||||
compile 'javax.xml.bind:jaxb-api:2.3.0'
|
||||
}
|
||||
|
||||
jacoco {
|
||||
@@ -70,8 +64,3 @@ jacocoTestReport {
|
||||
}
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
toolVersion = "7.6.1"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,35 +1,43 @@
|
||||
package greenify.server.data.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
//@AllArgsConstructor
|
||||
@EnableAutoConfiguration
|
||||
@Entity
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Table(name = "users")
|
||||
public class User {
|
||||
|
||||
private @Id
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
Long id;
|
||||
private Long id;
|
||||
|
||||
@NotNull
|
||||
private String name;
|
||||
|
||||
@NotNull
|
||||
private String password;
|
||||
|
||||
private int veganMeal;
|
||||
|
||||
public User() {}
|
||||
|
||||
/**
|
||||
* makes a user object.
|
||||
* @param id the id of the user.
|
||||
* @param name the supplied username
|
||||
* @param password the supplied password
|
||||
* @param veganMeal the supplied number of vegan meal
|
||||
*/
|
||||
public User(Long id, String name, String password) {
|
||||
public User(Long id, String name, String password, int veganMeal) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.password = password;
|
||||
this.veganMeal = veganMeal;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,6 +48,8 @@ public class User {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) { this.id = id; }
|
||||
|
||||
/**
|
||||
* gets the name.
|
||||
* @return the name
|
||||
@@ -48,6 +58,8 @@ public class User {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
/**
|
||||
* gets the password.
|
||||
* @return the password
|
||||
@@ -56,21 +68,15 @@ public class User {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
public void setPassword(String password) { this.password = password; }
|
||||
|
||||
/**
|
||||
* gets the number of vegan meal.
|
||||
* @return the veganMeal
|
||||
*/
|
||||
public int getVeganMeal() {
|
||||
return veganMeal;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
return "User(id=" + this.id + ", name=" + this.name + ", password=" + this.password + ")";
|
||||
}
|
||||
}
|
||||
public void setVeganMeal(int veganMeal) { this.veganMeal = veganMeal; }
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package greenify.server.data.repository;
|
||||
|
||||
import greenify.server.data.model.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface UserJpaRepository extends UserRepository, JpaRepository<User,Long> {
|
||||
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package greenify.server.data.repository;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import greenify.server.data.model.User;
|
||||
|
||||
public interface UserRepository {
|
||||
public interface UserRepository extends CrudRepository<User, Integer> {
|
||||
User findByName(String name);
|
||||
<T extends User> T save(T user);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package greenify.server.rest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import greenify.server.data.model.User;
|
||||
import greenify.server.data.repository.UserRepository;
|
||||
|
||||
@Controller // This means that this class is a Controller
|
||||
@RequestMapping(path="/demo") // This means URL's start with /demo (after Application path)
|
||||
public class MainController {
|
||||
@Autowired // This means to get the bean called userRepository
|
||||
// Which is auto-generated by Spring, we will use it to handle the data
|
||||
private UserRepository userRepository;
|
||||
|
||||
@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
|
||||
// @RequestParam means it is a parameter from the GET or POST request
|
||||
|
||||
User n = new User();
|
||||
n.setName(name);
|
||||
n.setPassword(password);
|
||||
userRepository.save(n);
|
||||
return "Saved";
|
||||
}
|
||||
|
||||
@GetMapping(path="/all")
|
||||
public @ResponseBody Iterable<User> getAllUsers() {
|
||||
// This returns a JSON or XML with the users
|
||||
return userRepository.findAll();
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,4 @@ public class UserController {
|
||||
@RequestParam(value = "password") String password) {
|
||||
return userService.registerUser(name, password);
|
||||
}
|
||||
|
||||
@RequestMapping("/login")
|
||||
public UserDTO login(@RequestParam(value = "name") String name,
|
||||
@RequestParam(value = "password") String password) {
|
||||
return userService.login(name, password);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class UserService {
|
||||
if (user != null) {
|
||||
throw new ApplicationException("User already exists");
|
||||
} else {
|
||||
user = userRepository.save(new User(null, name, password));
|
||||
user = userRepository.save(new User(null, name, password, 0));
|
||||
}
|
||||
logger.info("Created user id=" + user.getId() + ", name=" + user.getName());
|
||||
return new UserDTO(user.getId(), user.getName());
|
||||
@@ -38,15 +38,16 @@ public class UserService {
|
||||
* @param password the password of the user
|
||||
* @return a userDTO of the logged in user
|
||||
*/
|
||||
public UserDTO login(String name, String password) {
|
||||
User user = userRepository.findByName(name);
|
||||
if (user == null) {
|
||||
throw new ApplicationException("User does not exist");
|
||||
} else {
|
||||
if (!user.getPassword().equals(password)) {
|
||||
throw new ApplicationException("Wrong password");
|
||||
}
|
||||
}
|
||||
return new UserDTO(user.getId(), user.getName());
|
||||
}
|
||||
// public UserDTO login(String name, String password) {
|
||||
// User user = userRepository.findByName(name);
|
||||
// if (user == null) {
|
||||
// throw new ApplicationException("User does not exist");
|
||||
// } else {
|
||||
// if (!user.getPassword().equals(password)) {
|
||||
// throw new ApplicationException("Wrong password");
|
||||
// }
|
||||
// }
|
||||
// return new UserDTO(user.getId(), user.getName());
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
6
src/Server/src/main/resources/application.properties
Normal file
6
src/Server/src/main/resources/application.properties
Normal file
@@ -0,0 +1,6 @@
|
||||
spring.datasource.url=jdbc:h2:file:~/spring-boot-h2.db;DB_CLOSE_ON_EXIT=FALSE
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=
|
||||
spring.datasource.driver-class-name=org.h2.Driver
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.h2.console.enabled=true
|
||||
@@ -1,16 +1,16 @@
|
||||
import greenify.server.Application;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
public class ApplicationTest {
|
||||
@Test
|
||||
public void applicationContextLoaded() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applicationContextTest() {
|
||||
Application.main(new String[] {});
|
||||
}
|
||||
}
|
||||
//import greenify.server.Application;
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.springframework.test.context.junit4.SpringRunner;
|
||||
//
|
||||
//@RunWith(SpringRunner.class)
|
||||
//public class ApplicationTest {
|
||||
// @Test
|
||||
// public void applicationContextLoaded() {
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void applicationContextTest() {
|
||||
// Application.main(new String[] {});
|
||||
// }
|
||||
//}
|
||||
@@ -1,46 +1,46 @@
|
||||
import greenify.common.UserDTO;
|
||||
import greenify.server.Application;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.client.HttpStatusCodeException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
public class UserControllerTest {
|
||||
private static Logger logger = LoggerFactory.getLogger(UserControllerTest.class);
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
private RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
@Test
|
||||
public void registerUserTest() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + "/registerUser")
|
||||
.queryParam("name", "ceren")
|
||||
.queryParam("password", "password");
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
UserDTO user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
Assert.assertNotNull(user);
|
||||
Assert.assertEquals(user.getId().longValue(), 1L);
|
||||
try {
|
||||
user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
Assert.fail("Error should be reported");
|
||||
} catch (HttpStatusCodeException exception) {
|
||||
int statusCode = exception.getStatusCode().value();
|
||||
Assert.assertEquals(statusCode, 400);
|
||||
Assert.assertTrue(exception.getResponseBodyAsString().contains("User already exists"));
|
||||
}
|
||||
}
|
||||
}
|
||||
//import greenify.common.UserDTO;
|
||||
//import greenify.server.Application;
|
||||
//import org.junit.Assert;
|
||||
//import org.junit.Test;
|
||||
//import org.junit.runner.RunWith;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.boot.web.server.LocalServerPort;
|
||||
//import org.springframework.boot.test.context.SpringBootTest;
|
||||
//import org.springframework.http.*;
|
||||
//import org.springframework.test.context.junit4.SpringRunner;
|
||||
//import org.springframework.web.client.HttpStatusCodeException;
|
||||
//import org.springframework.web.client.RestTemplate;
|
||||
//import org.springframework.web.util.UriComponentsBuilder;
|
||||
//
|
||||
//@RunWith(SpringRunner.class)
|
||||
//@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
//public class UserControllerTest {
|
||||
// private static Logger logger = LoggerFactory.getLogger(UserControllerTest.class);
|
||||
//
|
||||
// @LocalServerPort
|
||||
// private int port;
|
||||
//
|
||||
// private RestTemplate restTemplate = new RestTemplate();
|
||||
//
|
||||
// @Test
|
||||
// public void registerUserTest() {
|
||||
// HttpHeaders headers = new HttpHeaders();
|
||||
// headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
// UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + "/registerUser")
|
||||
// .queryParam("name", "ceren")
|
||||
// .queryParam("password", "password");
|
||||
// HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
// UserDTO user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
// Assert.assertNotNull(user);
|
||||
// Assert.assertEquals(user.getId().longValue(), 1L);
|
||||
// try {
|
||||
// user = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
// Assert.fail("Error should be reported");
|
||||
// } catch (HttpStatusCodeException exception) {
|
||||
// int statusCode = exception.getStatusCode().value();
|
||||
// Assert.assertEquals(statusCode, 400);
|
||||
// Assert.assertTrue(exception.getResponseBodyAsString().contains("User already exists"));
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -6,37 +6,41 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
public class UserTest {
|
||||
@Test
|
||||
public void setAndGetTest() {
|
||||
User user = new User(1L, "greenify", "password");
|
||||
User testUser = new User(null, null, null);
|
||||
User user = new User(1L, "greenify", "password", 3);
|
||||
User testUser = new User();
|
||||
testUser.setId(1L);
|
||||
testUser.setName("greenify");
|
||||
testUser.setPassword("password");
|
||||
testUser.setVeganMeal(3);
|
||||
assertTrue(user.getId().equals(1L));
|
||||
assertEquals(user.getName(), "greenify");
|
||||
assertEquals(user.getPassword(), "password");
|
||||
assertEquals(user.getVeganMeal(), 3);
|
||||
assertEquals(user, testUser);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringTest() {
|
||||
User user = new User(1L, "greenify", "password");
|
||||
assertEquals("User(id=1, name=greenify, password=password)", user.toString());
|
||||
User user = new User(1L, "greenify", "password", 3);
|
||||
assertEquals("User(id=1, name=greenify, password=password, veganMeal=3)", user.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsTest() {
|
||||
User first = new User(1L, "greenify", "password");
|
||||
User second = new User(1L, "greenify", "password");
|
||||
User first = new User(1L, "greenify", "password", 3);
|
||||
User second = new User(1L, "greenify", "password", 3);
|
||||
assertEquals(first.getId(), second.getId());
|
||||
assertEquals(first.getName(), second.getName());
|
||||
assertEquals(first.getPassword(), second.getPassword());
|
||||
assertEquals(first.getVeganMeal(), second.getVeganMeal());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeTest() {
|
||||
User first = new User(1L, "greenify", "password");
|
||||
User second = new User(1L, "greenify", "password");
|
||||
User first = new User(1L, "greenify", "password", 3);
|
||||
User second = new User(1L, "greenify", "password", 3);
|
||||
assertTrue(first.equals(second) && second.equals(first));
|
||||
assertTrue(first.hashCode() == second.hashCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user