ADD::added buttons and counters for the various activities
they don't have functionality yet, but they are already placed ADD::added methods to get the name of the user
This commit is contained in:
@@ -22,19 +22,41 @@ public class DashBoardController {
|
||||
public Button dashboardButton;
|
||||
public Button activitiesButton;
|
||||
public Button userButton;
|
||||
public Button veganMealButton;
|
||||
public Label counter;
|
||||
public Label scoreField;
|
||||
|
||||
//activities buttons
|
||||
@FXML
|
||||
public Button veganMealButton;
|
||||
public Button localProduceButton;
|
||||
public Button bikeButton;
|
||||
public Button publicTransportButton;
|
||||
public Button temperatureButton;
|
||||
public Button solarPanelButton;
|
||||
|
||||
//activities counters
|
||||
public Label veganMealCounter;
|
||||
public Label localProduceCounter;
|
||||
public Label bikeCounter;
|
||||
public Label publicTransportCounter;
|
||||
public Label temperatureCounter;
|
||||
public Label solarPanelCounter;
|
||||
|
||||
/**
|
||||
* displays the dashboard pane.
|
||||
* @param event the event (clicking the button)
|
||||
*/
|
||||
public void displayDashboard(ActionEvent event) {
|
||||
System.out.println("display dashboard");
|
||||
|
||||
// UserService service = new UserService();
|
||||
// UserDTO user = service.getName(null);
|
||||
// String name = user.getName();
|
||||
// welcomebacktext.setText("Welcome back, " + name);
|
||||
|
||||
dashboardPane.setVisible(true);
|
||||
userPane.setVisible(false);
|
||||
activitiesPane.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +87,7 @@ public class DashBoardController {
|
||||
*/
|
||||
public void addVeganMeal(ActionEvent event) {
|
||||
count++;
|
||||
counter.setText("Count: " + count);
|
||||
veganMealCounter.setText("Count: " + count);
|
||||
UserService service = new UserService();
|
||||
service.addVeganMeal(null, null);
|
||||
System.out.println("Vegetarian meal is added");
|
||||
|
||||
@@ -4,8 +4,9 @@ import greenify.common.UserDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
@@ -25,8 +26,9 @@ public class UserService {
|
||||
* registers the user.
|
||||
* @param name the username of the user
|
||||
* @param password the password of the user
|
||||
* @return a userDTO
|
||||
* @return a built userDTO with the required information
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public UserDTO registerUser(String name, String password) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
@@ -38,6 +40,13 @@ public class UserService {
|
||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* logd the user in.
|
||||
* @param name the username of the user
|
||||
* @param password the password of the user
|
||||
* @return a built userDTO with the required information
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public UserDTO loginUser(String name, String password) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
@@ -49,6 +58,13 @@ public class UserService {
|
||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* adds a vegetarian meal to the user.
|
||||
* @param id the id of the user
|
||||
* @param name the username of the user
|
||||
* @return a built userDTO with the required information
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public UserDTO addVeganMeal(Long id, String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
@@ -59,4 +75,20 @@ public class UserService {
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the username from the user.
|
||||
* @param id the id of the user
|
||||
* @return a UserDTO with the required information
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public UserDTO getName(Long id) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getUsername")
|
||||
.queryParam("id", id);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
<?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.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.shape.Line?>
|
||||
<?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">
|
||||
<children>
|
||||
<AnchorPane fx:id="menuBar" prefHeight="603.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||
@@ -35,21 +39,84 @@
|
||||
</children></AnchorPane>
|
||||
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="603.0" prefWidth="711.0" visible="false">
|
||||
<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 size="30.0" />
|
||||
</font>
|
||||
</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">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Label fx:id="counter" layoutX="288.0" layoutY="110.0" prefHeight="44.0" prefWidth="115.0" text="Count: ">
|
||||
<font>
|
||||
<Font size="25.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Pane layoutX="60.0" layoutY="93.0" prefHeight="471.0" prefWidth="291.0" style="-fx-background-color: #f4fff4;">
|
||||
<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">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<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 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>
|
||||
<AnchorPane fx:id="userPane" layoutX="215.0" layoutY="-1.0" prefHeight="603.0" prefWidth="711.0" visible="false">
|
||||
<children>
|
||||
|
||||
@@ -2,11 +2,11 @@ package greenify.server.data.repository;
|
||||
|
||||
import greenify.server.data.model.User;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
public interface UserRepository extends CrudRepository<User, Integer> {
|
||||
User findByName(@Param("name") String name);
|
||||
// User findByName(String name);
|
||||
// User findByName(@Param("name") String name);
|
||||
User findByName(String name);
|
||||
User findById(Long id);
|
||||
<T extends User> T save(T user);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package greenify.server.rest;
|
||||
import greenify.common.UserDTO;
|
||||
import greenify.server.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -29,4 +30,9 @@ public class UserController {
|
||||
@RequestParam(value = "name") String name) {
|
||||
userService.addVeganMeal(id, name);
|
||||
}
|
||||
|
||||
@GetMapping("/getUsername")
|
||||
public void getUsername(@RequestParam(value = "id") Long id) {
|
||||
userService.getUsername(id);
|
||||
}
|
||||
}
|
||||
@@ -64,5 +64,12 @@ public class UserService {
|
||||
user.setVeganMeal(count);
|
||||
logger.info("Added vegan meal to user(id=" + user.getId() + ", name=" + user.getName() + ")");
|
||||
}
|
||||
|
||||
public String getUsername(Long id) {
|
||||
User user = userRepository.findById(id);
|
||||
String name = user.getName();
|
||||
logger.info("retrieved username from user with username=" + name + ", id=" + id);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user