mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-14 08:18:23 +00:00
1 parent
aa2b190a8c
commit
a27e0923b0
4 files changed
+22
-18
No files matched your search
@@ -32,6 +32,10 @@ import java.util.List;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import service.CakeBakingService;
|
import service.CakeBakingService;
|
||||||
import view.CakeViewImpl;
|
import view.CakeViewImpl;
|
||||||
@@ -44,6 +48,8 @@ import view.CakeViewImpl;
|
|||||||
* It uses the CakeBakingService to save new layers and toppings and to bake new cakes.
|
* It uses the CakeBakingService to save new layers and toppings and to bake new cakes.
|
||||||
* It also handles exceptions that might occur during the cake baking process.</p>
|
* It also handles exceptions that might occur during the cake baking process.</p>
|
||||||
*/
|
*/
|
||||||
|
@EntityScan(basePackages = "entity")
|
||||||
|
@ComponentScan(basePackages = {"com.iluwatar.layers", "service", "dto", "exception", "view", "dao"})
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class Runner implements CommandLineRunner {
|
public class Runner implements CommandLineRunner {
|
||||||
@@ -64,6 +70,10 @@ public class Runner implements CommandLineRunner {
|
|||||||
cakeView.render();
|
cakeView.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Runner.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the example data.
|
* Initializes the example data.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -26,14 +26,13 @@
|
|||||||
package dto;
|
package dto;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DTO for cakes.
|
* DTO for cakes.
|
||||||
*/
|
*/
|
||||||
public class CakeInfo {
|
public class CakeInfo {
|
||||||
|
|
||||||
public final Optional<Long> id;
|
public final Long id;
|
||||||
public final CakeToppingInfo cakeToppingInfo;
|
public final CakeToppingInfo cakeToppingInfo;
|
||||||
public final List<CakeLayerInfo> cakeLayerInfos;
|
public final List<CakeLayerInfo> cakeLayerInfos;
|
||||||
|
|
||||||
@@ -41,7 +40,7 @@ public class CakeInfo {
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public CakeInfo(Long id, CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerInfos) {
|
public CakeInfo(Long id, CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerInfos) {
|
||||||
this.id = Optional.of(id);
|
this.id = id;
|
||||||
this.cakeToppingInfo = cakeToppingInfo;
|
this.cakeToppingInfo = cakeToppingInfo;
|
||||||
this.cakeLayerInfos = cakeLayerInfos;
|
this.cakeLayerInfos = cakeLayerInfos;
|
||||||
}
|
}
|
||||||
@@ -50,7 +49,7 @@ public class CakeInfo {
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public CakeInfo(CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerInfos) {
|
public CakeInfo(CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerInfos) {
|
||||||
this.id = Optional.empty();
|
this.id = null;
|
||||||
this.cakeToppingInfo = cakeToppingInfo;
|
this.cakeToppingInfo = cakeToppingInfo;
|
||||||
this.cakeLayerInfos = cakeLayerInfos;
|
this.cakeLayerInfos = cakeLayerInfos;
|
||||||
}
|
}
|
||||||
@@ -66,7 +65,7 @@ public class CakeInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("CakeInfo id=%d topping=%s layers=%s totalCalories=%d", id.orElse(-1L),
|
return String.format("CakeInfo id=%d topping=%s layers=%s totalCalories=%d", id,
|
||||||
cakeToppingInfo, cakeLayerInfos, calculateTotalCalories());
|
cakeToppingInfo, cakeLayerInfos, calculateTotalCalories());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,14 +25,12 @@
|
|||||||
|
|
||||||
package dto;
|
package dto;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DTO for cake layers.
|
* DTO for cake layers.
|
||||||
*/
|
*/
|
||||||
public class CakeLayerInfo {
|
public class CakeLayerInfo {
|
||||||
|
|
||||||
public final Optional<Long> id;
|
public final Long id;
|
||||||
public final String name;
|
public final String name;
|
||||||
public final int calories;
|
public final int calories;
|
||||||
|
|
||||||
@@ -40,7 +38,7 @@ public class CakeLayerInfo {
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public CakeLayerInfo(Long id, String name, int calories) {
|
public CakeLayerInfo(Long id, String name, int calories) {
|
||||||
this.id = Optional.of(id);
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.calories = calories;
|
this.calories = calories;
|
||||||
}
|
}
|
||||||
@@ -49,13 +47,13 @@ public class CakeLayerInfo {
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public CakeLayerInfo(String name, int calories) {
|
public CakeLayerInfo(String name, int calories) {
|
||||||
this.id = Optional.empty();
|
this.id = null;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.calories = calories;
|
this.calories = calories;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("CakeLayerInfo id=%d name=%s calories=%d", id.orElse(-1L), name, calories);
|
return String.format("CakeLayerInfo id=%d name=%s calories=%d", id, name, calories);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,15 +25,12 @@
|
|||||||
|
|
||||||
package dto;
|
package dto;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DTO for cake toppings.
|
* DTO for cake toppings.
|
||||||
*/
|
*/
|
||||||
public class CakeToppingInfo {
|
public class CakeToppingInfo {
|
||||||
|
|
||||||
public final Optional<Long> id;
|
public final Long id;
|
||||||
public final String name;
|
public final String name;
|
||||||
public final int calories;
|
public final int calories;
|
||||||
|
|
||||||
@@ -41,7 +38,7 @@ public class CakeToppingInfo {
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public CakeToppingInfo(Long id, String name, int calories) {
|
public CakeToppingInfo(Long id, String name, int calories) {
|
||||||
this.id = Optional.of(id);
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.calories = calories;
|
this.calories = calories;
|
||||||
}
|
}
|
||||||
@@ -50,14 +47,14 @@ public class CakeToppingInfo {
|
|||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public CakeToppingInfo(String name, int calories) {
|
public CakeToppingInfo(String name, int calories) {
|
||||||
this.id = Optional.empty();
|
this.id = null;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.calories = calories;
|
this.calories = calories;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("CakeToppingInfo id=%d name=%s calories=%d", id.orElse(-1L), name,
|
return String.format("CakeToppingInfo id=%d name=%s calories=%d", id, name,
|
||||||
calories);
|
calories);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user