Skip to content

Commit

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

import java.util.List;
import java.util.Optional;

/**
* DTO for cakes.
*/
public class CakeInfo {

public final Long id;
public final Optional<Long> id;
public final CakeToppingInfo cakeToppingInfo;
public final List<CakeLayerInfo> cakeLayerInfos;

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

@Override
public String toString() {
return String.format("CakeInfo id=%d topping=%s layers=%s totalCalories=%d", id,
return String.format("CakeInfo id=%d topping=%s layers=%s totalCalories=%d", id.orElse(-1L),
cakeToppingInfo, cakeLayerInfos, calculateTotalCalories());
}
}
10 changes: 6 additions & 4 deletions layers/src/main/java/dto/CakeLayerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@

package dto;

import java.util.Optional;

/**
* DTO for cake layers.
*/
public class CakeLayerInfo {

public final Long id;
public final Optional<Long> id;
public final String name;
public final int calories;

/**
* Constructor.
*/
public CakeLayerInfo(Long id, String name, int calories) {
this.id = id;
this.id = Optional.of(id);
this.name = name;
this.calories = calories;
}
Expand All @@ -47,13 +49,13 @@ public CakeLayerInfo(Long id, String name, int calories) {
* Constructor.
*/
public CakeLayerInfo(String name, int calories) {
this.id = null;
this.id = Optional.empty();
this.name = name;
this.calories = calories;
}

@Override
public String toString() {
return String.format("CakeLayerInfo id=%d name=%s calories=%d", id, name, calories);
return String.format("CakeLayerInfo id=%d name=%s calories=%d", id.orElse(-1L), name, calories);
}
}
11 changes: 7 additions & 4 deletions layers/src/main/java/dto/CakeToppingInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,23 @@

package dto;


import java.util.Optional;

/**
* DTO for cake toppings.
*/
public class CakeToppingInfo {

public final Long id;
public final Optional<Long> id;
public final String name;
public final int calories;

/**
* Constructor.
*/
public CakeToppingInfo(Long id, String name, int calories) {
this.id = id;
this.id = Optional.of(id);
this.name = name;
this.calories = calories;
}
Expand All @@ -47,14 +50,14 @@ public CakeToppingInfo(Long id, String name, int calories) {
* Constructor.
*/
public CakeToppingInfo(String name, int calories) {
this.id = null;
this.id = Optional.empty();
this.name = name;
this.calories = calories;
}

@Override
public String toString() {
return String.format("CakeToppingInfo id=%d name=%s calories=%d", id, name,
return String.format("CakeToppingInfo id=%d name=%s calories=%d", id.orElse(-1L), name,
calories);
}
}

0 comments on commit 54aee49

Please sign in to comment.