-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dispara pedido via kafka no topico pedido
- Loading branch information
Showing
8 changed files
with
128 additions
and
22 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
7 changes: 3 additions & 4 deletions
7
src/main/java/com/fiap/mspedidoapi/domain/gateway/pedido/PreparaPedidoInterface.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,12 +1,11 @@ | ||
package com.fiap.mspedidoapi.domain.gateway.pedido; | ||
|
||
import com.fiap.mspedidoapi.domain.entity.entrega.Entrega; | ||
import com.fiap.mspedidoapi.domain.entity.pedido.PedidoEntity; | ||
import com.fiap.mspedidoapi.domain.exception.pedido.PedidoNaoEncontradoException; | ||
import com.fiap.mspedidoapi.infra.collection.pedido.Pedido; | ||
|
||
import java.util.UUID; | ||
|
||
public interface PreparaPedidoInterface { | ||
Pedido encontraPedidoPorUuid(UUID pedidoUuid) throws PedidoNaoEncontradoException; | ||
Entrega movePedidoParaEmPreparacao(UUID pedidoUuid, Integer tempoDePreparoEmMinutos) throws PedidoNaoEncontradoException; | ||
PedidoEntity encontraPedidoPorUuid(UUID pedidoUuid) throws PedidoNaoEncontradoException; | ||
PedidoEntity movePedidoParaEmPreparacao(UUID pedidoUuid, Integer tempoDePreparoEmMinutos) throws PedidoNaoEncontradoException; | ||
} |
7 changes: 7 additions & 0 deletions
7
...in/java/com/fiap/mspedidoapi/domain/gateway/producers/PreparaPedidoProducerInterface.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,7 @@ | ||
package com.fiap.mspedidoapi.domain.gateway.producers; | ||
|
||
import com.fiap.mspedidoapi.domain.output.pedido.PedidoEmPreparacaoOutput; | ||
|
||
public interface PreparaPedidoProducerInterface { | ||
void send(PedidoEmPreparacaoOutput pedidoEmPreparacaoOutput); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/fiap/mspedidoapi/domain/output/pedido/PedidoEmPreparacaoOutput.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,34 @@ | ||
package com.fiap.mspedidoapi.domain.output.pedido; | ||
|
||
import com.fiap.mspedidoapi.domain.entity.pedido.PedidoEntity; | ||
import com.fiap.mspedidoapi.domain.generic.output.OutputInterface; | ||
import com.fiap.mspedidoapi.domain.generic.output.OutputStatus; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Data | ||
@RequiredArgsConstructor | ||
@Getter | ||
@Setter | ||
public class PedidoEmPreparacaoOutput implements OutputInterface { | ||
private PedidoEntity pedido; | ||
private OutputStatus outputStatus; | ||
|
||
public PedidoEmPreparacaoOutput(PedidoEntity pedido, OutputStatus outputStatus) { | ||
this.pedido = pedido; | ||
this.outputStatus = outputStatus; | ||
} | ||
|
||
@Override | ||
public Object getBody() { | ||
return this.pedido; | ||
} | ||
|
||
@Override | ||
public OutputStatus getOutputStatus() { | ||
return this.outputStatus; | ||
} | ||
|
||
} |
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/fiap/mspedidoapi/infra/kafka/producers/PreparaPedidoProducer.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,34 @@ | ||
package com.fiap.mspedidoapi.infra.kafka.producers; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.fiap.mspedidoapi.domain.gateway.producers.PreparaPedidoProducerInterface; | ||
import com.fiap.mspedidoapi.domain.output.pedido.PedidoEmPreparacaoOutput; | ||
import com.fiap.mspedidoapi.infra.dependecy.kafka.resolvers.producers.KafkaProducerResolver; | ||
import com.fiap.mspedidoapi.infra.dependecy.kafka.resolvers.producers.KafkaSenderConfig; | ||
|
||
import java.util.UUID; | ||
|
||
public class PreparaPedidoProducer extends KafkaSenderConfig implements PreparaPedidoProducerInterface { | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public PreparaPedidoProducer(String servers) { | ||
super(servers, new KafkaProducerResolver().getPedidoProducer()); | ||
} | ||
|
||
@Override | ||
public void send(PedidoEmPreparacaoOutput pedidoEmPreparacaoOutput) { | ||
try { | ||
ObjectNode jsonNode = objectMapper.createObjectNode(); | ||
jsonNode.put("uuid_pedido", pedidoEmPreparacaoOutput.getPedido().getPedidoId().toString()); | ||
jsonNode.put("status_pedido", pedidoEmPreparacaoOutput.getPedido().getStatusPedido().toString()); | ||
jsonNode.put("numero_pedido", pedidoEmPreparacaoOutput.getPedido().getNumeroPedido()); | ||
jsonNode.put("tempo_preparo", pedidoEmPreparacaoOutput.getPedido().getTempoDePreparoEmMinutos()); | ||
String json = jsonNode.toString(); | ||
send(UUID.randomUUID().toString(), json); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |