mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-14 10:58:42 +00:00
@@ -32,6 +32,10 @@ import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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 service.CakeBakingService;
|
||||
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 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
|
||||
@Slf4j
|
||||
public class Runner implements CommandLineRunner {
|
||||
@@ -64,6 +70,10 @@ public class Runner implements CommandLineRunner {
|
||||
cakeView.render();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Runner.class, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the example data.
|
||||
*/
|
||||
|
||||
@@ -26,14 +26,13 @@
|
||||
package dto;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* DTO for cakes.
|
||||
*/
|
||||
public class CakeInfo {
|
||||
|
||||
public final Optional<Long> id;
|
||||
public final Long id;
|
||||
public final CakeToppingInfo cakeToppingInfo;
|
||||
public final List<CakeLayerInfo> cakeLayerInfos;
|
||||
|
||||
@@ -41,7 +40,7 @@ public class CakeInfo {
|
||||
* Constructor.
|
||||
*/
|
||||
public CakeInfo(Long id, CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerInfos) {
|
||||
this.id = Optional.of(id);
|
||||
this.id = id;
|
||||
this.cakeToppingInfo = cakeToppingInfo;
|
||||
this.cakeLayerInfos = cakeLayerInfos;
|
||||
}
|
||||
@@ -50,7 +49,7 @@ public class CakeInfo {
|
||||
* Constructor.
|
||||
*/
|
||||
public CakeInfo(CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerInfos) {
|
||||
this.id = Optional.empty();
|
||||
this.id = null;
|
||||
this.cakeToppingInfo = cakeToppingInfo;
|
||||
this.cakeLayerInfos = cakeLayerInfos;
|
||||
}
|
||||
@@ -66,7 +65,7 @@ public class CakeInfo {
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,14 +25,12 @@
|
||||
|
||||
package dto;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* DTO for cake layers.
|
||||
*/
|
||||
public class CakeLayerInfo {
|
||||
|
||||
public final Optional<Long> id;
|
||||
public final Long id;
|
||||
public final String name;
|
||||
public final int calories;
|
||||
|
||||
@@ -40,7 +38,7 @@ public class CakeLayerInfo {
|
||||
* Constructor.
|
||||
*/
|
||||
public CakeLayerInfo(Long id, String name, int calories) {
|
||||
this.id = Optional.of(id);
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.calories = calories;
|
||||
}
|
||||
@@ -49,13 +47,13 @@ public class CakeLayerInfo {
|
||||
* Constructor.
|
||||
*/
|
||||
public CakeLayerInfo(String name, int calories) {
|
||||
this.id = Optional.empty();
|
||||
this.id = null;
|
||||
this.name = name;
|
||||
this.calories = calories;
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* DTO for cake toppings.
|
||||
*/
|
||||
public class CakeToppingInfo {
|
||||
|
||||
public final Optional<Long> id;
|
||||
public final Long id;
|
||||
public final String name;
|
||||
public final int calories;
|
||||
|
||||
@@ -41,7 +38,7 @@ public class CakeToppingInfo {
|
||||
* Constructor.
|
||||
*/
|
||||
public CakeToppingInfo(Long id, String name, int calories) {
|
||||
this.id = Optional.of(id);
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.calories = calories;
|
||||
}
|
||||
@@ -50,14 +47,14 @@ public class CakeToppingInfo {
|
||||
* Constructor.
|
||||
*/
|
||||
public CakeToppingInfo(String name, int calories) {
|
||||
this.id = Optional.empty();
|
||||
this.id = null;
|
||||
this.name = name;
|
||||
this.calories = calories;
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user