This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: switch the product classes to clean architecture
- Loading branch information
1 parent
d83e9ee
commit 0ba9dd0
Showing
11 changed files
with
156 additions
and
117 deletions.
There are no files selected for viewing
10 changes: 5 additions & 5 deletions
10
src/main/java/br/com/fiap/grupo30/fastfood/domain/repositories/ProductRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
package br.com.fiap.grupo30.fastfood.domain.repositories; | ||
|
||
import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.ProductDTO; | ||
import br.com.fiap.grupo30.fastfood.domain.entities.Product; | ||
import java.util.List; | ||
|
||
public interface ProductRepository { | ||
|
||
List<ProductDTO> findProductsByCategoryId(Long categoryId); | ||
List<Product> findProductsByCategoryId(Long categoryId); | ||
|
||
ProductDTO findById(Long id); | ||
Product findById(Long id); | ||
|
||
ProductDTO insert(ProductDTO dto); | ||
Product insert(Product product); | ||
|
||
ProductDTO update(Long id, ProductDTO dto); | ||
Product update(Long id, Product product); | ||
|
||
void delete(Long id); | ||
} |
16 changes: 7 additions & 9 deletions
16
src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/CreateProductUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
package br.com.fiap.grupo30.fastfood.domain.usecases.product; | ||
|
||
import br.com.fiap.grupo30.fastfood.domain.repositories.ProductRepository; | ||
import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.ProductDTO; | ||
import org.springframework.stereotype.Component; | ||
import br.com.fiap.grupo30.fastfood.domain.entities.Product; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.gateways.ProductGateway; | ||
|
||
@Component | ||
public class CreateProductUseCase { | ||
|
||
private final ProductRepository productRepository; | ||
private final ProductGateway productGateway; | ||
|
||
public CreateProductUseCase(ProductRepository productRepository) { | ||
this.productRepository = productRepository; | ||
public CreateProductUseCase(ProductGateway productGateway) { | ||
this.productGateway = productGateway; | ||
} | ||
|
||
public ProductDTO execute(ProductDTO product) { | ||
return productRepository.insert(product); | ||
public Product execute(Product product) { | ||
return productGateway.insert(product); | ||
} | ||
} |
12 changes: 5 additions & 7 deletions
12
src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/DeleteProductUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
package br.com.fiap.grupo30.fastfood.domain.usecases.product; | ||
|
||
import br.com.fiap.grupo30.fastfood.domain.repositories.ProductRepository; | ||
import org.springframework.stereotype.Component; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.gateways.ProductGateway; | ||
|
||
@Component | ||
public class DeleteProductUseCase { | ||
|
||
private final ProductRepository productRepository; | ||
private final ProductGateway productGateway; | ||
|
||
public DeleteProductUseCase(ProductRepository productRepository) { | ||
this.productRepository = productRepository; | ||
public DeleteProductUseCase(ProductGateway productGateway) { | ||
this.productGateway = productGateway; | ||
} | ||
|
||
public void execute(Long id) { | ||
productRepository.delete(id); | ||
productGateway.delete(id); | ||
} | ||
} |
16 changes: 7 additions & 9 deletions
16
src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/GetProductUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
package br.com.fiap.grupo30.fastfood.domain.usecases.product; | ||
|
||
import br.com.fiap.grupo30.fastfood.domain.repositories.ProductRepository; | ||
import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.ProductDTO; | ||
import org.springframework.stereotype.Component; | ||
import br.com.fiap.grupo30.fastfood.domain.entities.Product; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.gateways.ProductGateway; | ||
|
||
@Component | ||
public class GetProductUseCase { | ||
|
||
private final ProductRepository productRepository; | ||
private final ProductGateway productGateway; | ||
|
||
public GetProductUseCase(ProductRepository productRepository) { | ||
this.productRepository = productRepository; | ||
public GetProductUseCase(ProductGateway productGateway) { | ||
this.productGateway = productGateway; | ||
} | ||
|
||
public ProductDTO execute(Long id) { | ||
return productRepository.findById(id); | ||
public Product execute(Long id) { | ||
return productGateway.findById(id); | ||
} | ||
} |
16 changes: 7 additions & 9 deletions
16
...a/br/com/fiap/grupo30/fastfood/domain/usecases/product/ListProductsByCategoryUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
package br.com.fiap.grupo30.fastfood.domain.usecases.product; | ||
|
||
import br.com.fiap.grupo30.fastfood.domain.repositories.ProductRepository; | ||
import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.ProductDTO; | ||
import br.com.fiap.grupo30.fastfood.domain.entities.Product; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.gateways.ProductGateway; | ||
import java.util.List; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ListProductsByCategoryUseCase { | ||
|
||
private final ProductRepository productRepository; | ||
private final ProductGateway productGateway; | ||
|
||
public ListProductsByCategoryUseCase(ProductRepository productRepository) { | ||
this.productRepository = productRepository; | ||
public ListProductsByCategoryUseCase(ProductGateway productGateway) { | ||
this.productGateway = productGateway; | ||
} | ||
|
||
public List<ProductDTO> execute(Long categoryId) { | ||
return productRepository.findProductsByCategoryId(categoryId); | ||
public List<Product> execute(Long categoryId) { | ||
return productGateway.findProductsByCategoryId(categoryId); | ||
} | ||
} |
16 changes: 7 additions & 9 deletions
16
src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/UpdateProductUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
package br.com.fiap.grupo30.fastfood.domain.usecases.product; | ||
|
||
import br.com.fiap.grupo30.fastfood.domain.repositories.ProductRepository; | ||
import br.com.fiap.grupo30.fastfood.presentation.presenters.dto.ProductDTO; | ||
import org.springframework.stereotype.Component; | ||
import br.com.fiap.grupo30.fastfood.domain.entities.Product; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.gateways.ProductGateway; | ||
|
||
@Component | ||
public class UpdateProductUseCase { | ||
|
||
private final ProductRepository productRepository; | ||
private final ProductGateway productGateway; | ||
|
||
public UpdateProductUseCase(ProductRepository productRepository) { | ||
this.productRepository = productRepository; | ||
public UpdateProductUseCase(ProductGateway productGateway) { | ||
this.productGateway = productGateway; | ||
} | ||
|
||
public ProductDTO execute(Long id, ProductDTO product) { | ||
return productRepository.update(id, product); | ||
public Product execute(Long id, Product product) { | ||
return productGateway.update(id, product); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
.../java/br/com/fiap/grupo30/fastfood/infrastructure/configuration/ProductConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package br.com.fiap.grupo30.fastfood.infrastructure.configuration; | ||
|
||
import br.com.fiap.grupo30.fastfood.domain.repositories.ProductRepository; | ||
import br.com.fiap.grupo30.fastfood.domain.usecases.product.*; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.gateways.ProductGateway; | ||
import br.com.fiap.grupo30.fastfood.infrastructure.persistence.repositories.JpaProductRepository; | ||
import br.com.fiap.grupo30.fastfood.presentation.presenters.mapper.impl.ProductEntityMapper; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class ProductConfiguration { | ||
|
||
@Bean | ||
public ProductRepository productRepository( | ||
JpaProductRepository jpaProductRepository, ProductEntityMapper productEntityMapper) { | ||
return new ProductGateway(jpaProductRepository, productEntityMapper); | ||
} | ||
|
||
@Bean | ||
public ListProductsByCategoryUseCase listProductsByCategoryUseCase( | ||
ProductGateway productGateway) { | ||
return new ListProductsByCategoryUseCase(productGateway); | ||
} | ||
|
||
@Bean | ||
public GetProductUseCase getProductUseCase(ProductGateway productGateway) { | ||
return new GetProductUseCase(productGateway); | ||
} | ||
|
||
@Bean | ||
public CreateProductUseCase createProductUseCase(ProductGateway productGateway) { | ||
return new CreateProductUseCase(productGateway); | ||
} | ||
|
||
@Bean | ||
public UpdateProductUseCase updateProductUseCase(ProductGateway productGateway) { | ||
return new UpdateProductUseCase(productGateway); | ||
} | ||
|
||
@Bean | ||
public DeleteProductUseCase deleteProductUseCase(ProductGateway productGateway) { | ||
return new DeleteProductUseCase(productGateway); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.