Skip to content

Commit

Permalink
Build tool maven, spring boot framework in combination with a databas…
Browse files Browse the repository at this point in the history
…e mysql added
  • Loading branch information
Dougnkong committed Dec 26, 2020
1 parent d12de99 commit 34d694c
Show file tree
Hide file tree
Showing 29 changed files with 462 additions and 119 deletions.
84 changes: 74 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,83 @@
<artifactId>drinkAutomat</artifactId>
<version>1.0-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
</parent>

<description>Demo project for Spring Drink machine</description>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.2</version>
</dependency>

<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.3.1.RELEASE</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.3.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.3.5.RELEASE</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<properties>
Expand All @@ -26,20 +97,13 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- Build an executable JAR -->
<configuration>
<archive>
<manifest>
<mainClass>start_the_machine.StartDrinkMachine</mainClass>
</manifest>
</archive>
<mainClass>com.ApplicationStartDrinkMachine</mainClass>
</configuration>
</plugin>
</plugins>

</build>

</project>
12 changes: 12 additions & 0 deletions src/main/java/com/ApplicationStartDrinkMachine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ApplicationStartDrinkMachine {
public static void main(String[] args) {
SpringApplication.run(ApplicationStartDrinkMachine.class, args);
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/controller/ViewsController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.controller;

import com.service.IDrinkService;
import com.model.Drink;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class ViewsController {

@Autowired
private IDrinkService drinkService;

@GetMapping("/drinks")
public String findDrinks(Model model) {

List<Drink> drinks = (List<Drink>) drinkService.findAll();

model.addAttribute("drinks", drinks);

return "showDrinks";
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/exceptions/InputContainsException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.exceptions;

public class InputContainsException extends Exception {

public InputContainsException() {
}

public InputContainsException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package common;
package com.interfaces_and_enum;

import model.Coin;
import model.CoinAndQuantity;
import com.model.Coin;
import com.model.CoinAndQuantity;

import java.util.List;

public abstract class Automat {
public abstract class AbstractAutomat {

protected abstract void fillInWithCoin(List<Coin> coins);

Expand All @@ -16,4 +16,4 @@ public abstract class Automat {
protected abstract void fillOut(List<CoinAndQuantity> restCoinToGiveBack);

protected abstract List<CoinAndQuantity> changeCoin(int sum);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
package common;
package com.interfaces_and_enum;

public abstract class ProductType {
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Objects;

import static javax.persistence.GenerationType.*;

public abstract class AbstractProductType {
protected String name;
protected double price;

/**
* @param name general name for drink product.
* @param price general price of drink.
*/
public ProductType(String name, double price) {
public AbstractProductType(String name, double price) {
this.name = name;
this.price = price;
}

public AbstractProductType() {
}

public double getPrice() {
return price;
}
Expand All @@ -28,4 +38,4 @@ public String getName() {
public void setName(String name) {
this.name = name;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package common;
package com.interfaces_and_enum;

/**
* The coin is initialised in cents.
*/
public enum CoinValue {
public enum EnumCoinValue {
ONE_EURO(100),
TWO_EURO(200),
FIFTY_CENT(50),
Expand All @@ -16,7 +16,7 @@ public int getValue() {
return this.coinValue;
}

CoinValue(int value) {
EnumCoinValue(int value) {
this.coinValue = value;
}
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/model/Coin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.model;

import com.interfaces_and_enum.EnumCoinValue;

public class Coin {

EnumCoinValue coinValue;

/**
* @param coinValue represents the real coin value.
*/
public Coin(EnumCoinValue coinValue) {
this.coinValue = coinValue;
}

public EnumCoinValue getCoinValue() {
return coinValue;
}

public void setCoinValue(EnumCoinValue coinValue) {
this.coinValue = coinValue;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package model;
package com.model;

import common.CoinValue;
import com.interfaces_and_enum.EnumCoinValue;

/**
* This class is used to store change coins.
*/
public class CoinAndQuantity implements Comparable<CoinAndQuantity> {

protected CoinValue type;
protected EnumCoinValue type;
protected int quantity;

/**
* @param coin
* @param quantity gives the number of coins for type coin
*/
public CoinAndQuantity(CoinValue coin, int quantity) {
public CoinAndQuantity(EnumCoinValue coin, int quantity) {

this.type = coin;
this.quantity = quantity;
Expand All @@ -32,7 +32,7 @@ public void reduceCoinNumber(int quantity) {
this.quantity -= quantity;
}

public CoinValue getType() {
public EnumCoinValue getType() {
return type;
}

Expand All @@ -43,4 +43,4 @@ public int compareTo(CoinAndQuantity o) {

return this.type.getValue() - f.type.getValue();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package model;
package com.model;

import common.ProductType;
import com.interfaces_and_enum.AbstractProductType;

/**
* Generic class for compartment in the drink machine.
* Each compartment will take the name of specific drink.
*
* @param <T>
*/
public class Compartment<T extends ProductType> {
public class Compartment<T extends AbstractProductType> {

private T common;
int quantity;
Expand All @@ -33,4 +33,4 @@ public int getQuantity() {
public void setQuantity(int quantity) {
this.quantity = quantity;
}
}
}
53 changes: 53 additions & 0 deletions src/main/java/com/model/Drink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.model;

import com.interfaces_and_enum.AbstractProductType;

import javax.persistence.*;

import java.util.Objects;

import static javax.persistence.GenerationType.AUTO;

@Entity
@Table(name = "drinks")
public class Drink extends AbstractProductType {
@Id
@GeneratedValue(strategy = AUTO)
protected long id;

public Drink(long id, String name, double price) {
super(name, price);
this.id = id;
}

public Drink() {
super();
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

@Override
public int hashCode() {
int hash = 7;
hash = 79 * hash + Objects.hashCode(this.id);
hash = 79 * hash + Objects.hashCode(this.name);
hash = (int) ((79 * hash) + this.price);
return hash;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("drink{");
sb.append("id=").append(id);
sb.append(", name='").append(name).append('\'');
sb.append(", price=").append(price);
sb.append('}');
return sb.toString();
}
}
Loading

0 comments on commit 34d694c

Please sign in to comment.