Skip to content

Commit

Permalink
"Acertando Transactions"
Browse files Browse the repository at this point in the history
  • Loading branch information
wolwerr committed Sep 20, 2024
1 parent 3cd26e9 commit b7ce107
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -31,7 +30,6 @@ public class PedidoProntoController {

@PostMapping("/{pedidoUuid}")
@Operation(summary = "Atualizar pedidos", tags = {"cozinha"})
@Transactional
public ResponseEntity<Object> atualizaPedido(@PathVariable UUID pedidoUuid) {
PedidoProntoUseCase useCase = new PedidoProntoUseCase(
new PedidoProntoRepository(pedidosMongoRepository),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class ListPedidosController {
@GetMapping("/lista-pedido/")
@Operation(summary = "Listar todos pedidos", tags = {"cozinha"})
public ResponseEntity<Object> getAllListaPedidos() {
//injetar repository do que consulta o MONGODB
BuscaListaPedidosUseCase useCase = new BuscaListaPedidosUseCase(new BuscarListaPedidoRepository(pedidosMongoRepository));
useCase.execute();
OutputInterface outputInterface = useCase.getBuscaProdutoOutput();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -30,7 +29,6 @@ public class IniciaPreparoPedidoController {

@PostMapping("/inicia-preparo")
@Operation(summary = "Iniciar preparo de pedido", tags = {"cozinha"})
@Transactional
public ResponseEntity<Object> iniciaPreparoPedido(@RequestBody StoreIniciaPreparoProdutoRequest iniciaPreparoProdutoRequest) {
IniciaPreparoPedidoUseCase useCase = new IniciaPreparoPedidoUseCase(
new PreparaPedidoRepository(pedidosMongoRepository),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import com.fiap.mspedidoapi.domain.output.pedido.PedidoEmPreparacaoOutput;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

Expand All @@ -21,7 +24,9 @@ public class IniciaPreparoPedidoUseCase {
private final PreparaPedidoInterface preparaPedidoInterface;
private final PreparaPedidoProducerInterface preparaPedidoProducerInterface;
private OutputInterface outputInterface;
private final Logger logger = LoggerFactory.getLogger(IniciaPreparoPedidoUseCase.class);

@Transactional
public void execute(UUID pedidoUUID, Integer tempoDePreparoEmMinutos) {
try {

Expand Down Expand Up @@ -50,7 +55,7 @@ public void execute(UUID pedidoUUID, Integer tempoDePreparoEmMinutos) {
);

}catch (PedidoNaoEncontradoException e) {
System.out.println("Pedido nao enconstrado");
logger.error("Pedido nao enconstrado");
this.outputInterface = new OutputError(
e.getMessage(),
new OutputStatus(404, "Not found", "Pedido não encontrado")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fiap.mspedidoapi.domain.generic.output.OutputStatus;
import com.fiap.mspedidoapi.domain.output.pedido.PedidoProntoOutput;
import lombok.Getter;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

Expand All @@ -23,6 +24,7 @@ public PedidoProntoUseCase(PedidoProntoInterface entregaInterface, PedidoProntoP
this.pedidoProntoProducerInterface = pedidoProntoProducerInterface;
}

@Transactional
public void execute(UUID uuidPedido) {
try {
Entrega entrega = entregaInterface.atualizaStatusPedido(uuidPedido);
Expand Down

0 comments on commit b7ce107

Please sign in to comment.