Skip to content

Commit

Permalink
Reapply "fix: Refactor Layered Architecture pattern iluwatar#2936"
Browse files Browse the repository at this point in the history
This reverts commit 54aee49.
  • Loading branch information
romannimets committed May 5, 2024
1 parent 54aee49 commit 0d19c7a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
10 changes: 10 additions & 0 deletions layers/src/main/java/com/iluwatar/layers/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
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;
Expand All @@ -44,6 +48,8 @@
* 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 {
Expand All @@ -64,6 +70,10 @@ public void run(String... args) {
cakeView.render();
}

public static void main(String[] args) {
SpringApplication.run(Runner.class, args);
}

/**
* Initializes the example data.
*/
Expand Down
9 changes: 4 additions & 5 deletions layers/src/main/java/dto/CakeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,21 @@
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;

/**
* Constructor.
*/
public CakeInfo(Long id, CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerInfos) {
this.id = Optional.of(id);
this.id = id;
this.cakeToppingInfo = cakeToppingInfo;
this.cakeLayerInfos = cakeLayerInfos;
}
Expand All @@ -50,7 +49,7 @@ public CakeInfo(Long id, CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> ca
* Constructor.
*/
public CakeInfo(CakeToppingInfo cakeToppingInfo, List<CakeLayerInfo> cakeLayerInfos) {
this.id = Optional.empty();
this.id = null;
this.cakeToppingInfo = cakeToppingInfo;
this.cakeLayerInfos = cakeLayerInfos;
}
Expand All @@ -66,7 +65,7 @@ public int calculateTotalCalories() {

@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());
}
}
10 changes: 4 additions & 6 deletions layers/src/main/java/dto/CakeLayerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@

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;

/**
* Constructor.
*/
public CakeLayerInfo(Long id, String name, int calories) {
this.id = Optional.of(id);
this.id = id;
this.name = name;
this.calories = calories;
}
Expand All @@ -49,13 +47,13 @@ public CakeLayerInfo(Long id, String name, int calories) {
* 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);
}
}
11 changes: 4 additions & 7 deletions layers/src/main/java/dto/CakeToppingInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,20 @@

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;

/**
* Constructor.
*/
public CakeToppingInfo(Long id, String name, int calories) {
this.id = Optional.of(id);
this.id = id;
this.name = name;
this.calories = calories;
}
Expand All @@ -50,14 +47,14 @@ public CakeToppingInfo(Long id, String name, int calories) {
* 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);
}
}

0 comments on commit 0d19c7a

Please sign in to comment.