diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/adapters/in/rest/CategoryResource.java b/src/main/java/br/com/fiap/grupo30/fastfood/adapters/in/rest/CategoryResource.java index 8c28e74..e7b5ecb 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/adapters/in/rest/CategoryResource.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/adapters/in/rest/CategoryResource.java @@ -1,7 +1,7 @@ package br.com.fiap.grupo30.fastfood.adapters.in.rest; import br.com.fiap.grupo30.fastfood.application.dto.CategoryDTO; -import br.com.fiap.grupo30.fastfood.application.useCases.CategoryUseCase; +import br.com.fiap.grupo30.fastfood.domain.usecases.product.ListAllCategoriesInMenuUseCase; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import java.util.List; @@ -16,11 +16,11 @@ @Tag(name = "Categories Resource", description = "RESTful API for managing categories.") public class CategoryResource { - private final CategoryUseCase categoryUseCase; + private final ListAllCategoriesInMenuUseCase listAllCategoriesInMenuUseCase; @Autowired - public CategoryResource(CategoryUseCase categoryUseCase) { - this.categoryUseCase = categoryUseCase; + public CategoryResource(ListAllCategoriesInMenuUseCase listAllCategoriesInMenuUseCase) { + this.listAllCategoriesInMenuUseCase = listAllCategoriesInMenuUseCase; } @GetMapping @@ -28,7 +28,7 @@ public CategoryResource(CategoryUseCase categoryUseCase) { summary = "Get all categories", description = "Retrieve a list of all registered categories") public ResponseEntity> findAll() { - List list = categoryUseCase.findProducts(); + List list = this.listAllCategoriesInMenuUseCase.execute(); return ResponseEntity.ok().body(list); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/adapters/in/rest/CustomerResource.java b/src/main/java/br/com/fiap/grupo30/fastfood/adapters/in/rest/CustomerResource.java index 2f0dbca..e312503 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/adapters/in/rest/CustomerResource.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/adapters/in/rest/CustomerResource.java @@ -1,7 +1,8 @@ package br.com.fiap.grupo30.fastfood.adapters.in.rest; import br.com.fiap.grupo30.fastfood.application.dto.CustomerDTO; -import br.com.fiap.grupo30.fastfood.application.useCases.CustomerUseCase; +import br.com.fiap.grupo30.fastfood.domain.usecases.customer.FindCustomerByCpfUseCase; +import br.com.fiap.grupo30.fastfood.domain.usecases.customer.RegisterNewCustomerUseCase; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -18,18 +19,22 @@ public class CustomerResource { private static final String PATH_VARIABLE_ID = "/{id}"; - private final CustomerUseCase customerUseCase; + private final FindCustomerByCpfUseCase findCustomerByCpfUseCase; + private final RegisterNewCustomerUseCase registerNewCustomerUseCase; @Autowired - public CustomerResource(CustomerUseCase customerUseCase) { - this.customerUseCase = customerUseCase; + public CustomerResource( + FindCustomerByCpfUseCase findCustomerByCpfUseCase, + RegisterNewCustomerUseCase registerNewCustomerUseCase) { + this.findCustomerByCpfUseCase = findCustomerByCpfUseCase; + this.registerNewCustomerUseCase = registerNewCustomerUseCase; } @GetMapping @Operation(summary = "Get a customer", description = "Retrieve a registered customer by cpf") public ResponseEntity findCustomerByCpf( @RequestParam(value = "cpf", defaultValue = "0") String cpf) { - CustomerDTO dto = customerUseCase.findCustomerByCpf(cpf); + CustomerDTO dto = this.findCustomerByCpfUseCase.execute(cpf); return ResponseEntity.ok().body(dto); } @@ -38,7 +43,7 @@ public ResponseEntity findCustomerByCpf( summary = "Create a new customer", description = "Create a new customer and return the created customer's data") public ResponseEntity createCustomer(@RequestBody @Valid CustomerDTO dto) { - CustomerDTO dtoCreated = customerUseCase.createCustomer(dto); + CustomerDTO dtoCreated = this.registerNewCustomerUseCase.execute(dto); URI uri = ServletUriComponentsBuilder.fromCurrentRequest() .path(PATH_VARIABLE_ID) diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/adapters/in/rest/ProductResource.java b/src/main/java/br/com/fiap/grupo30/fastfood/adapters/in/rest/ProductResource.java index b17dac8..031cd6d 100644 --- a/src/main/java/br/com/fiap/grupo30/fastfood/adapters/in/rest/ProductResource.java +++ b/src/main/java/br/com/fiap/grupo30/fastfood/adapters/in/rest/ProductResource.java @@ -1,7 +1,11 @@ package br.com.fiap.grupo30.fastfood.adapters.in.rest; import br.com.fiap.grupo30.fastfood.application.dto.ProductDTO; -import br.com.fiap.grupo30.fastfood.application.useCases.ProductUseCase; +import br.com.fiap.grupo30.fastfood.domain.usecases.product.CreateProductUseCase; +import br.com.fiap.grupo30.fastfood.domain.usecases.product.DeleteProductUseCase; +import br.com.fiap.grupo30.fastfood.domain.usecases.product.GetProductUseCase; +import br.com.fiap.grupo30.fastfood.domain.usecases.product.ListProductsByCategoryUseCase; +import br.com.fiap.grupo30.fastfood.domain.usecases.product.UpdateProductUseCase; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; @@ -19,11 +23,25 @@ public class ProductResource { private static final String PATH_VARIABLE_ID = "/{id}"; - private final ProductUseCase productUseCase; + private final ListProductsByCategoryUseCase listProductsByCategoryUseCase; + private final GetProductUseCase getProductUseCase; + private final CreateProductUseCase createProductUseCase; + private final UpdateProductUseCase updateProductUseCase; + private final DeleteProductUseCase deleteProductUseCase; @Autowired - public ProductResource(ProductUseCase productUseCase) { - this.productUseCase = productUseCase; + public ProductResource( + ListProductsByCategoryUseCase listProductsByCategoryUseCase, + GetProductUseCase getProductUseCase, + CreateProductUseCase createProductUseCase, + UpdateProductUseCase updateProductUseCase, + DeleteProductUseCase deleteProductUseCase) { + + this.listProductsByCategoryUseCase = listProductsByCategoryUseCase; + this.getProductUseCase = getProductUseCase; + this.createProductUseCase = createProductUseCase; + this.updateProductUseCase = updateProductUseCase; + this.deleteProductUseCase = deleteProductUseCase; } @GetMapping @@ -34,7 +52,7 @@ public ProductResource(ProductUseCase productUseCase) { + "via RequestParam. i.e., ?categoryId=1") public ResponseEntity> findProductsByCategoryId( @RequestParam(value = "categoryId", defaultValue = "0") Long categoryId) { - List list = productUseCase.findProductsByCategoryId(categoryId); + List list = this.listProductsByCategoryUseCase.execute(categoryId); return ResponseEntity.ok().body(list); } @@ -43,7 +61,7 @@ public ResponseEntity> findProductsByCategoryId( summary = "Get a product by ID", description = "Retrieve a specific product based on its ID") public ResponseEntity findProductById(@PathVariable Long id) { - ProductDTO dto = productUseCase.findProductById(id); + ProductDTO dto = this.getProductUseCase.execute(id); return ResponseEntity.ok().body(dto); } @@ -52,7 +70,7 @@ public ResponseEntity findProductById(@PathVariable Long id) { summary = "Create a new product", description = "Create a new product and return the created product's data") public ResponseEntity createProduct(@RequestBody @Valid ProductDTO dto) { - ProductDTO dtoCreated = productUseCase.createProduct(dto); + ProductDTO dtoCreated = this.createProductUseCase.execute(dto); URI uri = ServletUriComponentsBuilder.fromCurrentRequest() .path(PATH_VARIABLE_ID) @@ -67,7 +85,7 @@ public ResponseEntity createProduct(@RequestBody @Valid ProductDTO d description = "Update the data of an existing product based on its ID") public ResponseEntity updateProduct( @PathVariable Long id, @RequestBody @Valid ProductDTO dto) { - ProductDTO dtoUpdated = productUseCase.updateProduct(id, dto); + ProductDTO dtoUpdated = this.updateProductUseCase.execute(id, dto); return ResponseEntity.ok().body(dtoUpdated); } @@ -76,7 +94,7 @@ public ResponseEntity updateProduct( summary = "Delete a product", description = "Delete an existing product based on its ID") public ResponseEntity deleteProduct(@PathVariable Long id) { - productUseCase.deleteProduct(id); + this.deleteProductUseCase.execute(id); return ResponseEntity.noContent().build(); } } diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/CategoryUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/CategoryUseCase.java deleted file mode 100644 index 456cc7f..0000000 --- a/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/CategoryUseCase.java +++ /dev/null @@ -1,9 +0,0 @@ -package br.com.fiap.grupo30.fastfood.application.useCases; - -import br.com.fiap.grupo30.fastfood.application.dto.CategoryDTO; -import java.util.List; - -public interface CategoryUseCase { - - List findProducts(); -} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/CustomerUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/CustomerUseCase.java deleted file mode 100644 index 0d6d760..0000000 --- a/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/CustomerUseCase.java +++ /dev/null @@ -1,10 +0,0 @@ -package br.com.fiap.grupo30.fastfood.application.useCases; - -import br.com.fiap.grupo30.fastfood.application.dto.CustomerDTO; - -public interface CustomerUseCase { - - CustomerDTO findCustomerByCpf(String cpf); - - CustomerDTO createCustomer(CustomerDTO dto); -} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/ProductUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/ProductUseCase.java deleted file mode 100644 index d77a12b..0000000 --- a/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/ProductUseCase.java +++ /dev/null @@ -1,17 +0,0 @@ -package br.com.fiap.grupo30.fastfood.application.useCases; - -import br.com.fiap.grupo30.fastfood.application.dto.ProductDTO; -import java.util.List; - -public interface ProductUseCase { - - List findProductsByCategoryId(Long categoryId); - - ProductDTO findProductById(Long id); - - ProductDTO createProduct(ProductDTO productDTO); - - ProductDTO updateProduct(Long id, ProductDTO dto); - - void deleteProduct(Long id); -} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/impl/CategoryUseCaseImpl.java b/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/impl/CategoryUseCaseImpl.java deleted file mode 100644 index 47ef7c9..0000000 --- a/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/impl/CategoryUseCaseImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package br.com.fiap.grupo30.fastfood.application.useCases.impl; - -import br.com.fiap.grupo30.fastfood.application.dto.CategoryDTO; -import br.com.fiap.grupo30.fastfood.application.services.CategoryService; -import br.com.fiap.grupo30.fastfood.application.useCases.CategoryUseCase; -import java.util.List; -import org.springframework.stereotype.Service; - -@Service -public class CategoryUseCaseImpl implements CategoryUseCase { - - private final CategoryService categoryService; - - public CategoryUseCaseImpl(CategoryService categoryService) { - this.categoryService = categoryService; - } - - @Override - public List findProducts() { - return categoryService.findAll(); - } -} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/impl/CustomerUseCaseImpl.java b/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/impl/CustomerUseCaseImpl.java deleted file mode 100644 index 516cef9..0000000 --- a/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/impl/CustomerUseCaseImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package br.com.fiap.grupo30.fastfood.application.useCases.impl; - -import br.com.fiap.grupo30.fastfood.application.dto.CustomerDTO; -import br.com.fiap.grupo30.fastfood.application.services.CustomerService; -import br.com.fiap.grupo30.fastfood.application.useCases.CustomerUseCase; -import org.springframework.stereotype.Service; - -@Service -public class CustomerUseCaseImpl implements CustomerUseCase { - - private final CustomerService customerService; - - public CustomerUseCaseImpl(CustomerService customerService) { - this.customerService = customerService; - } - - @Override - public CustomerDTO findCustomerByCpf(String cpf) { - return customerService.findCustomerByCpf(cpf); - } - - @Override - public CustomerDTO createCustomer(CustomerDTO dto) { - return customerService.insert(dto); - } -} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/impl/ProductUseCaseImpl.java b/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/impl/ProductUseCaseImpl.java deleted file mode 100644 index 3d96bdb..0000000 --- a/src/main/java/br/com/fiap/grupo30/fastfood/application/useCases/impl/ProductUseCaseImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -package br.com.fiap.grupo30.fastfood.application.useCases.impl; - -import br.com.fiap.grupo30.fastfood.application.dto.ProductDTO; -import br.com.fiap.grupo30.fastfood.application.services.ProductService; -import br.com.fiap.grupo30.fastfood.application.useCases.ProductUseCase; -import java.util.List; -import org.springframework.stereotype.Service; - -@Service -public class ProductUseCaseImpl implements ProductUseCase { - - private final ProductService productService; - - public ProductUseCaseImpl(ProductService productService) { - this.productService = productService; - } - - @Override - public List findProductsByCategoryId(Long categoryId) { - return productService.findProductsByCategoryId(categoryId); - } - - @Override - public ProductDTO findProductById(Long id) { - return productService.findById(id); - } - - @Override - public ProductDTO createProduct(ProductDTO productDTO) { - return productService.insert(productDTO); - } - - @Override - public ProductDTO updateProduct(Long id, ProductDTO dto) { - return productService.update(id, dto); - } - - @Override - public void deleteProduct(Long id) { - productService.delete(id); - } -} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/FindCustomerByCpfUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/FindCustomerByCpfUseCase.java new file mode 100644 index 0000000..d499b63 --- /dev/null +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/FindCustomerByCpfUseCase.java @@ -0,0 +1,19 @@ +package br.com.fiap.grupo30.fastfood.domain.usecases.customer; + +import br.com.fiap.grupo30.fastfood.application.dto.CustomerDTO; +import br.com.fiap.grupo30.fastfood.application.services.CustomerService; +import org.springframework.stereotype.Component; + +@Component +public class FindCustomerByCpfUseCase { + + private final CustomerService customerService; + + public FindCustomerByCpfUseCase(CustomerService customerService) { + this.customerService = customerService; + } + + public CustomerDTO execute(String cpf) { + return customerService.findCustomerByCpf(cpf); + } +} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/RegisterNewCustomerUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/RegisterNewCustomerUseCase.java new file mode 100644 index 0000000..948e26f --- /dev/null +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/customer/RegisterNewCustomerUseCase.java @@ -0,0 +1,19 @@ +package br.com.fiap.grupo30.fastfood.domain.usecases.customer; + +import br.com.fiap.grupo30.fastfood.application.dto.CustomerDTO; +import br.com.fiap.grupo30.fastfood.application.services.CustomerService; +import org.springframework.stereotype.Component; + +@Component +public class RegisterNewCustomerUseCase { + + private final CustomerService customerService; + + public RegisterNewCustomerUseCase(CustomerService customerService) { + this.customerService = customerService; + } + + public CustomerDTO execute(CustomerDTO dto) { + return customerService.insert(dto); + } +} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/CreateProductUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/CreateProductUseCase.java new file mode 100644 index 0000000..641c304 --- /dev/null +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/CreateProductUseCase.java @@ -0,0 +1,19 @@ +package br.com.fiap.grupo30.fastfood.domain.usecases.product; + +import br.com.fiap.grupo30.fastfood.application.dto.ProductDTO; +import br.com.fiap.grupo30.fastfood.application.services.ProductService; +import org.springframework.stereotype.Component; + +@Component +public class CreateProductUseCase { + + private final ProductService productService; + + public CreateProductUseCase(ProductService productService) { + this.productService = productService; + } + + public ProductDTO execute(ProductDTO product) { + return productService.insert(product); + } +} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/DeleteProductUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/DeleteProductUseCase.java new file mode 100644 index 0000000..95bafdd --- /dev/null +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/DeleteProductUseCase.java @@ -0,0 +1,18 @@ +package br.com.fiap.grupo30.fastfood.domain.usecases.product; + +import br.com.fiap.grupo30.fastfood.application.services.ProductService; +import org.springframework.stereotype.Component; + +@Component +public class DeleteProductUseCase { + + private final ProductService productService; + + public DeleteProductUseCase(ProductService productService) { + this.productService = productService; + } + + public void execute(Long id) { + productService.delete(id); + } +} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/GetProductUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/GetProductUseCase.java new file mode 100644 index 0000000..4c62b7a --- /dev/null +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/GetProductUseCase.java @@ -0,0 +1,19 @@ +package br.com.fiap.grupo30.fastfood.domain.usecases.product; + +import br.com.fiap.grupo30.fastfood.application.dto.ProductDTO; +import br.com.fiap.grupo30.fastfood.application.services.ProductService; +import org.springframework.stereotype.Component; + +@Component +public class GetProductUseCase { + + private final ProductService productService; + + public GetProductUseCase(ProductService productService) { + this.productService = productService; + } + + public ProductDTO execute(Long id) { + return productService.findById(id); + } +} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/ListAllCategoriesInMenuUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/ListAllCategoriesInMenuUseCase.java new file mode 100644 index 0000000..0056968 --- /dev/null +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/ListAllCategoriesInMenuUseCase.java @@ -0,0 +1,20 @@ +package br.com.fiap.grupo30.fastfood.domain.usecases.product; + +import br.com.fiap.grupo30.fastfood.application.dto.CategoryDTO; +import br.com.fiap.grupo30.fastfood.application.services.CategoryService; +import java.util.List; +import org.springframework.stereotype.Component; + +@Component +public class ListAllCategoriesInMenuUseCase { + + private final CategoryService categoryService; + + public ListAllCategoriesInMenuUseCase(CategoryService categoryService) { + this.categoryService = categoryService; + } + + public List execute() { + return categoryService.findAll(); + } +} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/ListProductsByCategoryUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/ListProductsByCategoryUseCase.java new file mode 100644 index 0000000..e338f87 --- /dev/null +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/ListProductsByCategoryUseCase.java @@ -0,0 +1,20 @@ +package br.com.fiap.grupo30.fastfood.domain.usecases.product; + +import br.com.fiap.grupo30.fastfood.application.dto.ProductDTO; +import br.com.fiap.grupo30.fastfood.application.services.ProductService; +import java.util.List; +import org.springframework.stereotype.Component; + +@Component +public class ListProductsByCategoryUseCase { + + private final ProductService productService; + + public ListProductsByCategoryUseCase(ProductService productService) { + this.productService = productService; + } + + public List execute(Long categoryId) { + return productService.findProductsByCategoryId(categoryId); + } +} diff --git a/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/UpdateProductUseCase.java b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/UpdateProductUseCase.java new file mode 100644 index 0000000..4f592f1 --- /dev/null +++ b/src/main/java/br/com/fiap/grupo30/fastfood/domain/usecases/product/UpdateProductUseCase.java @@ -0,0 +1,19 @@ +package br.com.fiap.grupo30.fastfood.domain.usecases.product; + +import br.com.fiap.grupo30.fastfood.application.dto.ProductDTO; +import br.com.fiap.grupo30.fastfood.application.services.ProductService; +import org.springframework.stereotype.Component; + +@Component +public class UpdateProductUseCase { + + private final ProductService productService; + + public UpdateProductUseCase(ProductService productService) { + this.productService = productService; + } + + public ProductDTO execute(Long id, ProductDTO product) { + return productService.update(id, product); + } +}