This repository has been archived by the owner on Apr 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from g12-4soat/feature/refac-clean-arch
refatorando produtos usando abordagem clean arch
- Loading branch information
Showing
29 changed files
with
402 additions
and
187 deletions.
There are no files selected for viewing
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
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
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
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
14 changes: 14 additions & 0 deletions
14
src/TechLanches/Core/TechLanches.Application/Controllers/Interfaces/IProdutoController.cs
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,14 @@ | ||
using TechLanches.Application.DTOs; | ||
|
||
namespace TechLanches.Application.Controllers.Interfaces | ||
{ | ||
public interface IProdutoController | ||
{ | ||
Task<List<ProdutoResponseDTO>> BuscarTodos(); | ||
Task<ProdutoResponseDTO> BuscarPorId(int produtoId); | ||
Task<List<ProdutoResponseDTO>> BuscarPorCategoria(int categoriaId); | ||
Task<ProdutoResponseDTO> Cadastrar(string nome, string descricao, decimal preco, int categoriaId); | ||
Task Atualizar(int produtoId, string nome, string descricao, decimal preco, int categoriaId); | ||
Task Deletar(int produtoId); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
src/TechLanches/Core/TechLanches.Application/Controllers/ProdutoController.cs
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,81 @@ | ||
using TechLanches.Application.Controllers.Interfaces; | ||
using TechLanches.Application.DTOs; | ||
using TechLanches.Application.Gateways.Interfaces; | ||
using TechLanches.Application.Presenters; | ||
using TechLanches.Application.Presenters.Interfaces; | ||
using TechLanches.Application.UseCases.Produtos; | ||
using TechLanches.Domain.Aggregates; | ||
using TechLanches.Domain.ValueObjects; | ||
|
||
namespace TechLanches.Application.Controllers | ||
{ | ||
public class ProdutoController : IProdutoController | ||
{ | ||
private readonly IProdutoGateway _produtoGateway; | ||
private readonly IProdutoPresenter _produtoPresenter; | ||
|
||
public ProdutoController(IProdutoGateway produtoGateway, IProdutoPresenter produtoPresenter) | ||
{ | ||
_produtoGateway = produtoGateway; | ||
_produtoPresenter = produtoPresenter; | ||
} | ||
|
||
public async Task Atualizar( | ||
int produtoId, | ||
string nome, | ||
string descricao, | ||
decimal preco, | ||
int categoriaId) | ||
{ | ||
await ProdutoUseCases.Atualizar( | ||
produtoId, | ||
nome, | ||
descricao, | ||
preco, | ||
categoriaId, | ||
_produtoGateway); | ||
|
||
await _produtoGateway.CommitAsync(); | ||
} | ||
|
||
public async Task<List<ProdutoResponseDTO>> BuscarPorCategoria(int categoriaId) | ||
{ | ||
var categoriaProduto = CategoriaProduto.From(categoriaId); | ||
var produtos = await _produtoGateway.BuscarPorCategoria(categoriaProduto); | ||
|
||
return _produtoPresenter.ParaListaDto(produtos); | ||
} | ||
|
||
public async Task<ProdutoResponseDTO> BuscarPorId(int produtoId) | ||
{ | ||
var produto = await _produtoGateway.BuscarPorId(produtoId); | ||
|
||
return _produtoPresenter.ParaDto(produto); | ||
} | ||
|
||
public async Task<List<ProdutoResponseDTO>> BuscarTodos() | ||
{ | ||
var produtos = await _produtoGateway.BuscarTodos(); | ||
|
||
return _produtoPresenter.ParaListaDto(produtos); | ||
} | ||
|
||
public async Task<ProdutoResponseDTO> Cadastrar(string nome, string descricao, decimal preco, int categoriaId) | ||
{ | ||
var novoProduto = await ProdutoUseCases.Cadastrar(nome, descricao, preco, categoriaId, _produtoGateway); | ||
|
||
await _produtoGateway.CommitAsync(); | ||
|
||
return _produtoPresenter.ParaDto(novoProduto); | ||
} | ||
|
||
public async Task Deletar(int produtoId) | ||
{ | ||
var produto = await _produtoGateway.BuscarPorId(produtoId); | ||
|
||
produto.DeletarProduto(); | ||
|
||
await _produtoGateway.CommitAsync(); | ||
} | ||
} | ||
} |
Oops, something went wrong.