diff --git a/.gitignore b/.gitignore index 5eac309..11ddca2 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,5 @@ build/ !**/src/test/**/build/ ### VS Code ### -.vscode/ \ No newline at end of file +.vscode/ +/infrastructure/docker-compose/volumes/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml index eb44784..de3c783 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -33,6 +33,13 @@ + + + + + + + \ No newline at end of file diff --git a/common/common-domain/src/main/java/com/food/order/sysyem/DomainConstants.java b/common/common-domain/src/main/java/com/food/order/sysyem/DomainConstants.java new file mode 100644 index 0000000..8327e68 --- /dev/null +++ b/common/common-domain/src/main/java/com/food/order/sysyem/DomainConstants.java @@ -0,0 +1,10 @@ +package com.food.order.sysyem; + +public class DomainConstants { + + private DomainConstants() { + } + + public static final String UTC = "UTC"; + +} diff --git a/common/common-domain/src/main/java/com/food/order/sysyem/event/DomainEvent.java b/common/common-domain/src/main/java/com/food/order/sysyem/event/DomainEvent.java index ab1abd7..b05b464 100644 --- a/common/common-domain/src/main/java/com/food/order/sysyem/event/DomainEvent.java +++ b/common/common-domain/src/main/java/com/food/order/sysyem/event/DomainEvent.java @@ -4,5 +4,6 @@ package com.food.order.sysyem.event; // Base Domain Event Generic Class public interface DomainEvent { + void fire(); } diff --git a/common/common-domain/src/main/java/com/food/order/sysyem/valueobject/Money.java b/common/common-domain/src/main/java/com/food/order/sysyem/valueobject/Money.java index 3821131..6098945 100644 --- a/common/common-domain/src/main/java/com/food/order/sysyem/valueobject/Money.java +++ b/common/common-domain/src/main/java/com/food/order/sysyem/valueobject/Money.java @@ -28,7 +28,7 @@ public class Money { this.amount.compareTo(other.amount) > 0; } - public Money substract(Money other) { + public Money subtract(Money other) { return new Money(setScale(this.amount.subtract(other.getAmount()))); } diff --git a/common/common-domain/src/main/java/com/food/order/sysyem/valueobject/PaymentOrderStatus.java b/common/common-domain/src/main/java/com/food/order/sysyem/valueobject/PaymentOrderStatus.java new file mode 100644 index 0000000..b777250 --- /dev/null +++ b/common/common-domain/src/main/java/com/food/order/sysyem/valueobject/PaymentOrderStatus.java @@ -0,0 +1,6 @@ +package com.food.order.sysyem.valueobject; + +public enum PaymentOrderStatus { + PENDING, + CANCELLED +} diff --git a/infrastructure/docker-compose/.env b/infrastructure/docker-compose/.env index 4958bd5..d45e7d7 100644 --- a/infrastructure/docker-compose/.env +++ b/infrastructure/docker-compose/.env @@ -1,3 +1,3 @@ KAFKA_VERSION=7.0.1 GLOBAL_NETWORK=food-order-system -GROUP_ID=com.food-order-system +GROUP_ID=com.food.order diff --git a/infrastructure/docker-compose/init_kafka.yml b/infrastructure/docker-compose/init_kafka.yml index 4e91e52..db971ec 100644 --- a/infrastructure/docker-compose/init_kafka.yml +++ b/infrastructure/docker-compose/init_kafka.yml @@ -9,16 +9,16 @@ services: kafka-topics --bootstrap-server kafka-broker-1:9092 --list echo -e 'Deleting kafka topics' - kafka-topics --bootstrap-server kafka-broker-1:9092 --topic payment-request --delete --if-exists - kafka-topics --bootstrap-server kafka-broker-1:9092 --topic payment-response --delete --if-exists - kafka-topics --bootstrap-server kafka-broker-1:9092 --topic restaurant-approval-request --delete --if-exists - kafka-topics --bootstrap-server kafka-broker-1:9092 --topic restaurant-approval-response --delete --if-exists + kafka-topics --bootstrap-server kafka-broker-1:9092 --topic payment-request-value --delete --if-exists + kafka-topics --bootstrap-server kafka-broker-1:9092 --topic payment-response-value --delete --if-exists + kafka-topics --bootstrap-server kafka-broker-1:9092 --topic restaurant-approval-request-value --delete --if-exists + kafka-topics --bootstrap-server kafka-broker-1:9092 --topic restaurant-approval-response-value --delete --if-exists echo -e 'Creating kafka topics' - kafka-topics --bootstrap-server kafka-broker-1:9092 --create --if-not-exists --topic payment-request --replication-factor 3 --partitions 3 - kafka-topics --bootstrap-server kafka-broker-1:9092 --create --if-not-exists --topic payment-response --replication-factor 3 --partitions 3 - kafka-topics --bootstrap-server kafka-broker-1:9092 --create --if-not-exists --topic restaurant-approval-request --replication-factor 3 --partitions 3 - kafka-topics --bootstrap-server kafka-broker-1:9092 --create --if-not-exists --topic restaurant-approval-response --replication-factor 3 --partitions 3 + kafka-topics --bootstrap-server kafka-broker-1:9092 --create --if-not-exists --topic payment-request-value --replication-factor 3 --partitions 3 + kafka-topics --bootstrap-server kafka-broker-1:9092 --create --if-not-exists --topic payment-response-value --replication-factor 3 --partitions 3 + kafka-topics --bootstrap-server kafka-broker-1:9092 --create --if-not-exists --topic restaurant-approval-request-value --replication-factor 3 --partitions 3 + kafka-topics --bootstrap-server kafka-broker-1:9092 --create --if-not-exists --topic restaurant-approval-response-value --replication-factor 3 --partitions 3 echo -e 'Successfully created the following topics:' diff --git a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/OrderApprovalStatus.java b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/OrderApprovalStatus.java index 4fb217c..be2ebdf 100644 --- a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/OrderApprovalStatus.java +++ b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/OrderApprovalStatus.java @@ -7,7 +7,7 @@ package com.food.order.system.kafka.order.avro.model; @org.apache.avro.specific.AvroGenerated public enum OrderApprovalStatus implements org.apache.avro.generic.GenericEnumSymbol { APPROVED, REJECTED ; - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"OrderApprovalStatus\",\"namespace\":\"com.food.ordering.system.kafka.order.avro.model\",\"symbols\":[\"APPROVED\",\"REJECTED\"]}"); + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"OrderApprovalStatus\",\"namespace\":\"com.food.order.system.kafka.order.avro.model\",\"symbols\":[\"APPROVED\",\"REJECTED\"]}"); public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } public org.apache.avro.Schema getSchema() { return SCHEMA$; } } diff --git a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentOrderStatus.java b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentOrderStatus.java index 4b19bdc..fe0c28e 100644 --- a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentOrderStatus.java +++ b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentOrderStatus.java @@ -7,7 +7,7 @@ package com.food.order.system.kafka.order.avro.model; @org.apache.avro.specific.AvroGenerated public enum PaymentOrderStatus implements org.apache.avro.generic.GenericEnumSymbol { PENDING, CANCELLED ; - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"PaymentOrderStatus\",\"namespace\":\"com.food.ordering.system.kafka.order.avro.model\",\"symbols\":[\"PENDING\",\"CANCELLED\"]}"); + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"PaymentOrderStatus\",\"namespace\":\"com.food.order.system.kafka.order.avro.model\",\"symbols\":[\"PENDING\",\"CANCELLED\"]}"); public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } public org.apache.avro.Schema getSchema() { return SCHEMA$; } } diff --git a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentRequestAvroModel.java b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentRequestAvroModel.java index 2da9800..84920f8 100644 --- a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentRequestAvroModel.java +++ b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentRequestAvroModel.java @@ -12,10 +12,10 @@ import org.apache.avro.specific.SpecificData; @org.apache.avro.specific.AvroGenerated public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { - private static final long serialVersionUID = 1425163749928760031L; + private static final long serialVersionUID = 2928240305434837410L; - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"PaymentRequestAvroModel\",\"namespace\":\"com.food.ordering.system.kafka.order.avro.model\",\"fields\":[{\"name\":\"id\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"sagaId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"customerId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"orderId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"price\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":10,\"scale\":2}},{\"name\":\"createdAt\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}},{\"name\":\"paymentOrderStatus\",\"type\":{\"type\":\"enum\",\"name\":\"PaymentOrderStatus\",\"symbols\":[\"PENDING\",\"CANCELLED\"]}}]}"); + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"PaymentRequestAvroModel\",\"namespace\":\"com.food.order.system.kafka.order.avro.model\",\"fields\":[{\"name\":\"id\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"sagaId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"customerId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"orderId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"price\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":10,\"scale\":2}},{\"name\":\"createdAt\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}},{\"name\":\"paymentOrderStatus\",\"type\":{\"type\":\"enum\",\"name\":\"PaymentOrderStatus\",\"symbols\":[\"PENDING\",\"CANCELLED\"]}}]}"); public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } private static final SpecificData MODEL$ = new SpecificData(); @@ -75,13 +75,13 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe return DECODER.decode(b); } - private String id; - private String sagaId; - private String customerId; - private String orderId; + private java.lang.String id; + private java.lang.String sagaId; + private java.lang.String customerId; + private java.lang.String orderId; private java.math.BigDecimal price; private java.time.Instant createdAt; - private PaymentOrderStatus paymentOrderStatus; + private com.food.order.system.kafka.order.avro.model.PaymentOrderStatus paymentOrderStatus; /** * Default constructor. Note that this does not initialize fields @@ -100,7 +100,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * @param createdAt The new value for createdAt * @param paymentOrderStatus The new value for paymentOrderStatus */ - public PaymentRequestAvroModel(String id, String sagaId, String customerId, String orderId, java.math.BigDecimal price, java.time.Instant createdAt, PaymentOrderStatus paymentOrderStatus) { + public PaymentRequestAvroModel(java.lang.String id, java.lang.String sagaId, java.lang.String customerId, java.lang.String orderId, java.math.BigDecimal price, java.time.Instant createdAt, com.food.order.system.kafka.order.avro.model.PaymentOrderStatus paymentOrderStatus) { this.id = id; this.sagaId = sagaId; this.customerId = customerId; @@ -110,10 +110,10 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe this.paymentOrderStatus = paymentOrderStatus; } - public SpecificData getSpecificData() { return MODEL$; } + public org.apache.avro.specific.SpecificData getSpecificData() { return MODEL$; } public org.apache.avro.Schema getSchema() { return SCHEMA$; } // Used by DatumWriter. Applications should not call. - public Object get(int field$) { + public java.lang.Object get(int field$) { switch (field$) { case 0: return id; case 1: return sagaId; @@ -145,7 +145,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe // Used by DatumReader. Applications should not call. @SuppressWarnings(value="unchecked") - public void put(int field$, Object value$) { + public void put(int field$, java.lang.Object value$) { switch (field$) { case 0: id = value$ != null ? value$.toString() : null; break; case 1: sagaId = value$ != null ? value$.toString() : null; break; @@ -153,7 +153,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe case 3: orderId = value$ != null ? value$.toString() : null; break; case 4: price = (java.math.BigDecimal)value$; break; case 5: createdAt = (java.time.Instant)value$; break; - case 6: paymentOrderStatus = (PaymentOrderStatus)value$; break; + case 6: paymentOrderStatus = (com.food.order.system.kafka.order.avro.model.PaymentOrderStatus)value$; break; default: throw new IndexOutOfBoundsException("Invalid index: " + field$); } } @@ -162,7 +162,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Gets the value of the 'id' field. * @return The value of the 'id' field. */ - public String getId() { + public java.lang.String getId() { return id; } @@ -171,7 +171,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Sets the value of the 'id' field. * @param value the value to set. */ - public void setId(String value) { + public void setId(java.lang.String value) { this.id = value; } @@ -179,7 +179,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Gets the value of the 'sagaId' field. * @return The value of the 'sagaId' field. */ - public String getSagaId() { + public java.lang.String getSagaId() { return sagaId; } @@ -188,7 +188,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Sets the value of the 'sagaId' field. * @param value the value to set. */ - public void setSagaId(String value) { + public void setSagaId(java.lang.String value) { this.sagaId = value; } @@ -196,7 +196,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Gets the value of the 'customerId' field. * @return The value of the 'customerId' field. */ - public String getCustomerId() { + public java.lang.String getCustomerId() { return customerId; } @@ -205,7 +205,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Sets the value of the 'customerId' field. * @param value the value to set. */ - public void setCustomerId(String value) { + public void setCustomerId(java.lang.String value) { this.customerId = value; } @@ -213,7 +213,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Gets the value of the 'orderId' field. * @return The value of the 'orderId' field. */ - public String getOrderId() { + public java.lang.String getOrderId() { return orderId; } @@ -222,7 +222,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Sets the value of the 'orderId' field. * @param value the value to set. */ - public void setOrderId(String value) { + public void setOrderId(java.lang.String value) { this.orderId = value; } @@ -264,7 +264,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Gets the value of the 'paymentOrderStatus' field. * @return The value of the 'paymentOrderStatus' field. */ - public PaymentOrderStatus getPaymentOrderStatus() { + public com.food.order.system.kafka.order.avro.model.PaymentOrderStatus getPaymentOrderStatus() { return paymentOrderStatus; } @@ -273,7 +273,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Sets the value of the 'paymentOrderStatus' field. * @param value the value to set. */ - public void setPaymentOrderStatus(PaymentOrderStatus value) { + public void setPaymentOrderStatus(com.food.order.system.kafka.order.avro.model.PaymentOrderStatus value) { this.paymentOrderStatus = value; } @@ -281,8 +281,8 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Creates a new PaymentRequestAvroModel RecordBuilder. * @return A new PaymentRequestAvroModel RecordBuilder */ - public static Builder newBuilder() { - return new Builder(); + public static com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder newBuilder() { + return new com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder(); } /** @@ -290,11 +290,11 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * @param other The existing builder to copy. * @return A new PaymentRequestAvroModel RecordBuilder */ - public static Builder newBuilder(Builder other) { + public static com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder newBuilder(com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder other) { if (other == null) { - return new Builder(); + return new com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder(); } else { - return new Builder(other); + return new com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder(other); } } @@ -303,11 +303,11 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * @param other The existing instance to copy. * @return A new PaymentRequestAvroModel RecordBuilder */ - public static Builder newBuilder(PaymentRequestAvroModel other) { + public static com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder newBuilder(com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel other) { if (other == null) { - return new Builder(); + return new com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder(); } else { - return new Builder(other); + return new com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder(other); } } @@ -318,13 +318,13 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe public static class Builder extends org.apache.avro.specific.SpecificRecordBuilderBase implements org.apache.avro.data.RecordBuilder { - private String id; - private String sagaId; - private String customerId; - private String orderId; + private java.lang.String id; + private java.lang.String sagaId; + private java.lang.String customerId; + private java.lang.String orderId; private java.math.BigDecimal price; private java.time.Instant createdAt; - private PaymentOrderStatus paymentOrderStatus; + private com.food.order.system.kafka.order.avro.model.PaymentOrderStatus paymentOrderStatus; /** Creates a new Builder */ private Builder() { @@ -335,7 +335,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Creates a Builder by copying an existing Builder. * @param other The existing Builder to copy. */ - private Builder(Builder other) { + private Builder(com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder other) { super(other); if (isValidValue(fields()[0], other.id)) { this.id = data().deepCopy(fields()[0].schema(), other.id); @@ -371,7 +371,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Creates a Builder by copying an existing PaymentRequestAvroModel instance * @param other The existing instance to copy. */ - private Builder(PaymentRequestAvroModel other) { + private Builder(com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel other) { super(SCHEMA$, MODEL$); if (isValidValue(fields()[0], other.id)) { this.id = data().deepCopy(fields()[0].schema(), other.id); @@ -407,7 +407,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Gets the value of the 'id' field. * @return The value. */ - public String getId() { + public java.lang.String getId() { return id; } @@ -417,7 +417,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * @param value The value of 'id'. * @return This builder. */ - public Builder setId(String value) { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder setId(java.lang.String value) { validate(fields()[0], value); this.id = value; fieldSetFlags()[0] = true; @@ -437,7 +437,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Clears the value of the 'id' field. * @return This builder. */ - public Builder clearId() { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder clearId() { id = null; fieldSetFlags()[0] = false; return this; @@ -447,7 +447,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Gets the value of the 'sagaId' field. * @return The value. */ - public String getSagaId() { + public java.lang.String getSagaId() { return sagaId; } @@ -457,7 +457,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * @param value The value of 'sagaId'. * @return This builder. */ - public Builder setSagaId(String value) { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder setSagaId(java.lang.String value) { validate(fields()[1], value); this.sagaId = value; fieldSetFlags()[1] = true; @@ -477,7 +477,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Clears the value of the 'sagaId' field. * @return This builder. */ - public Builder clearSagaId() { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder clearSagaId() { sagaId = null; fieldSetFlags()[1] = false; return this; @@ -487,7 +487,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Gets the value of the 'customerId' field. * @return The value. */ - public String getCustomerId() { + public java.lang.String getCustomerId() { return customerId; } @@ -497,7 +497,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * @param value The value of 'customerId'. * @return This builder. */ - public Builder setCustomerId(String value) { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder setCustomerId(java.lang.String value) { validate(fields()[2], value); this.customerId = value; fieldSetFlags()[2] = true; @@ -517,7 +517,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Clears the value of the 'customerId' field. * @return This builder. */ - public Builder clearCustomerId() { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder clearCustomerId() { customerId = null; fieldSetFlags()[2] = false; return this; @@ -527,7 +527,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Gets the value of the 'orderId' field. * @return The value. */ - public String getOrderId() { + public java.lang.String getOrderId() { return orderId; } @@ -537,7 +537,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * @param value The value of 'orderId'. * @return This builder. */ - public Builder setOrderId(String value) { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder setOrderId(java.lang.String value) { validate(fields()[3], value); this.orderId = value; fieldSetFlags()[3] = true; @@ -557,7 +557,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Clears the value of the 'orderId' field. * @return This builder. */ - public Builder clearOrderId() { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder clearOrderId() { orderId = null; fieldSetFlags()[3] = false; return this; @@ -577,7 +577,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * @param value The value of 'price'. * @return This builder. */ - public Builder setPrice(java.math.BigDecimal value) { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder setPrice(java.math.BigDecimal value) { validate(fields()[4], value); this.price = value; fieldSetFlags()[4] = true; @@ -597,7 +597,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Clears the value of the 'price' field. * @return This builder. */ - public Builder clearPrice() { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder clearPrice() { price = null; fieldSetFlags()[4] = false; return this; @@ -617,7 +617,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * @param value The value of 'createdAt'. * @return This builder. */ - public Builder setCreatedAt(java.time.Instant value) { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder setCreatedAt(java.time.Instant value) { validate(fields()[5], value); this.createdAt = value.truncatedTo(java.time.temporal.ChronoUnit.MILLIS); fieldSetFlags()[5] = true; @@ -637,7 +637,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Clears the value of the 'createdAt' field. * @return This builder. */ - public Builder clearCreatedAt() { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder clearCreatedAt() { fieldSetFlags()[5] = false; return this; } @@ -646,7 +646,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Gets the value of the 'paymentOrderStatus' field. * @return The value. */ - public PaymentOrderStatus getPaymentOrderStatus() { + public com.food.order.system.kafka.order.avro.model.PaymentOrderStatus getPaymentOrderStatus() { return paymentOrderStatus; } @@ -656,7 +656,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * @param value The value of 'paymentOrderStatus'. * @return This builder. */ - public Builder setPaymentOrderStatus(PaymentOrderStatus value) { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder setPaymentOrderStatus(com.food.order.system.kafka.order.avro.model.PaymentOrderStatus value) { validate(fields()[6], value); this.paymentOrderStatus = value; fieldSetFlags()[6] = true; @@ -676,7 +676,7 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe * Clears the value of the 'paymentOrderStatus' field. * @return This builder. */ - public Builder clearPaymentOrderStatus() { + public com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel.Builder clearPaymentOrderStatus() { paymentOrderStatus = null; fieldSetFlags()[6] = false; return this; @@ -687,17 +687,17 @@ public class PaymentRequestAvroModel extends org.apache.avro.specific.SpecificRe public PaymentRequestAvroModel build() { try { PaymentRequestAvroModel record = new PaymentRequestAvroModel(); - record.id = fieldSetFlags()[0] ? this.id : (String) defaultValue(fields()[0]); - record.sagaId = fieldSetFlags()[1] ? this.sagaId : (String) defaultValue(fields()[1]); - record.customerId = fieldSetFlags()[2] ? this.customerId : (String) defaultValue(fields()[2]); - record.orderId = fieldSetFlags()[3] ? this.orderId : (String) defaultValue(fields()[3]); + record.id = fieldSetFlags()[0] ? this.id : (java.lang.String) defaultValue(fields()[0]); + record.sagaId = fieldSetFlags()[1] ? this.sagaId : (java.lang.String) defaultValue(fields()[1]); + record.customerId = fieldSetFlags()[2] ? this.customerId : (java.lang.String) defaultValue(fields()[2]); + record.orderId = fieldSetFlags()[3] ? this.orderId : (java.lang.String) defaultValue(fields()[3]); record.price = fieldSetFlags()[4] ? this.price : (java.math.BigDecimal) defaultValue(fields()[4]); record.createdAt = fieldSetFlags()[5] ? this.createdAt : (java.time.Instant) defaultValue(fields()[5]); - record.paymentOrderStatus = fieldSetFlags()[6] ? this.paymentOrderStatus : (PaymentOrderStatus) defaultValue(fields()[6]); + record.paymentOrderStatus = fieldSetFlags()[6] ? this.paymentOrderStatus : (com.food.order.system.kafka.order.avro.model.PaymentOrderStatus) defaultValue(fields()[6]); return record; } catch (org.apache.avro.AvroMissingFieldException e) { throw e; - } catch (Exception e) { + } catch (java.lang.Exception e) { throw new org.apache.avro.AvroRuntimeException(e); } } diff --git a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentResponseAvroModel.java b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentResponseAvroModel.java index c8e64ef..f7d9f80 100644 --- a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentResponseAvroModel.java +++ b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentResponseAvroModel.java @@ -5,17 +5,19 @@ */ package com.food.order.system.kafka.order.avro.model; +import org.apache.avro.generic.GenericArray; import org.apache.avro.specific.SpecificData; +import org.apache.avro.util.Utf8; import org.apache.avro.message.BinaryMessageEncoder; import org.apache.avro.message.BinaryMessageDecoder; import org.apache.avro.message.SchemaStore; @org.apache.avro.specific.AvroGenerated public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { - private static final long serialVersionUID = -2126784712017759782L; + private static final long serialVersionUID = -3686686114915224929L; - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"PaymentResponseAvroModel\",\"namespace\":\"com.food.ordering.system.kafka.order.avro.model\",\"fields\":[{\"name\":\"id\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"sagaId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"paymentId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"customerId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"orderId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"price\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":10,\"scale\":2}},{\"name\":\"createdAt\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}},{\"name\":\"paymentStatus\",\"type\":{\"type\":\"enum\",\"name\":\"PaymentStatus\",\"symbols\":[\"COMPLETED\",\"CANCELLED\",\"FAILED\"]}},{\"name\":\"failureMessages\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"avro.java.string\":\"String\"}}}]}"); + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"PaymentResponseAvroModel\",\"namespace\":\"com.food.order.system.kafka.order.avro.model\",\"fields\":[{\"name\":\"id\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"sagaId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"paymentId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"customerId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"orderId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"price\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":10,\"scale\":2}},{\"name\":\"createdAt\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}},{\"name\":\"paymentStatus\",\"type\":{\"type\":\"enum\",\"name\":\"PaymentStatus\",\"symbols\":[\"COMPLETED\",\"CANCELLED\",\"FAILED\"]}},{\"name\":\"failureMessages\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"avro.java.string\":\"String\"}}}]}"); public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } private static final SpecificData MODEL$ = new SpecificData(); @@ -82,7 +84,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR private java.lang.String orderId; private java.math.BigDecimal price; private java.time.Instant createdAt; - private PaymentStatus paymentStatus; + private com.food.order.system.kafka.order.avro.model.PaymentStatus paymentStatus; private java.util.List failureMessages; /** @@ -104,7 +106,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * @param paymentStatus The new value for paymentStatus * @param failureMessages The new value for failureMessages */ - public PaymentResponseAvroModel(java.lang.String id, java.lang.String sagaId, java.lang.String paymentId, java.lang.String customerId, java.lang.String orderId, java.math.BigDecimal price, java.time.Instant createdAt, PaymentStatus paymentStatus, java.util.List failureMessages) { + public PaymentResponseAvroModel(java.lang.String id, java.lang.String sagaId, java.lang.String paymentId, java.lang.String customerId, java.lang.String orderId, java.math.BigDecimal price, java.time.Instant createdAt, com.food.order.system.kafka.order.avro.model.PaymentStatus paymentStatus, java.util.List failureMessages) { this.id = id; this.sagaId = sagaId; this.paymentId = paymentId; @@ -164,7 +166,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR case 4: orderId = value$ != null ? value$.toString() : null; break; case 5: price = (java.math.BigDecimal)value$; break; case 6: createdAt = (java.time.Instant)value$; break; - case 7: paymentStatus = (PaymentStatus)value$; break; + case 7: paymentStatus = (com.food.order.system.kafka.order.avro.model.PaymentStatus)value$; break; case 8: failureMessages = (java.util.List)value$; break; default: throw new IndexOutOfBoundsException("Invalid index: " + field$); } @@ -293,7 +295,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Gets the value of the 'paymentStatus' field. * @return The value of the 'paymentStatus' field. */ - public PaymentStatus getPaymentStatus() { + public com.food.order.system.kafka.order.avro.model.PaymentStatus getPaymentStatus() { return paymentStatus; } @@ -302,7 +304,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Sets the value of the 'paymentStatus' field. * @param value the value to set. */ - public void setPaymentStatus(PaymentStatus value) { + public void setPaymentStatus(com.food.order.system.kafka.order.avro.model.PaymentStatus value) { this.paymentStatus = value; } @@ -327,8 +329,8 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Creates a new PaymentResponseAvroModel RecordBuilder. * @return A new PaymentResponseAvroModel RecordBuilder */ - public static PaymentResponseAvroModel.Builder newBuilder() { - return new PaymentResponseAvroModel.Builder(); + public static com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder newBuilder() { + return new com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder(); } /** @@ -336,11 +338,11 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * @param other The existing builder to copy. * @return A new PaymentResponseAvroModel RecordBuilder */ - public static PaymentResponseAvroModel.Builder newBuilder(PaymentResponseAvroModel.Builder other) { + public static com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder newBuilder(com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder other) { if (other == null) { - return new PaymentResponseAvroModel.Builder(); + return new com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder(); } else { - return new PaymentResponseAvroModel.Builder(other); + return new com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder(other); } } @@ -349,11 +351,11 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * @param other The existing instance to copy. * @return A new PaymentResponseAvroModel RecordBuilder */ - public static PaymentResponseAvroModel.Builder newBuilder(PaymentResponseAvroModel other) { + public static com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder newBuilder(com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel other) { if (other == null) { - return new PaymentResponseAvroModel.Builder(); + return new com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder(); } else { - return new PaymentResponseAvroModel.Builder(other); + return new com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder(other); } } @@ -371,7 +373,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR private java.lang.String orderId; private java.math.BigDecimal price; private java.time.Instant createdAt; - private PaymentStatus paymentStatus; + private com.food.order.system.kafka.order.avro.model.PaymentStatus paymentStatus; private java.util.List failureMessages; /** Creates a new Builder */ @@ -383,7 +385,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Creates a Builder by copying an existing Builder. * @param other The existing Builder to copy. */ - private Builder(PaymentResponseAvroModel.Builder other) { + private Builder(com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder other) { super(other); if (isValidValue(fields()[0], other.id)) { this.id = data().deepCopy(fields()[0].schema(), other.id); @@ -427,7 +429,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Creates a Builder by copying an existing PaymentResponseAvroModel instance * @param other The existing instance to copy. */ - private Builder(PaymentResponseAvroModel other) { + private Builder(com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel other) { super(SCHEMA$, MODEL$); if (isValidValue(fields()[0], other.id)) { this.id = data().deepCopy(fields()[0].schema(), other.id); @@ -481,7 +483,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * @param value The value of 'id'. * @return This builder. */ - public PaymentResponseAvroModel.Builder setId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder setId(java.lang.String value) { validate(fields()[0], value); this.id = value; fieldSetFlags()[0] = true; @@ -501,7 +503,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Clears the value of the 'id' field. * @return This builder. */ - public PaymentResponseAvroModel.Builder clearId() { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder clearId() { id = null; fieldSetFlags()[0] = false; return this; @@ -521,7 +523,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * @param value The value of 'sagaId'. * @return This builder. */ - public PaymentResponseAvroModel.Builder setSagaId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder setSagaId(java.lang.String value) { validate(fields()[1], value); this.sagaId = value; fieldSetFlags()[1] = true; @@ -541,7 +543,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Clears the value of the 'sagaId' field. * @return This builder. */ - public PaymentResponseAvroModel.Builder clearSagaId() { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder clearSagaId() { sagaId = null; fieldSetFlags()[1] = false; return this; @@ -561,7 +563,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * @param value The value of 'paymentId'. * @return This builder. */ - public PaymentResponseAvroModel.Builder setPaymentId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder setPaymentId(java.lang.String value) { validate(fields()[2], value); this.paymentId = value; fieldSetFlags()[2] = true; @@ -581,7 +583,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Clears the value of the 'paymentId' field. * @return This builder. */ - public PaymentResponseAvroModel.Builder clearPaymentId() { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder clearPaymentId() { paymentId = null; fieldSetFlags()[2] = false; return this; @@ -601,7 +603,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * @param value The value of 'customerId'. * @return This builder. */ - public PaymentResponseAvroModel.Builder setCustomerId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder setCustomerId(java.lang.String value) { validate(fields()[3], value); this.customerId = value; fieldSetFlags()[3] = true; @@ -621,7 +623,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Clears the value of the 'customerId' field. * @return This builder. */ - public PaymentResponseAvroModel.Builder clearCustomerId() { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder clearCustomerId() { customerId = null; fieldSetFlags()[3] = false; return this; @@ -641,7 +643,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * @param value The value of 'orderId'. * @return This builder. */ - public PaymentResponseAvroModel.Builder setOrderId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder setOrderId(java.lang.String value) { validate(fields()[4], value); this.orderId = value; fieldSetFlags()[4] = true; @@ -661,7 +663,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Clears the value of the 'orderId' field. * @return This builder. */ - public PaymentResponseAvroModel.Builder clearOrderId() { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder clearOrderId() { orderId = null; fieldSetFlags()[4] = false; return this; @@ -681,7 +683,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * @param value The value of 'price'. * @return This builder. */ - public PaymentResponseAvroModel.Builder setPrice(java.math.BigDecimal value) { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder setPrice(java.math.BigDecimal value) { validate(fields()[5], value); this.price = value; fieldSetFlags()[5] = true; @@ -701,7 +703,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Clears the value of the 'price' field. * @return This builder. */ - public PaymentResponseAvroModel.Builder clearPrice() { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder clearPrice() { price = null; fieldSetFlags()[5] = false; return this; @@ -721,7 +723,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * @param value The value of 'createdAt'. * @return This builder. */ - public PaymentResponseAvroModel.Builder setCreatedAt(java.time.Instant value) { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder setCreatedAt(java.time.Instant value) { validate(fields()[6], value); this.createdAt = value.truncatedTo(java.time.temporal.ChronoUnit.MILLIS); fieldSetFlags()[6] = true; @@ -741,7 +743,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Clears the value of the 'createdAt' field. * @return This builder. */ - public PaymentResponseAvroModel.Builder clearCreatedAt() { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder clearCreatedAt() { fieldSetFlags()[6] = false; return this; } @@ -750,7 +752,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Gets the value of the 'paymentStatus' field. * @return The value. */ - public PaymentStatus getPaymentStatus() { + public com.food.order.system.kafka.order.avro.model.PaymentStatus getPaymentStatus() { return paymentStatus; } @@ -760,7 +762,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * @param value The value of 'paymentStatus'. * @return This builder. */ - public PaymentResponseAvroModel.Builder setPaymentStatus(PaymentStatus value) { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder setPaymentStatus(com.food.order.system.kafka.order.avro.model.PaymentStatus value) { validate(fields()[7], value); this.paymentStatus = value; fieldSetFlags()[7] = true; @@ -780,7 +782,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Clears the value of the 'paymentStatus' field. * @return This builder. */ - public PaymentResponseAvroModel.Builder clearPaymentStatus() { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder clearPaymentStatus() { paymentStatus = null; fieldSetFlags()[7] = false; return this; @@ -800,7 +802,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * @param value The value of 'failureMessages'. * @return This builder. */ - public PaymentResponseAvroModel.Builder setFailureMessages(java.util.List value) { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder setFailureMessages(java.util.List value) { validate(fields()[8], value); this.failureMessages = value; fieldSetFlags()[8] = true; @@ -820,7 +822,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR * Clears the value of the 'failureMessages' field. * @return This builder. */ - public PaymentResponseAvroModel.Builder clearFailureMessages() { + public com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel.Builder clearFailureMessages() { failureMessages = null; fieldSetFlags()[8] = false; return this; @@ -838,7 +840,7 @@ public class PaymentResponseAvroModel extends org.apache.avro.specific.SpecificR record.orderId = fieldSetFlags()[4] ? this.orderId : (java.lang.String) defaultValue(fields()[4]); record.price = fieldSetFlags()[5] ? this.price : (java.math.BigDecimal) defaultValue(fields()[5]); record.createdAt = fieldSetFlags()[6] ? this.createdAt : (java.time.Instant) defaultValue(fields()[6]); - record.paymentStatus = fieldSetFlags()[7] ? this.paymentStatus : (PaymentStatus) defaultValue(fields()[7]); + record.paymentStatus = fieldSetFlags()[7] ? this.paymentStatus : (com.food.order.system.kafka.order.avro.model.PaymentStatus) defaultValue(fields()[7]); record.failureMessages = fieldSetFlags()[8] ? this.failureMessages : (java.util.List) defaultValue(fields()[8]); return record; } catch (org.apache.avro.AvroMissingFieldException e) { diff --git a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentStatus.java b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentStatus.java index aad5b0e..be0b3fa 100644 --- a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentStatus.java +++ b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/PaymentStatus.java @@ -7,7 +7,7 @@ package com.food.order.system.kafka.order.avro.model; @org.apache.avro.specific.AvroGenerated public enum PaymentStatus implements org.apache.avro.generic.GenericEnumSymbol { COMPLETED, CANCELLED, FAILED ; - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"PaymentStatus\",\"namespace\":\"com.food.ordering.system.kafka.order.avro.model\",\"symbols\":[\"COMPLETED\",\"CANCELLED\",\"FAILED\"]}"); + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"PaymentStatus\",\"namespace\":\"com.food.order.system.kafka.order.avro.model\",\"symbols\":[\"COMPLETED\",\"CANCELLED\",\"FAILED\"]}"); public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } public org.apache.avro.Schema getSchema() { return SCHEMA$; } } diff --git a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/Product.java b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/Product.java index c07eeea..272c966 100644 --- a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/Product.java +++ b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/Product.java @@ -5,17 +5,19 @@ */ package com.food.order.system.kafka.order.avro.model; -import org.apache.avro.message.BinaryMessageDecoder; -import org.apache.avro.message.BinaryMessageEncoder; -import org.apache.avro.message.SchemaStore; +import org.apache.avro.generic.GenericArray; import org.apache.avro.specific.SpecificData; +import org.apache.avro.util.Utf8; +import org.apache.avro.message.BinaryMessageEncoder; +import org.apache.avro.message.BinaryMessageDecoder; +import org.apache.avro.message.SchemaStore; @org.apache.avro.specific.AvroGenerated public class Product extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { - private static final long serialVersionUID = -6511580554663840009L; + private static final long serialVersionUID = -6762943505103404653L; - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Product\",\"namespace\":\"com.food.ordering.system.kafka.order.avro.model\",\"fields\":[{\"name\":\"id\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"},\"logicalType\":\"uuid\"},{\"name\":\"quantity\",\"type\":\"int\"}]}"); + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"Product\",\"namespace\":\"com.food.order.system.kafka.order.avro.model\",\"fields\":[{\"name\":\"id\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"},\"logicalType\":\"uuid\"},{\"name\":\"quantity\",\"type\":\"int\"}]}"); public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } private static final SpecificData MODEL$ = new SpecificData(); @@ -150,8 +152,8 @@ public class Product extends org.apache.avro.specific.SpecificRecordBase impleme * Creates a new Product RecordBuilder. * @return A new Product RecordBuilder */ - public static Product.Builder newBuilder() { - return new Product.Builder(); + public static com.food.order.system.kafka.order.avro.model.Product.Builder newBuilder() { + return new com.food.order.system.kafka.order.avro.model.Product.Builder(); } /** @@ -159,11 +161,11 @@ public class Product extends org.apache.avro.specific.SpecificRecordBase impleme * @param other The existing builder to copy. * @return A new Product RecordBuilder */ - public static Product.Builder newBuilder(Product.Builder other) { + public static com.food.order.system.kafka.order.avro.model.Product.Builder newBuilder(com.food.order.system.kafka.order.avro.model.Product.Builder other) { if (other == null) { - return new Product.Builder(); + return new com.food.order.system.kafka.order.avro.model.Product.Builder(); } else { - return new Product.Builder(other); + return new com.food.order.system.kafka.order.avro.model.Product.Builder(other); } } @@ -172,11 +174,11 @@ public class Product extends org.apache.avro.specific.SpecificRecordBase impleme * @param other The existing instance to copy. * @return A new Product RecordBuilder */ - public static Product.Builder newBuilder(Product other) { + public static com.food.order.system.kafka.order.avro.model.Product.Builder newBuilder(com.food.order.system.kafka.order.avro.model.Product other) { if (other == null) { - return new Product.Builder(); + return new com.food.order.system.kafka.order.avro.model.Product.Builder(); } else { - return new Product.Builder(other); + return new com.food.order.system.kafka.order.avro.model.Product.Builder(other); } } @@ -199,7 +201,7 @@ public class Product extends org.apache.avro.specific.SpecificRecordBase impleme * Creates a Builder by copying an existing Builder. * @param other The existing Builder to copy. */ - private Builder(Product.Builder other) { + private Builder(com.food.order.system.kafka.order.avro.model.Product.Builder other) { super(other); if (isValidValue(fields()[0], other.id)) { this.id = data().deepCopy(fields()[0].schema(), other.id); @@ -215,7 +217,7 @@ public class Product extends org.apache.avro.specific.SpecificRecordBase impleme * Creates a Builder by copying an existing Product instance * @param other The existing instance to copy. */ - private Builder(Product other) { + private Builder(com.food.order.system.kafka.order.avro.model.Product other) { super(SCHEMA$, MODEL$); if (isValidValue(fields()[0], other.id)) { this.id = data().deepCopy(fields()[0].schema(), other.id); @@ -241,7 +243,7 @@ public class Product extends org.apache.avro.specific.SpecificRecordBase impleme * @param value The value of 'id'. * @return This builder. */ - public Product.Builder setId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.Product.Builder setId(java.lang.String value) { validate(fields()[0], value); this.id = value; fieldSetFlags()[0] = true; @@ -261,7 +263,7 @@ public class Product extends org.apache.avro.specific.SpecificRecordBase impleme * Clears the value of the 'id' field. * @return This builder. */ - public Product.Builder clearId() { + public com.food.order.system.kafka.order.avro.model.Product.Builder clearId() { id = null; fieldSetFlags()[0] = false; return this; @@ -281,7 +283,7 @@ public class Product extends org.apache.avro.specific.SpecificRecordBase impleme * @param value The value of 'quantity'. * @return This builder. */ - public Product.Builder setQuantity(int value) { + public com.food.order.system.kafka.order.avro.model.Product.Builder setQuantity(int value) { validate(fields()[1], value); this.quantity = value; fieldSetFlags()[1] = true; @@ -301,7 +303,7 @@ public class Product extends org.apache.avro.specific.SpecificRecordBase impleme * Clears the value of the 'quantity' field. * @return This builder. */ - public Product.Builder clearQuantity() { + public com.food.order.system.kafka.order.avro.model.Product.Builder clearQuantity() { fieldSetFlags()[1] = false; return this; } diff --git a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/RestaurantApprovalRequestAvroModel.java b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/RestaurantApprovalRequestAvroModel.java index 6313129..c8fcaa2 100644 --- a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/RestaurantApprovalRequestAvroModel.java +++ b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/RestaurantApprovalRequestAvroModel.java @@ -5,17 +5,19 @@ */ package com.food.order.system.kafka.order.avro.model; +import org.apache.avro.generic.GenericArray; import org.apache.avro.specific.SpecificData; +import org.apache.avro.util.Utf8; import org.apache.avro.message.BinaryMessageEncoder; import org.apache.avro.message.BinaryMessageDecoder; import org.apache.avro.message.SchemaStore; @org.apache.avro.specific.AvroGenerated public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { - private static final long serialVersionUID = -3917361261016430486L; + private static final long serialVersionUID = -3514710772324064017L; - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"RestaurantApprovalRequestAvroModel\",\"namespace\":\"com.food.ordering.system.kafka.order.avro.model\",\"fields\":[{\"name\":\"id\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"sagaId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"restaurantId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"orderId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"restaurantOrderStatus\",\"type\":{\"type\":\"enum\",\"name\":\"RestaurantOrderStatus\",\"symbols\":[\"PAID\"]}},{\"name\":\"products\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"Product\",\"fields\":[{\"name\":\"id\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"},\"logicalType\":\"uuid\"},{\"name\":\"quantity\",\"type\":\"int\"}]}}},{\"name\":\"price\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":10,\"scale\":2}},{\"name\":\"createdAt\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}}]}"); + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"RestaurantApprovalRequestAvroModel\",\"namespace\":\"com.food.order.system.kafka.order.avro.model\",\"fields\":[{\"name\":\"id\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"sagaId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"restaurantId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"orderId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"restaurantOrderStatus\",\"type\":{\"type\":\"enum\",\"name\":\"RestaurantOrderStatus\",\"symbols\":[\"PAID\"]}},{\"name\":\"products\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"record\",\"name\":\"Product\",\"fields\":[{\"name\":\"id\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"},\"logicalType\":\"uuid\"},{\"name\":\"quantity\",\"type\":\"int\"}]}}},{\"name\":\"price\",\"type\":{\"type\":\"bytes\",\"logicalType\":\"decimal\",\"precision\":10,\"scale\":2}},{\"name\":\"createdAt\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}}]}"); public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } private static final SpecificData MODEL$ = new SpecificData(); @@ -79,8 +81,8 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific private java.lang.String sagaId; private java.lang.String restaurantId; private java.lang.String orderId; - private RestaurantOrderStatus restaurantOrderStatus; - private java.util.List products; + private com.food.order.system.kafka.order.avro.model.RestaurantOrderStatus restaurantOrderStatus; + private java.util.List products; private java.math.BigDecimal price; private java.time.Instant createdAt; @@ -102,7 +104,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * @param price The new value for price * @param createdAt The new value for createdAt */ - public RestaurantApprovalRequestAvroModel(java.lang.String id, java.lang.String sagaId, java.lang.String restaurantId, java.lang.String orderId, RestaurantOrderStatus restaurantOrderStatus, java.util.List products, java.math.BigDecimal price, java.time.Instant createdAt) { + public RestaurantApprovalRequestAvroModel(java.lang.String id, java.lang.String sagaId, java.lang.String restaurantId, java.lang.String orderId, com.food.order.system.kafka.order.avro.model.RestaurantOrderStatus restaurantOrderStatus, java.util.List products, java.math.BigDecimal price, java.time.Instant createdAt) { this.id = id; this.sagaId = sagaId; this.restaurantId = restaurantId; @@ -156,8 +158,8 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific case 1: sagaId = value$ != null ? value$.toString() : null; break; case 2: restaurantId = value$ != null ? value$.toString() : null; break; case 3: orderId = value$ != null ? value$.toString() : null; break; - case 4: restaurantOrderStatus = (RestaurantOrderStatus)value$; break; - case 5: products = (java.util.List)value$; break; + case 4: restaurantOrderStatus = (com.food.order.system.kafka.order.avro.model.RestaurantOrderStatus)value$; break; + case 5: products = (java.util.List)value$; break; case 6: price = (java.math.BigDecimal)value$; break; case 7: createdAt = (java.time.Instant)value$; break; default: throw new IndexOutOfBoundsException("Invalid index: " + field$); @@ -236,7 +238,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Gets the value of the 'restaurantOrderStatus' field. * @return The value of the 'restaurantOrderStatus' field. */ - public RestaurantOrderStatus getRestaurantOrderStatus() { + public com.food.order.system.kafka.order.avro.model.RestaurantOrderStatus getRestaurantOrderStatus() { return restaurantOrderStatus; } @@ -245,7 +247,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Sets the value of the 'restaurantOrderStatus' field. * @param value the value to set. */ - public void setRestaurantOrderStatus(RestaurantOrderStatus value) { + public void setRestaurantOrderStatus(com.food.order.system.kafka.order.avro.model.RestaurantOrderStatus value) { this.restaurantOrderStatus = value; } @@ -253,7 +255,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Gets the value of the 'products' field. * @return The value of the 'products' field. */ - public java.util.List getProducts() { + public java.util.List getProducts() { return products; } @@ -262,7 +264,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Sets the value of the 'products' field. * @param value the value to set. */ - public void setProducts(java.util.List value) { + public void setProducts(java.util.List value) { this.products = value; } @@ -304,8 +306,8 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Creates a new RestaurantApprovalRequestAvroModel RecordBuilder. * @return A new RestaurantApprovalRequestAvroModel RecordBuilder */ - public static RestaurantApprovalRequestAvroModel.Builder newBuilder() { - return new RestaurantApprovalRequestAvroModel.Builder(); + public static com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder newBuilder() { + return new com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder(); } /** @@ -313,11 +315,11 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * @param other The existing builder to copy. * @return A new RestaurantApprovalRequestAvroModel RecordBuilder */ - public static RestaurantApprovalRequestAvroModel.Builder newBuilder(RestaurantApprovalRequestAvroModel.Builder other) { + public static com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder newBuilder(com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder other) { if (other == null) { - return new RestaurantApprovalRequestAvroModel.Builder(); + return new com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder(); } else { - return new RestaurantApprovalRequestAvroModel.Builder(other); + return new com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder(other); } } @@ -326,11 +328,11 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * @param other The existing instance to copy. * @return A new RestaurantApprovalRequestAvroModel RecordBuilder */ - public static RestaurantApprovalRequestAvroModel.Builder newBuilder(RestaurantApprovalRequestAvroModel other) { + public static com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder newBuilder(com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel other) { if (other == null) { - return new RestaurantApprovalRequestAvroModel.Builder(); + return new com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder(); } else { - return new RestaurantApprovalRequestAvroModel.Builder(other); + return new com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder(other); } } @@ -345,8 +347,8 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific private java.lang.String sagaId; private java.lang.String restaurantId; private java.lang.String orderId; - private RestaurantOrderStatus restaurantOrderStatus; - private java.util.List products; + private com.food.order.system.kafka.order.avro.model.RestaurantOrderStatus restaurantOrderStatus; + private java.util.List products; private java.math.BigDecimal price; private java.time.Instant createdAt; @@ -359,7 +361,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Creates a Builder by copying an existing Builder. * @param other The existing Builder to copy. */ - private Builder(RestaurantApprovalRequestAvroModel.Builder other) { + private Builder(com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder other) { super(other); if (isValidValue(fields()[0], other.id)) { this.id = data().deepCopy(fields()[0].schema(), other.id); @@ -399,7 +401,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Creates a Builder by copying an existing RestaurantApprovalRequestAvroModel instance * @param other The existing instance to copy. */ - private Builder(RestaurantApprovalRequestAvroModel other) { + private Builder(com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel other) { super(SCHEMA$, MODEL$); if (isValidValue(fields()[0], other.id)) { this.id = data().deepCopy(fields()[0].schema(), other.id); @@ -449,7 +451,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * @param value The value of 'id'. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder setId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder setId(java.lang.String value) { validate(fields()[0], value); this.id = value; fieldSetFlags()[0] = true; @@ -469,7 +471,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Clears the value of the 'id' field. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder clearId() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder clearId() { id = null; fieldSetFlags()[0] = false; return this; @@ -489,7 +491,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * @param value The value of 'sagaId'. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder setSagaId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder setSagaId(java.lang.String value) { validate(fields()[1], value); this.sagaId = value; fieldSetFlags()[1] = true; @@ -509,7 +511,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Clears the value of the 'sagaId' field. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder clearSagaId() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder clearSagaId() { sagaId = null; fieldSetFlags()[1] = false; return this; @@ -529,7 +531,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * @param value The value of 'restaurantId'. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder setRestaurantId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder setRestaurantId(java.lang.String value) { validate(fields()[2], value); this.restaurantId = value; fieldSetFlags()[2] = true; @@ -549,7 +551,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Clears the value of the 'restaurantId' field. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder clearRestaurantId() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder clearRestaurantId() { restaurantId = null; fieldSetFlags()[2] = false; return this; @@ -569,7 +571,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * @param value The value of 'orderId'. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder setOrderId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder setOrderId(java.lang.String value) { validate(fields()[3], value); this.orderId = value; fieldSetFlags()[3] = true; @@ -589,7 +591,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Clears the value of the 'orderId' field. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder clearOrderId() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder clearOrderId() { orderId = null; fieldSetFlags()[3] = false; return this; @@ -599,7 +601,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Gets the value of the 'restaurantOrderStatus' field. * @return The value. */ - public RestaurantOrderStatus getRestaurantOrderStatus() { + public com.food.order.system.kafka.order.avro.model.RestaurantOrderStatus getRestaurantOrderStatus() { return restaurantOrderStatus; } @@ -609,7 +611,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * @param value The value of 'restaurantOrderStatus'. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder setRestaurantOrderStatus(RestaurantOrderStatus value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder setRestaurantOrderStatus(com.food.order.system.kafka.order.avro.model.RestaurantOrderStatus value) { validate(fields()[4], value); this.restaurantOrderStatus = value; fieldSetFlags()[4] = true; @@ -629,7 +631,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Clears the value of the 'restaurantOrderStatus' field. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder clearRestaurantOrderStatus() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder clearRestaurantOrderStatus() { restaurantOrderStatus = null; fieldSetFlags()[4] = false; return this; @@ -639,7 +641,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Gets the value of the 'products' field. * @return The value. */ - public java.util.List getProducts() { + public java.util.List getProducts() { return products; } @@ -649,7 +651,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * @param value The value of 'products'. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder setProducts(java.util.List value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder setProducts(java.util.List value) { validate(fields()[5], value); this.products = value; fieldSetFlags()[5] = true; @@ -669,7 +671,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Clears the value of the 'products' field. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder clearProducts() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder clearProducts() { products = null; fieldSetFlags()[5] = false; return this; @@ -689,7 +691,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * @param value The value of 'price'. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder setPrice(java.math.BigDecimal value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder setPrice(java.math.BigDecimal value) { validate(fields()[6], value); this.price = value; fieldSetFlags()[6] = true; @@ -709,7 +711,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Clears the value of the 'price' field. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder clearPrice() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder clearPrice() { price = null; fieldSetFlags()[6] = false; return this; @@ -729,7 +731,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * @param value The value of 'createdAt'. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder setCreatedAt(java.time.Instant value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder setCreatedAt(java.time.Instant value) { validate(fields()[7], value); this.createdAt = value.truncatedTo(java.time.temporal.ChronoUnit.MILLIS); fieldSetFlags()[7] = true; @@ -749,7 +751,7 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific * Clears the value of the 'createdAt' field. * @return This builder. */ - public RestaurantApprovalRequestAvroModel.Builder clearCreatedAt() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel.Builder clearCreatedAt() { fieldSetFlags()[7] = false; return this; } @@ -763,8 +765,8 @@ public class RestaurantApprovalRequestAvroModel extends org.apache.avro.specific record.sagaId = fieldSetFlags()[1] ? this.sagaId : (java.lang.String) defaultValue(fields()[1]); record.restaurantId = fieldSetFlags()[2] ? this.restaurantId : (java.lang.String) defaultValue(fields()[2]); record.orderId = fieldSetFlags()[3] ? this.orderId : (java.lang.String) defaultValue(fields()[3]); - record.restaurantOrderStatus = fieldSetFlags()[4] ? this.restaurantOrderStatus : (RestaurantOrderStatus) defaultValue(fields()[4]); - record.products = fieldSetFlags()[5] ? this.products : (java.util.List) defaultValue(fields()[5]); + record.restaurantOrderStatus = fieldSetFlags()[4] ? this.restaurantOrderStatus : (com.food.order.system.kafka.order.avro.model.RestaurantOrderStatus) defaultValue(fields()[4]); + record.products = fieldSetFlags()[5] ? this.products : (java.util.List) defaultValue(fields()[5]); record.price = fieldSetFlags()[6] ? this.price : (java.math.BigDecimal) defaultValue(fields()[6]); record.createdAt = fieldSetFlags()[7] ? this.createdAt : (java.time.Instant) defaultValue(fields()[7]); return record; diff --git a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/RestaurantApprovalResponseAvroModel.java b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/RestaurantApprovalResponseAvroModel.java index 4aa525b..fe43b73 100644 --- a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/RestaurantApprovalResponseAvroModel.java +++ b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/RestaurantApprovalResponseAvroModel.java @@ -5,17 +5,19 @@ */ package com.food.order.system.kafka.order.avro.model; +import org.apache.avro.generic.GenericArray; import org.apache.avro.specific.SpecificData; +import org.apache.avro.util.Utf8; import org.apache.avro.message.BinaryMessageEncoder; import org.apache.avro.message.BinaryMessageDecoder; import org.apache.avro.message.SchemaStore; @org.apache.avro.specific.AvroGenerated public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specific.SpecificRecordBase implements org.apache.avro.specific.SpecificRecord { - private static final long serialVersionUID = -3431989201238018220L; + private static final long serialVersionUID = -5203212934279996672L; - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"RestaurantApprovalResponseAvroModel\",\"namespace\":\"com.food.ordering.system.kafka.order.avro.model\",\"fields\":[{\"name\":\"id\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"sagaId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"restaurantId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"orderId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"createdAt\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}},{\"name\":\"orderApprovalStatus\",\"type\":{\"type\":\"enum\",\"name\":\"OrderApprovalStatus\",\"symbols\":[\"APPROVED\",\"REJECTED\"]}},{\"name\":\"failureMessages\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"avro.java.string\":\"String\"}}}]}"); + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"record\",\"name\":\"RestaurantApprovalResponseAvroModel\",\"namespace\":\"com.food.order.system.kafka.order.avro.model\",\"fields\":[{\"name\":\"id\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"sagaId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"restaurantId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"orderId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"}},{\"name\":\"createdAt\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"}},{\"name\":\"orderApprovalStatus\",\"type\":{\"type\":\"enum\",\"name\":\"OrderApprovalStatus\",\"symbols\":[\"APPROVED\",\"REJECTED\"]}},{\"name\":\"failureMessages\",\"type\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"avro.java.string\":\"String\"}}}]}"); public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } private static final SpecificData MODEL$ = new SpecificData(); @@ -79,7 +81,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi private java.lang.String restaurantId; private java.lang.String orderId; private java.time.Instant createdAt; - private OrderApprovalStatus orderApprovalStatus; + private com.food.order.system.kafka.order.avro.model.OrderApprovalStatus orderApprovalStatus; private java.util.List failureMessages; /** @@ -99,7 +101,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * @param orderApprovalStatus The new value for orderApprovalStatus * @param failureMessages The new value for failureMessages */ - public RestaurantApprovalResponseAvroModel(java.lang.String id, java.lang.String sagaId, java.lang.String restaurantId, java.lang.String orderId, java.time.Instant createdAt, OrderApprovalStatus orderApprovalStatus, java.util.List failureMessages) { + public RestaurantApprovalResponseAvroModel(java.lang.String id, java.lang.String sagaId, java.lang.String restaurantId, java.lang.String orderId, java.time.Instant createdAt, com.food.order.system.kafka.order.avro.model.OrderApprovalStatus orderApprovalStatus, java.util.List failureMessages) { this.id = id; this.sagaId = sagaId; this.restaurantId = restaurantId; @@ -151,7 +153,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi case 2: restaurantId = value$ != null ? value$.toString() : null; break; case 3: orderId = value$ != null ? value$.toString() : null; break; case 4: createdAt = (java.time.Instant)value$; break; - case 5: orderApprovalStatus = (OrderApprovalStatus)value$; break; + case 5: orderApprovalStatus = (com.food.order.system.kafka.order.avro.model.OrderApprovalStatus)value$; break; case 6: failureMessages = (java.util.List)value$; break; default: throw new IndexOutOfBoundsException("Invalid index: " + field$); } @@ -246,7 +248,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Gets the value of the 'orderApprovalStatus' field. * @return The value of the 'orderApprovalStatus' field. */ - public OrderApprovalStatus getOrderApprovalStatus() { + public com.food.order.system.kafka.order.avro.model.OrderApprovalStatus getOrderApprovalStatus() { return orderApprovalStatus; } @@ -255,7 +257,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Sets the value of the 'orderApprovalStatus' field. * @param value the value to set. */ - public void setOrderApprovalStatus(OrderApprovalStatus value) { + public void setOrderApprovalStatus(com.food.order.system.kafka.order.avro.model.OrderApprovalStatus value) { this.orderApprovalStatus = value; } @@ -280,8 +282,8 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Creates a new RestaurantApprovalResponseAvroModel RecordBuilder. * @return A new RestaurantApprovalResponseAvroModel RecordBuilder */ - public static RestaurantApprovalResponseAvroModel.Builder newBuilder() { - return new RestaurantApprovalResponseAvroModel.Builder(); + public static com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder newBuilder() { + return new com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder(); } /** @@ -289,11 +291,11 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * @param other The existing builder to copy. * @return A new RestaurantApprovalResponseAvroModel RecordBuilder */ - public static RestaurantApprovalResponseAvroModel.Builder newBuilder(RestaurantApprovalResponseAvroModel.Builder other) { + public static com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder newBuilder(com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder other) { if (other == null) { - return new RestaurantApprovalResponseAvroModel.Builder(); + return new com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder(); } else { - return new RestaurantApprovalResponseAvroModel.Builder(other); + return new com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder(other); } } @@ -302,11 +304,11 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * @param other The existing instance to copy. * @return A new RestaurantApprovalResponseAvroModel RecordBuilder */ - public static RestaurantApprovalResponseAvroModel.Builder newBuilder(RestaurantApprovalResponseAvroModel other) { + public static com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder newBuilder(com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel other) { if (other == null) { - return new RestaurantApprovalResponseAvroModel.Builder(); + return new com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder(); } else { - return new RestaurantApprovalResponseAvroModel.Builder(other); + return new com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder(other); } } @@ -322,7 +324,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi private java.lang.String restaurantId; private java.lang.String orderId; private java.time.Instant createdAt; - private OrderApprovalStatus orderApprovalStatus; + private com.food.order.system.kafka.order.avro.model.OrderApprovalStatus orderApprovalStatus; private java.util.List failureMessages; /** Creates a new Builder */ @@ -334,7 +336,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Creates a Builder by copying an existing Builder. * @param other The existing Builder to copy. */ - private Builder(RestaurantApprovalResponseAvroModel.Builder other) { + private Builder(com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder other) { super(other); if (isValidValue(fields()[0], other.id)) { this.id = data().deepCopy(fields()[0].schema(), other.id); @@ -370,7 +372,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Creates a Builder by copying an existing RestaurantApprovalResponseAvroModel instance * @param other The existing instance to copy. */ - private Builder(RestaurantApprovalResponseAvroModel other) { + private Builder(com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel other) { super(SCHEMA$, MODEL$); if (isValidValue(fields()[0], other.id)) { this.id = data().deepCopy(fields()[0].schema(), other.id); @@ -416,7 +418,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * @param value The value of 'id'. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder setId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder setId(java.lang.String value) { validate(fields()[0], value); this.id = value; fieldSetFlags()[0] = true; @@ -436,7 +438,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Clears the value of the 'id' field. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder clearId() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder clearId() { id = null; fieldSetFlags()[0] = false; return this; @@ -456,7 +458,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * @param value The value of 'sagaId'. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder setSagaId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder setSagaId(java.lang.String value) { validate(fields()[1], value); this.sagaId = value; fieldSetFlags()[1] = true; @@ -476,7 +478,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Clears the value of the 'sagaId' field. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder clearSagaId() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder clearSagaId() { sagaId = null; fieldSetFlags()[1] = false; return this; @@ -496,7 +498,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * @param value The value of 'restaurantId'. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder setRestaurantId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder setRestaurantId(java.lang.String value) { validate(fields()[2], value); this.restaurantId = value; fieldSetFlags()[2] = true; @@ -516,7 +518,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Clears the value of the 'restaurantId' field. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder clearRestaurantId() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder clearRestaurantId() { restaurantId = null; fieldSetFlags()[2] = false; return this; @@ -536,7 +538,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * @param value The value of 'orderId'. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder setOrderId(java.lang.String value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder setOrderId(java.lang.String value) { validate(fields()[3], value); this.orderId = value; fieldSetFlags()[3] = true; @@ -556,7 +558,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Clears the value of the 'orderId' field. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder clearOrderId() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder clearOrderId() { orderId = null; fieldSetFlags()[3] = false; return this; @@ -576,7 +578,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * @param value The value of 'createdAt'. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder setCreatedAt(java.time.Instant value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder setCreatedAt(java.time.Instant value) { validate(fields()[4], value); this.createdAt = value.truncatedTo(java.time.temporal.ChronoUnit.MILLIS); fieldSetFlags()[4] = true; @@ -596,7 +598,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Clears the value of the 'createdAt' field. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder clearCreatedAt() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder clearCreatedAt() { fieldSetFlags()[4] = false; return this; } @@ -605,7 +607,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Gets the value of the 'orderApprovalStatus' field. * @return The value. */ - public OrderApprovalStatus getOrderApprovalStatus() { + public com.food.order.system.kafka.order.avro.model.OrderApprovalStatus getOrderApprovalStatus() { return orderApprovalStatus; } @@ -615,7 +617,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * @param value The value of 'orderApprovalStatus'. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder setOrderApprovalStatus(OrderApprovalStatus value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder setOrderApprovalStatus(com.food.order.system.kafka.order.avro.model.OrderApprovalStatus value) { validate(fields()[5], value); this.orderApprovalStatus = value; fieldSetFlags()[5] = true; @@ -635,7 +637,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Clears the value of the 'orderApprovalStatus' field. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder clearOrderApprovalStatus() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder clearOrderApprovalStatus() { orderApprovalStatus = null; fieldSetFlags()[5] = false; return this; @@ -655,7 +657,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * @param value The value of 'failureMessages'. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder setFailureMessages(java.util.List value) { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder setFailureMessages(java.util.List value) { validate(fields()[6], value); this.failureMessages = value; fieldSetFlags()[6] = true; @@ -675,7 +677,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi * Clears the value of the 'failureMessages' field. * @return This builder. */ - public RestaurantApprovalResponseAvroModel.Builder clearFailureMessages() { + public com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel.Builder clearFailureMessages() { failureMessages = null; fieldSetFlags()[6] = false; return this; @@ -691,7 +693,7 @@ public class RestaurantApprovalResponseAvroModel extends org.apache.avro.specifi record.restaurantId = fieldSetFlags()[2] ? this.restaurantId : (java.lang.String) defaultValue(fields()[2]); record.orderId = fieldSetFlags()[3] ? this.orderId : (java.lang.String) defaultValue(fields()[3]); record.createdAt = fieldSetFlags()[4] ? this.createdAt : (java.time.Instant) defaultValue(fields()[4]); - record.orderApprovalStatus = fieldSetFlags()[5] ? this.orderApprovalStatus : (OrderApprovalStatus) defaultValue(fields()[5]); + record.orderApprovalStatus = fieldSetFlags()[5] ? this.orderApprovalStatus : (com.food.order.system.kafka.order.avro.model.OrderApprovalStatus) defaultValue(fields()[5]); record.failureMessages = fieldSetFlags()[6] ? this.failureMessages : (java.util.List) defaultValue(fields()[6]); return record; } catch (org.apache.avro.AvroMissingFieldException e) { diff --git a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/RestaurantOrderStatus.java b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/RestaurantOrderStatus.java index 3bc7626..e7e7850 100644 --- a/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/RestaurantOrderStatus.java +++ b/infrastructure/kafka/kafka-model/src/main/java/com/food/order/system/kafka/order/avro/model/RestaurantOrderStatus.java @@ -7,7 +7,7 @@ package com.food.order.system.kafka.order.avro.model; @org.apache.avro.specific.AvroGenerated public enum RestaurantOrderStatus implements org.apache.avro.generic.GenericEnumSymbol { PAID ; - public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"RestaurantOrderStatus\",\"namespace\":\"com.food.ordering.system.kafka.order.avro.model\",\"symbols\":[\"PAID\"]}"); + public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("{\"type\":\"enum\",\"name\":\"RestaurantOrderStatus\",\"namespace\":\"com.food.order.system.kafka.order.avro.model\",\"symbols\":[\"PAID\"]}"); public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } public org.apache.avro.Schema getSchema() { return SCHEMA$; } } diff --git a/infrastructure/kafka/kafka-model/src/main/resources/avro/payment_response.avsc b/infrastructure/kafka/kafka-model/src/main/resources/avro/payment_response.avsc index a968794..1d2de16 100644 --- a/infrastructure/kafka/kafka-model/src/main/resources/avro/payment_response.avsc +++ b/infrastructure/kafka/kafka-model/src/main/resources/avro/payment_response.avsc @@ -1,5 +1,5 @@ { - "namespace": "com.food.ordering.system.kafka.order.avro.model", + "namespace": "com.food.order.system.kafka.order.avro.model", "type": "record", "name": "PaymentResponseAvroModel", "fields": [ diff --git a/infrastructure/kafka/kafka-model/src/main/resources/avro/restaurant_approval_request.avsc b/infrastructure/kafka/kafka-model/src/main/resources/avro/restaurant_approval_request.avsc index 13d873c..ac95306 100644 --- a/infrastructure/kafka/kafka-model/src/main/resources/avro/restaurant_approval_request.avsc +++ b/infrastructure/kafka/kafka-model/src/main/resources/avro/restaurant_approval_request.avsc @@ -1,5 +1,5 @@ { - "namespace": "com.food.ordering.system.kafka.order.avro.model", + "namespace": "com.food.order.system.kafka.order.avro.model", "type": "record", "name": "RestaurantApprovalRequestAvroModel", "fields": [ diff --git a/infrastructure/kafka/kafka-model/src/main/resources/avro/restaurant_approval_response.avsc b/infrastructure/kafka/kafka-model/src/main/resources/avro/restaurant_approval_response.avsc index ca0bbef..8023076 100644 --- a/infrastructure/kafka/kafka-model/src/main/resources/avro/restaurant_approval_response.avsc +++ b/infrastructure/kafka/kafka-model/src/main/resources/avro/restaurant_approval_response.avsc @@ -1,5 +1,5 @@ { - "namespace": "com.food.ordering.system.kafka.order.avro.model", + "namespace": "com.food.order.system.kafka.order.avro.model", "type": "record", "name": "RestaurantApprovalResponseAvroModel", "fields": [ diff --git a/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/OrderKafkaMessageHelper.java b/infrastructure/kafka/kafka-producer/src/main/java/com/food/order/system/kafka/producer/KafkaMessageHelper.java similarity index 92% rename from order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/OrderKafkaMessageHelper.java rename to infrastructure/kafka/kafka-producer/src/main/java/com/food/order/system/kafka/producer/KafkaMessageHelper.java index eb4c08a..5089369 100644 --- a/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/OrderKafkaMessageHelper.java +++ b/infrastructure/kafka/kafka-producer/src/main/java/com/food/order/system/kafka/producer/KafkaMessageHelper.java @@ -1,4 +1,4 @@ -package com.food.order.system.order.messaging.publisher.kafka; +package com.food.order.system.kafka.producer; import lombok.extern.slf4j.Slf4j; import org.apache.kafka.clients.producer.RecordMetadata; @@ -8,7 +8,7 @@ import org.springframework.util.concurrent.ListenableFutureCallback; @Component @Slf4j -public class OrderKafkaMessageHelper { +public class KafkaMessageHelper { public ListenableFutureCallback> getKafkaCallBack (String responseTopicName, T t,String orderId, String requestAvroModelName) { diff --git a/infrastructure/kafka/kafka-producer/src/main/java/com/food/order/system/kafka/producer/service/impl/KafkaProducerImpl.java b/infrastructure/kafka/kafka-producer/src/main/java/com/food/order/system/kafka/producer/service/impl/KafkaProducerImpl.java index cd818e7..4fca267 100644 --- a/infrastructure/kafka/kafka-producer/src/main/java/com/food/order/system/kafka/producer/service/impl/KafkaProducerImpl.java +++ b/infrastructure/kafka/kafka-producer/src/main/java/com/food/order/system/kafka/producer/service/impl/KafkaProducerImpl.java @@ -1,48 +1,52 @@ package com.food.order.system.kafka.producer.service.impl; -import com.food.order.system.kafka.producer.exception.KafkaProducerException; import com.food.order.system.kafka.producer.service.KafkaProducer; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.avro.specific.SpecificRecordBase; -import org.springframework.kafka.KafkaException; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.support.SendResult; import org.springframework.stereotype.Component; -import org.springframework.util.concurrent.ListenableFuture; import org.springframework.util.concurrent.ListenableFutureCallback; import javax.annotation.PreDestroy; import java.io.Serializable; +import java.util.Objects; -@Slf4j @Component +@RequiredArgsConstructor +@Slf4j public class KafkaProducerImpl implements KafkaProducer { private final KafkaTemplate kafkaTemplate; - public KafkaProducerImpl(KafkaTemplate kafkaTemplate) { - this.kafkaTemplate = kafkaTemplate; - } - @Override public void send(String topicName, K key, V message, ListenableFutureCallback> callback) { - log.info("Sending message={} to topic={}", message, topicName); - try { - ListenableFuture> kafkaResultFuture = kafkaTemplate.send(topicName, key, message); - kafkaResultFuture.addCallback(callback); - } catch (KafkaException e) { - log.error("Error on kafka producer with key: {}, message: {} and exception: {}", key, message, - e.getMessage()); - throw new KafkaProducerException("Error on kafka producer with key: " + key + " and message: " + message); - } + log.info("Sending message to topic: {}, also message {}", topicName,message); + kafkaTemplate.send(topicName, key, message) + .addCallback(new ListenableFutureCallback<>() { + @Override + public void onFailure(Throwable ex) { + log.error("Error sending message to topic: {}, also message {}", topicName, message, ex); + callback.onFailure(ex); + } + + @Override + public void onSuccess(SendResult result) { + log.info("Message sent to topic: {}, also message {}", topicName, message); + callback.onSuccess(result); + } + }); } @PreDestroy - public void close() { - if (kafkaTemplate != null) { - log.info("Closing kafka producer!"); + public void destroy() { + log.info("KafkaProducerImpl is being destroyed"); + if (Objects.nonNull(kafkaTemplate)) { kafkaTemplate.destroy(); } } + + } diff --git a/order-service/order-container/src/main/resources/application.yml b/order-service/order-container/src/main/resources/application.yml index 07abc06..fc6e593 100644 --- a/order-service/order-container/src/main/resources/application.yml +++ b/order-service/order-container/src/main/resources/application.yml @@ -5,10 +5,10 @@ logging: com.food.order.system : DEBUG order-service: - payment-request-topic-name: payment-request - payment-response-topic-name: payment-response - restaurant-approval-request-topic-name: restaurant-approval-request - restaurant-approval-response-topic-name: restaurant-approval-response + payment-request-topic-name: payment-request-value + payment-response-topic-name: payment-response-value + restaurant-approval-request-topic-name: restaurant-approval-request-value + restaurant-approval-response-topic-name: restaurant-approval-response-value spring: jpa: diff --git a/order-service/order-domain/order-application-service/src/main/java/com/food/order/sysyem/OrderCreateHelper.java b/order-service/order-domain/order-application-service/src/main/java/com/food/order/sysyem/OrderCreateHelper.java index 779c885..53a3840 100644 --- a/order-service/order-domain/order-application-service/src/main/java/com/food/order/sysyem/OrderCreateHelper.java +++ b/order-service/order-domain/order-application-service/src/main/java/com/food/order/sysyem/OrderCreateHelper.java @@ -1,6 +1,7 @@ package com.food.order.sysyem; import com.food.order.sysyem.dto.create.CreateOrderCommand; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; import com.food.order.sysyem.mapper.OrderDataMapper; import com.food.order.sysyem.ports.output.repository.CustomerRepository; import com.food.order.sysyem.ports.output.repository.OrderRepository; @@ -27,6 +28,7 @@ public class OrderCreateHelper { private final CustomerRepository customerRepository; private final RestaurantRepository restaurantRepository; private final OrderDataMapper orderDataMapper; + private final DomainEventPublisher publisher; @Transactional public OrderCreatedEvent persistOrder(CreateOrderCommand createOrderCommand) { @@ -34,7 +36,7 @@ public class OrderCreateHelper { checkCustomer(createOrderCommand.customerId()); Restaurant restaurant = checkRestaurant(createOrderCommand); var order = orderDataMapper.createOrderCommandToOrder(createOrderCommand); - var createdEventOrder = orderDomainService.validateAndInitiateOrder(order, restaurant); + var createdEventOrder = orderDomainService.validateAndInitiateOrder(order, restaurant,publisher); saveOrder(order); log.info("Created Order Event : {}", createdEventOrder); return createdEventOrder; diff --git a/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/event/OrderCancelledEvent.java b/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/event/OrderCancelledEvent.java index 6e8f7b5..7970c1e 100644 --- a/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/event/OrderCancelledEvent.java +++ b/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/event/OrderCancelledEvent.java @@ -1,12 +1,22 @@ package com.food.order.system.domain.event; import com.food.order.system.domain.entity.Order; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; import java.time.ZonedDateTime; public class OrderCancelledEvent extends OrderEvent { - public OrderCancelledEvent(Order order, ZonedDateTime utc) { + private final DomainEventPublisher publisher; + + + public OrderCancelledEvent(Order order, ZonedDateTime utc, DomainEventPublisher publisher) { super(order, utc); + this.publisher = publisher; + } + + @Override + public void fire() { + publisher.publish(this); } } diff --git a/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/event/OrderCreatedEvent.java b/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/event/OrderCreatedEvent.java index 620f5c1..b0f98da 100644 --- a/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/event/OrderCreatedEvent.java +++ b/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/event/OrderCreatedEvent.java @@ -1,11 +1,20 @@ package com.food.order.system.domain.event; import com.food.order.system.domain.entity.Order; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; import java.time.ZonedDateTime; public class OrderCreatedEvent extends OrderEvent { - public OrderCreatedEvent(Order order, ZonedDateTime createdAt) { + + private final DomainEventPublisher publisher; + public OrderCreatedEvent(Order order, ZonedDateTime createdAt, DomainEventPublisher publisher) { super(order, createdAt); + this.publisher = publisher; + } + + @Override + public void fire() { + publisher.publish(this); } } diff --git a/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/event/OrderPaidEvent.java b/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/event/OrderPaidEvent.java index 6467567..6dfaa2d 100644 --- a/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/event/OrderPaidEvent.java +++ b/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/event/OrderPaidEvent.java @@ -1,13 +1,21 @@ package com.food.order.system.domain.event; import com.food.order.system.domain.entity.Order; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; import java.time.ZonedDateTime; public class OrderPaidEvent extends OrderEvent { - public OrderPaidEvent(Order order, ZonedDateTime utc) { + private final DomainEventPublisher publisher; + + public OrderPaidEvent(Order order, ZonedDateTime utc, DomainEventPublisher publisher) { super(order, utc); + this.publisher = publisher; } + @Override + public void fire() { + publisher.publish(this); + } } diff --git a/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/service/OrderDomainService.java b/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/service/OrderDomainService.java index 6de2853..e514266 100644 --- a/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/service/OrderDomainService.java +++ b/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/service/OrderDomainService.java @@ -5,18 +5,19 @@ import com.food.order.system.domain.entity.Restaurant; import com.food.order.system.domain.event.OrderCancelledEvent; import com.food.order.system.domain.event.OrderCreatedEvent; import com.food.order.system.domain.event.OrderPaidEvent; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; import java.util.List; public interface OrderDomainService { - OrderCreatedEvent validateAndInitiateOrder(Order order, Restaurant restaurant); + OrderCreatedEvent validateAndInitiateOrder(Order order, Restaurant restaurant, DomainEventPublisher publisher); - OrderPaidEvent payOrder(Order order); + OrderPaidEvent payOrder(Order order,DomainEventPublisher publisher); void approve(Order order); - OrderCancelledEvent cancelOrderPayment(Order order, List failureMessages); + OrderCancelledEvent cancelOrderPayment(Order order, List failureMessages,DomainEventPublisher publisher); void cancelOrder(Order order, List failureMessages); diff --git a/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/service/impl/OrderDomainServiceImpl.java b/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/service/impl/OrderDomainServiceImpl.java index 0f9e55c..418d245 100644 --- a/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/service/impl/OrderDomainServiceImpl.java +++ b/order-service/order-domain/order-core-domain/src/main/java/com/food/order/system/domain/service/impl/OrderDomainServiceImpl.java @@ -7,6 +7,7 @@ import com.food.order.system.domain.event.OrderCreatedEvent; import com.food.order.system.domain.event.OrderPaidEvent; import com.food.order.system.domain.exception.OrderDomainException; import com.food.order.system.domain.service.OrderDomainService; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; import lombok.extern.slf4j.Slf4j; import java.time.ZoneId; @@ -19,13 +20,14 @@ public class OrderDomainServiceImpl implements OrderDomainService { private static final String UTC = "UTC"; @Override - public OrderCreatedEvent validateAndInitiateOrder(Order order, Restaurant restaurant) { + public OrderCreatedEvent validateAndInitiateOrder(Order order, Restaurant restaurant, + DomainEventPublisher publisher) { validateRestaurant(restaurant); setOrderProductInformation(order,restaurant); order.validateOrder(); order.initializeOrder(); log.info("Order with id {} initialize successfully", order.getId().getValue()); - return new OrderCreatedEvent(order, ZonedDateTime.now(ZoneId.of(UTC))); + return new OrderCreatedEvent(order, ZonedDateTime.now(ZoneId.of(UTC)),publisher); } private void setOrderProductInformation(Order order, Restaurant restaurant) { @@ -46,10 +48,10 @@ public class OrderDomainServiceImpl implements OrderDomainService { } @Override - public OrderPaidEvent payOrder(Order order) { + public OrderPaidEvent payOrder(Order order, DomainEventPublisher publisher) { order.pay(); log.info("Order with id {} paid successfully", order.getId().getValue()); - return new OrderPaidEvent(order, ZonedDateTime.now(ZoneId.of(UTC))); + return new OrderPaidEvent(order, ZonedDateTime.now(ZoneId.of(UTC)),publisher); } @Override @@ -59,10 +61,11 @@ public class OrderDomainServiceImpl implements OrderDomainService { } @Override - public OrderCancelledEvent cancelOrderPayment(Order order, List failureMessages) { + public OrderCancelledEvent cancelOrderPayment(Order order, List failureMessages, + DomainEventPublisher publisher) { order.initCancel(failureMessages); log.info("Order with id {} cancelled successfully", order.getId().getValue()); - return new OrderCancelledEvent(order, ZonedDateTime.now(ZoneId.of(UTC))); + return new OrderCancelledEvent(order, ZonedDateTime.now(ZoneId.of(UTC)),publisher); } @Override diff --git a/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/listener/kafka/PaymentResponseKafkaListener.java b/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/listener/kafka/PaymentResponseKafkaListener.java index db34d0b..d00dea3 100644 --- a/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/listener/kafka/PaymentResponseKafkaListener.java +++ b/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/listener/kafka/PaymentResponseKafkaListener.java @@ -1,10 +1,10 @@ package com.food.order.system.order.messaging.listener.kafka; -import com.food.order.sysyem.ports.input.message.listener.payment.PaymentResponseMessageListener; import com.food.order.system.kafka.consumer.KafkaConsumer; -import com.food.order.system.order.messaging.mapper.OrderMessagingDataMapper; import com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel; import com.food.order.system.kafka.order.avro.model.PaymentStatus; +import com.food.order.system.order.messaging.mapper.OrderMessagingDataMapper; +import com.food.order.sysyem.ports.input.message.listener.payment.PaymentResponseMessageListener; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.kafka.annotation.KafkaListener; diff --git a/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/listener/kafka/RestaurantApprovalResponseKafkaListener.java b/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/listener/kafka/RestaurantApprovalResponseKafkaListener.java index 8243609..1448cca 100644 --- a/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/listener/kafka/RestaurantApprovalResponseKafkaListener.java +++ b/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/listener/kafka/RestaurantApprovalResponseKafkaListener.java @@ -1,10 +1,10 @@ package com.food.order.system.order.messaging.listener.kafka; -import com.food.order.sysyem.ports.input.message.listener.restaurantapproval.RestaurantApprovalResponseMessageListener; import com.food.order.system.kafka.consumer.KafkaConsumer; -import com.food.order.system.order.messaging.mapper.OrderMessagingDataMapper; import com.food.order.system.kafka.order.avro.model.OrderApprovalStatus; import com.food.order.system.kafka.order.avro.model.RestaurantApprovalResponseAvroModel; +import com.food.order.system.order.messaging.mapper.OrderMessagingDataMapper; +import com.food.order.sysyem.ports.input.message.listener.restaurantapproval.RestaurantApprovalResponseMessageListener; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.kafka.annotation.KafkaListener; diff --git a/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/CancelOrderKafkaMessagePublisher.java b/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/CancelOrderKafkaMessagePublisher.java index 6cf586a..8d6894d 100644 --- a/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/CancelOrderKafkaMessagePublisher.java +++ b/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/CancelOrderKafkaMessagePublisher.java @@ -1,11 +1,12 @@ package com.food.order.system.order.messaging.publisher.kafka; import com.food.order.system.domain.event.OrderCancelledEvent; +import com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel; +import com.food.order.system.kafka.producer.KafkaMessageHelper; import com.food.order.system.kafka.producer.service.KafkaProducer; import com.food.order.system.order.messaging.mapper.OrderMessagingDataMapper; import com.food.order.sysyem.config.OrderServiceConfigData; import com.food.order.sysyem.ports.output.message.publisher.payment.OrderCancelledPaymentRequestMessagePublisher; -import com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -19,7 +20,7 @@ public class CancelOrderKafkaMessagePublisher implements OrderCancelledPaymentRe private final OrderServiceConfigData configData; private final KafkaProducer kafkaProducer; - private final OrderKafkaMessageHelper orderKafkaMessageHelper; + private final KafkaMessageHelper kafkaMessageHelper; @Override public void publish(OrderCancelledEvent event) { @@ -35,7 +36,7 @@ public class CancelOrderKafkaMessagePublisher implements OrderCancelledPaymentRe configData.getPaymentRequestTopicName(), orderId, paymentRequestAvroModel, - orderKafkaMessageHelper.getKafkaCallBack(configData.getPaymentRequestTopicName() + kafkaMessageHelper.getKafkaCallBack(configData.getPaymentRequestTopicName() ,paymentRequestAvroModel, orderId, "PaymentRequestAvroModel")); diff --git a/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/CreateOrderKafkaMessagePublisher.java b/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/CreateOrderKafkaMessagePublisher.java index a7f800c..5ee687c 100644 --- a/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/CreateOrderKafkaMessagePublisher.java +++ b/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/CreateOrderKafkaMessagePublisher.java @@ -2,11 +2,12 @@ package com.food.order.system.order.messaging.publisher.kafka; import com.food.order.system.domain.event.OrderCreatedEvent; +import com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel; +import com.food.order.system.kafka.producer.KafkaMessageHelper; import com.food.order.system.kafka.producer.service.KafkaProducer; import com.food.order.system.order.messaging.mapper.OrderMessagingDataMapper; import com.food.order.sysyem.config.OrderServiceConfigData; import com.food.order.sysyem.ports.output.message.publisher.payment.OrderCreatedPaymentRequestMessagePublisher; -import com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -19,7 +20,7 @@ public class CreateOrderKafkaMessagePublisher implements OrderCreatedPaymentRequ private final OrderMessagingDataMapper orderMessagingDataMapper; private final OrderServiceConfigData configData; private final KafkaProducer kafkaProducer; - private final OrderKafkaMessageHelper orderKafkaMessageHelper; + private final KafkaMessageHelper kafkaMessageHelper; @Override @@ -35,7 +36,7 @@ public class CreateOrderKafkaMessagePublisher implements OrderCreatedPaymentRequ configData.getPaymentRequestTopicName(), orderId, paymentRequestAvroModel, - orderKafkaMessageHelper.getKafkaCallBack(configData.getPaymentRequestTopicName(), + kafkaMessageHelper.getKafkaCallBack(configData.getPaymentRequestTopicName(), paymentRequestAvroModel, orderId, "PaymentRequestAvroModel")); diff --git a/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/PayOrderKafkaMessagePublisher.java b/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/PayOrderKafkaMessagePublisher.java index 25e7565..bf5c71b 100644 --- a/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/PayOrderKafkaMessagePublisher.java +++ b/order-service/order-messaging/src/main/java/com/food/order/system/order/messaging/publisher/kafka/PayOrderKafkaMessagePublisher.java @@ -1,11 +1,12 @@ package com.food.order.system.order.messaging.publisher.kafka; -import com.food.order.sysyem.config.OrderServiceConfigData; -import com.food.order.sysyem.ports.output.message.publisher.restaurantapproval.OrderPaidRestaurantRequestMessagePublisher; import com.food.order.system.domain.event.OrderPaidEvent; +import com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel; +import com.food.order.system.kafka.producer.KafkaMessageHelper; import com.food.order.system.kafka.producer.service.KafkaProducer; import com.food.order.system.order.messaging.mapper.OrderMessagingDataMapper; -import com.food.order.system.kafka.order.avro.model.RestaurantApprovalRequestAvroModel; +import com.food.order.sysyem.config.OrderServiceConfigData; +import com.food.order.sysyem.ports.output.message.publisher.restaurantapproval.OrderPaidRestaurantRequestMessagePublisher; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -18,7 +19,7 @@ public class PayOrderKafkaMessagePublisher implements OrderPaidRestaurantRequest private final OrderMessagingDataMapper orderMessagingDataMapper; private final OrderServiceConfigData configData; private final KafkaProducer kafkaProducer; - private final OrderKafkaMessageHelper orderKafkaMessageHelper; + private final KafkaMessageHelper kafkaMessageHelper; @Override public void publish(OrderPaidEvent event) { @@ -32,7 +33,7 @@ public class PayOrderKafkaMessagePublisher implements OrderPaidRestaurantRequest kafkaProducer.send(configData.getRestaurantApprovalRequestTopicName(), orderId, message, - orderKafkaMessageHelper.getKafkaCallBack(configData.getRestaurantApprovalRequestTopicName(), message, + kafkaMessageHelper.getKafkaCallBack(configData.getRestaurantApprovalRequestTopicName(), message, orderId, "RestaurantApprovalRequestAvroModel")); diff --git a/payment-service/payment-container/pom.xml b/payment-service/payment-container/pom.xml new file mode 100644 index 0000000..5fd21a3 --- /dev/null +++ b/payment-service/payment-container/pom.xml @@ -0,0 +1,64 @@ + + + + payment-service + com.food.order + 1.0-SNAPSHOT + + 4.0.0 + + payment-container + + + + com.food.order + payment-domain-core + + + com.food.order + payment-application-service + + + + com.food.order + payment-dataaccess + + + + com.food.order + payment-messaging + + + + org.springframework.boot + spring-boot-starter + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + ${project.groupId}/payment.service:${project.version} + + + + + install + + build-image + + + + + + + + \ No newline at end of file diff --git a/payment-service/payment-container/src/main/java/com/food/order/system/payment/service/domain/BeanConfig.java b/payment-service/payment-container/src/main/java/com/food/order/system/payment/service/domain/BeanConfig.java new file mode 100644 index 0000000..b489c73 --- /dev/null +++ b/payment-service/payment-container/src/main/java/com/food/order/system/payment/service/domain/BeanConfig.java @@ -0,0 +1,14 @@ +package com.food.order.system.payment.service.domain; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class BeanConfig { + + @Bean + public PaymentDomainService paymentDomainService() { + return new PaymentDomainServiceImpl(); + } + +} diff --git a/payment-service/payment-container/src/main/java/com/food/order/system/payment/service/domain/PaymentServiceApplication.java b/payment-service/payment-container/src/main/java/com/food/order/system/payment/service/domain/PaymentServiceApplication.java new file mode 100644 index 0000000..a65d3c1 --- /dev/null +++ b/payment-service/payment-container/src/main/java/com/food/order/system/payment/service/domain/PaymentServiceApplication.java @@ -0,0 +1,16 @@ +package com.food.order.system.payment.service.domain; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +@EnableJpaRepositories(basePackages = "com.food.order.system.payment.data.access") +@EntityScan(basePackages = "com.food.order.system.payment.data.access") +@SpringBootApplication(scanBasePackages = "com.food.order") +public class PaymentServiceApplication { + public static void main(String[] args) { + SpringApplication.run(PaymentServiceApplication.class, args); + } + +} diff --git a/payment-service/payment-container/src/main/resources/application.yml b/payment-service/payment-container/src/main/resources/application.yml new file mode 100644 index 0000000..3521f3c --- /dev/null +++ b/payment-service/payment-container/src/main/resources/application.yml @@ -0,0 +1,64 @@ +server: + port: 8182 + +logging: + level: + com.food.order.system: DEBUG + +payment-service: + payment-request-topic-name: payment-request-value + payment-response-topic-name: payment-response-value + +spring: + jpa: + open-in-view: false + show-sql: true + database-platform: org.hibernate.dialect.PostgreSQL9Dialect + properties: + hibernate: + dialect: org.hibernate.dialect.PostgreSQL9Dialect + datasource: + url: jdbc:postgresql://localhost:5432/postgres?currentSchema=payment&binaryTransfer=true&reWriteBatchedInserts=true&stringtype=unspecified + username: postgres + password: postgres + driver-class-name: org.postgresql.Driver + platform: postgres + schema: classpath:init-schema.sql + data: classpath:init-data.sql + initialization-mode: always + +kafka-config: + bootstrap-servers: localhost:19092, localhost:29092, localhost:39092 + schema-registry-url-key: schema.registry.url + schema-registry-url: http://localhost:8081 + num-of-partitions: 3 + replication-factor: 3 + +kafka-producer-config: + key-serializer-class: org.apache.kafka.common.serialization.StringSerializer + value-serializer-class: io.confluent.kafka.serializers.KafkaAvroSerializer + compression-type: snappy + acks: all + batch-size: 16384 + batch-size-boost-factor: 100 + linger-ms: 5 + request-timeout-ms: 60000 + retry-count: 5 + +kafka-consumer-config: + key-deserializer: org.apache.kafka.common.serialization.StringDeserializer + value-deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer + payment-consumer-group-id: payment-topic-consumer + auto-offset-reset: earliest + specific-avro-reader-key: specific.avro.reader + specific-avro-reader: true + batch-listener: true + auto-startup: true + concurrency-level: 3 + session-timeout-ms: 10000 + heartbeat-interval-ms: 3000 + max-poll-interval-ms: 300000 + max-poll-records: 500 + max-partition-fetch-bytes-default: 1048576 + max-partition-fetch-bytes-boost-factor: 1 + poll-timeout-ms: 150 \ No newline at end of file diff --git a/payment-service/payment-container/src/main/resources/init-data.sql b/payment-service/payment-container/src/main/resources/init-data.sql new file mode 100644 index 0000000..734cf36 --- /dev/null +++ b/payment-service/payment-container/src/main/resources/init-data.sql @@ -0,0 +1,17 @@ +INSERT INTO payment.credit_entry(id, customer_id, total_credit_amount) + VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb21', 'd215b5f8-0249-4dc5-89a3-51fd148cfb41', 500.00); +INSERT INTO payment.credit_history(id, customer_id, amount, type) + VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb23', 'd215b5f8-0249-4dc5-89a3-51fd148cfb41', 100.00, 'CREDIT'); +INSERT INTO payment.credit_history(id, customer_id, amount, type) + VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb24', 'd215b5f8-0249-4dc5-89a3-51fd148cfb41', 600.00, 'CREDIT'); +INSERT INTO payment.credit_history(id, customer_id, amount, type) + VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb25', 'd215b5f8-0249-4dc5-89a3-51fd148cfb41', 200.00, 'DEBIT'); + + +INSERT INTO payment.credit_entry(id, customer_id, total_credit_amount) + VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb22', 'd215b5f8-0249-4dc5-89a3-51fd148cfb43', 100.00); +INSERT INTO payment.credit_history(id, customer_id, amount, type) + VALUES ('d215b5f8-0249-4dc5-89a3-51fd148cfb26', 'd215b5f8-0249-4dc5-89a3-51fd148cfb43', 100.00, 'CREDIT'); + + + diff --git a/payment-service/payment-container/src/main/resources/init-schema.sql b/payment-service/payment-container/src/main/resources/init-schema.sql new file mode 100644 index 0000000..b6c34f6 --- /dev/null +++ b/payment-service/payment-container/src/main/resources/init-schema.sql @@ -0,0 +1,47 @@ +DROP SCHEMA IF EXISTS payment CASCADE; + +CREATE SCHEMA payment; + +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +DROP TYPE IF EXISTS payment_status; + +CREATE TYPE payment_status AS ENUM ('COMPLETED', 'CANCELLED', 'FAILED'); + +DROP TABLE IF EXISTS "payment".payments CASCADE; + +CREATE TABLE "payment".payments +( + id uuid NOT NULL, + customer_id uuid NOT NULL, + order_id uuid NOT NULL, + price numeric(10,2) NOT NULL, + created_at TIMESTAMP WITH TIME ZONE NOT NULL, + status payment_status NOT NULL, + CONSTRAINT payments_pkey PRIMARY KEY (id) +); + +DROP TABLE IF EXISTS "payment".credit_entry CASCADE; + +CREATE TABLE "payment".credit_entry +( + id uuid NOT NULL, + customer_id uuid NOT NULL, + total_credit_amount numeric(10,2) NOT NULL, + CONSTRAINT credit_entry_pkey PRIMARY KEY (id) +); + +DROP TYPE IF EXISTS transaction_type; + +CREATE TYPE transaction_type AS ENUM ('DEBIT', 'CREDIT'); + +DROP TABLE IF EXISTS "payment".credit_history CASCADE; + +CREATE TABLE "payment".credit_history +( + id uuid NOT NULL, + customer_id uuid NOT NULL, + amount numeric(10,2) NOT NULL, + type transaction_type NOT NULL, + CONSTRAINT credit_history_pkey PRIMARY KEY (id) +); \ No newline at end of file diff --git a/payment-service/payment-dataaccess/pom.xml b/payment-service/payment-dataaccess/pom.xml new file mode 100644 index 0000000..021c372 --- /dev/null +++ b/payment-service/payment-dataaccess/pom.xml @@ -0,0 +1,34 @@ + + + + payment-service + com.food.order + 1.0-SNAPSHOT + + 4.0.0 + + payment-dataaccess + + + + + com.food.order + payment-application-service + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + + org.postgresql + postgresql + + + + + \ No newline at end of file diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/adapter/CreditEntryRepositoryImpl.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/adapter/CreditEntryRepositoryImpl.java new file mode 100644 index 0000000..a04c5a9 --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/adapter/CreditEntryRepositoryImpl.java @@ -0,0 +1,38 @@ +package com.food.order.system.payment.data.access.creditentry.adapter; + + +import com.food.order.system.payment.application.service.ports.output.repository.CreditEntryRepository; +import com.food.order.system.payment.data.access.creditentry.mapper.CreditEntryDataAccessMapper; +import com.food.order.system.payment.data.access.creditentry.repository.CreditEntryJpaRepository; +import com.food.order.system.payment.service.domain.entity.CreditEntry; +import com.food.order.sysyem.valueobject.CustomerId; +import org.springframework.stereotype.Component; + +import java.util.Optional; + +@Component +public class CreditEntryRepositoryImpl implements CreditEntryRepository { + + private final CreditEntryJpaRepository creditEntryJpaRepository; + private final CreditEntryDataAccessMapper creditEntryDataAccessMapper; + + public CreditEntryRepositoryImpl(CreditEntryJpaRepository creditEntryJpaRepository, + CreditEntryDataAccessMapper creditEntryDataAccessMapper) { + this.creditEntryJpaRepository = creditEntryJpaRepository; + this.creditEntryDataAccessMapper = creditEntryDataAccessMapper; + } + + @Override + public CreditEntry save(CreditEntry creditEntry) { + return creditEntryDataAccessMapper + .creditEntryEntityToCreditEntry(creditEntryJpaRepository + .save(creditEntryDataAccessMapper.creditEntryToCreditEntryEntity(creditEntry))); + } + + @Override + public Optional findByCustomerId(CustomerId customerId) { + return creditEntryJpaRepository + .findByCustomerId(customerId.getValue()) + .map(creditEntryDataAccessMapper::creditEntryEntityToCreditEntry); + } +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/entity/CreditEntryEntity.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/entity/CreditEntryEntity.java new file mode 100644 index 0000000..da93927 --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/entity/CreditEntryEntity.java @@ -0,0 +1,38 @@ +package com.food.order.system.payment.data.access.creditentry.entity; + +import lombok.*; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.math.BigDecimal; +import java.util.Objects; +import java.util.UUID; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "credit_entry") +@Entity +public class CreditEntryEntity { + + @Id + private UUID id; + private UUID customerId; + private BigDecimal totalCreditAmount; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CreditEntryEntity that = (CreditEntryEntity) o; + return id.equals(that.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/exception/CreditEntryDataaccessException.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/exception/CreditEntryDataaccessException.java new file mode 100644 index 0000000..b8e70f4 --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/exception/CreditEntryDataaccessException.java @@ -0,0 +1,8 @@ +package com.food.order.system.payment.data.access.creditentry.exception; + +public class CreditEntryDataaccessException extends RuntimeException { + + public CreditEntryDataaccessException(String message) { + super(message); + } +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/mapper/CreditEntryDataAccessMapper.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/mapper/CreditEntryDataAccessMapper.java new file mode 100644 index 0000000..ff37152 --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/mapper/CreditEntryDataAccessMapper.java @@ -0,0 +1,30 @@ +package com.food.order.system.payment.data.access.creditentry.mapper; + + +import com.food.order.system.payment.data.access.creditentry.entity.CreditEntryEntity; +import com.food.order.system.payment.service.domain.entity.CreditEntry; +import com.food.order.system.payment.service.domain.valueobject.CreditEntryId; +import com.food.order.sysyem.valueobject.CustomerId; +import com.food.order.sysyem.valueobject.Money; +import org.springframework.stereotype.Component; + +@Component +public class CreditEntryDataAccessMapper { + + public CreditEntry creditEntryEntityToCreditEntry(CreditEntryEntity creditEntryEntity) { + return CreditEntry.builder() + .id(new CreditEntryId(creditEntryEntity.getId())) + .customerId(new CustomerId(creditEntryEntity.getCustomerId())) + .totalCreditAmount(new Money(creditEntryEntity.getTotalCreditAmount())) + .build(); + } + + public CreditEntryEntity creditEntryToCreditEntryEntity(CreditEntry creditEntry) { + return CreditEntryEntity.builder() + .id(creditEntry.getId().getValue()) + .customerId(creditEntry.getCustomerId().getValue()) + .totalCreditAmount(creditEntry.getTotalCreditAmount().getAmount()) + .build(); + } + +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/repository/CreditEntryJpaRepository.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/repository/CreditEntryJpaRepository.java new file mode 100644 index 0000000..8f1317f --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/creditentry/repository/CreditEntryJpaRepository.java @@ -0,0 +1,16 @@ +package com.food.order.system.payment.data.access.creditentry.repository; + +import com.food.order.system.payment.data.access.creditentry.entity.CreditEntryEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; +import java.util.UUID; + +@Repository +public interface CreditEntryJpaRepository extends JpaRepository { + + Optional findByCustomerId(UUID customerId); + + +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/adapter/CreditHistoryRepositoryImpl.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/adapter/CreditHistoryRepositoryImpl.java new file mode 100644 index 0000000..283b7af --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/adapter/CreditHistoryRepositoryImpl.java @@ -0,0 +1,41 @@ +package com.food.order.system.payment.data.access.credithistory.adapter; + + +import com.food.order.system.payment.application.service.ports.output.repository.CreditHistoryRepository; +import com.food.order.system.payment.data.access.credithistory.mapper.CreditHistoryDataAccessMapper; +import com.food.order.system.payment.data.access.credithistory.repository.CreditHistoryJpaRepository; +import com.food.order.system.payment.service.domain.entity.CreditHistory; +import com.food.order.sysyem.valueobject.CustomerId; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class CreditHistoryRepositoryImpl implements CreditHistoryRepository { + + private final CreditHistoryJpaRepository creditHistoryJpaRepository; + private final CreditHistoryDataAccessMapper creditHistoryDataAccessMapper; + + public CreditHistoryRepositoryImpl(CreditHistoryJpaRepository creditHistoryJpaRepository, + CreditHistoryDataAccessMapper creditHistoryDataAccessMapper) { + this.creditHistoryJpaRepository = creditHistoryJpaRepository; + this.creditHistoryDataAccessMapper = creditHistoryDataAccessMapper; + } + + @Override + public CreditHistory save(CreditHistory creditHistory) { + return creditHistoryDataAccessMapper.creditHistoryEntityToCreditHistory(creditHistoryJpaRepository + .save(creditHistoryDataAccessMapper.creditHistoryToCreditHistoryEntity(creditHistory))); + } + + @Override + public Optional> findByCustomerId(CustomerId customerId) { + return creditHistoryJpaRepository.findByCustomerId(customerId.getValue()) + .map(creditHistoryList -> + creditHistoryList.stream() + .map(creditHistoryDataAccessMapper::creditHistoryEntityToCreditHistory) + .toList()); + + } +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/entity/CreditHistoryEntity.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/entity/CreditHistoryEntity.java new file mode 100644 index 0000000..fff4bc2 --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/entity/CreditHistoryEntity.java @@ -0,0 +1,39 @@ +package com.food.order.system.payment.data.access.credithistory.entity; + +import com.food.order.system.payment.service.domain.valueobject.TransactionType; +import lombok.*; + +import javax.persistence.*; +import java.math.BigDecimal; +import java.util.Objects; +import java.util.UUID; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "credit_history") +@Entity +public class CreditHistoryEntity { + + @Id + private UUID id; + private UUID customerId; + private BigDecimal amount; + @Enumerated(EnumType.STRING) + private TransactionType type; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + CreditHistoryEntity that = (CreditHistoryEntity) o; + return id.equals(that.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/exception/CreditHistoryDataaccessException.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/exception/CreditHistoryDataaccessException.java new file mode 100644 index 0000000..0db46e7 --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/exception/CreditHistoryDataaccessException.java @@ -0,0 +1,8 @@ +package com.food.order.system.payment.data.access.credithistory.exception; + +public class CreditHistoryDataaccessException extends RuntimeException { + + public CreditHistoryDataaccessException(String message) { + super(message); + } +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/mapper/CreditHistoryDataAccessMapper.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/mapper/CreditHistoryDataAccessMapper.java new file mode 100644 index 0000000..001218f --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/mapper/CreditHistoryDataAccessMapper.java @@ -0,0 +1,32 @@ +package com.food.order.system.payment.data.access.credithistory.mapper; + + +import com.food.order.system.payment.data.access.credithistory.entity.CreditHistoryEntity; +import com.food.order.system.payment.service.domain.entity.CreditHistory; +import com.food.order.system.payment.service.domain.valueobject.CreditHistoryId; +import com.food.order.sysyem.valueobject.CustomerId; +import com.food.order.sysyem.valueobject.Money; +import org.springframework.stereotype.Component; + +@Component +public class CreditHistoryDataAccessMapper { + + public CreditHistory creditHistoryEntityToCreditHistory(CreditHistoryEntity creditHistoryEntity) { + return CreditHistory.builder() + .id(new CreditHistoryId(creditHistoryEntity.getId())) + .customerId(new CustomerId(creditHistoryEntity.getCustomerId())) + .amount(new Money(creditHistoryEntity.getAmount())) + .transactionType(creditHistoryEntity.getType()) + .build(); + } + + public CreditHistoryEntity creditHistoryToCreditHistoryEntity(CreditHistory creditHistory) { + return CreditHistoryEntity.builder() + .id(creditHistory.getId().getValue()) + .customerId(creditHistory.getCustomerId().getValue()) + .amount(creditHistory.getAmount().getAmount()) + .type(creditHistory.getTransactionType()) + .build(); + } + +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/repository/CreditHistoryJpaRepository.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/repository/CreditHistoryJpaRepository.java new file mode 100644 index 0000000..fb980d6 --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/credithistory/repository/CreditHistoryJpaRepository.java @@ -0,0 +1,17 @@ +package com.food.order.system.payment.data.access.credithistory.repository; + +import com.food.order.system.payment.data.access.credithistory.entity.CreditHistoryEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Repository +public interface CreditHistoryJpaRepository extends JpaRepository { + + Optional> findByCustomerId(UUID customerId); + + +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/adapter/PaymentRepositoryImpl.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/adapter/PaymentRepositoryImpl.java new file mode 100644 index 0000000..7e06623 --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/adapter/PaymentRepositoryImpl.java @@ -0,0 +1,37 @@ +package com.food.order.system.payment.data.access.payment.adapter; + + +import com.food.order.system.payment.application.service.ports.output.repository.PaymentRepository; +import com.food.order.system.payment.data.access.payment.mapper.PaymentDataAccessMapper; +import com.food.order.system.payment.data.access.payment.repository.PaymentJpaRepository; +import com.food.order.system.payment.service.domain.entity.Payment; +import org.springframework.stereotype.Component; + +import java.util.Optional; +import java.util.UUID; + +@Component +public class PaymentRepositoryImpl implements PaymentRepository { + + private final PaymentJpaRepository paymentJpaRepository; + private final PaymentDataAccessMapper paymentDataAccessMapper; + + public PaymentRepositoryImpl(PaymentJpaRepository paymentJpaRepository, + PaymentDataAccessMapper paymentDataAccessMapper) { + this.paymentJpaRepository = paymentJpaRepository; + this.paymentDataAccessMapper = paymentDataAccessMapper; + } + + @Override + public Payment save(Payment payment) { + return paymentDataAccessMapper + .paymentEntityToPayment(paymentJpaRepository + .save(paymentDataAccessMapper.paymentToPaymentEntity(payment))); + } + + @Override + public Optional findByOrderId(UUID orderId) { + return paymentJpaRepository.findByOrderId(orderId) + .map(paymentDataAccessMapper::paymentEntityToPayment); + } +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/entity/PaymentEntity.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/entity/PaymentEntity.java new file mode 100644 index 0000000..b733b68 --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/entity/PaymentEntity.java @@ -0,0 +1,42 @@ +package com.food.order.system.payment.data.access.payment.entity; + +import com.food.order.sysyem.valueobject.PaymentStatus; +import lombok.*; + +import javax.persistence.*; +import java.math.BigDecimal; +import java.time.ZonedDateTime; +import java.util.Objects; +import java.util.UUID; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "payments") +@Entity +public class PaymentEntity { + + @Id + private UUID id; + private UUID customerId; + private UUID orderId; + private BigDecimal price; + @Enumerated(EnumType.STRING) + private PaymentStatus status; + private ZonedDateTime createdAt; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PaymentEntity that = (PaymentEntity) o; + return id.equals(that.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/exception/PaymentDataaccessException.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/exception/PaymentDataaccessException.java new file mode 100644 index 0000000..baf23f8 --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/exception/PaymentDataaccessException.java @@ -0,0 +1,8 @@ +package com.food.order.system.payment.data.access.payment.exception; + +public class PaymentDataaccessException extends RuntimeException { + + public PaymentDataaccessException(String message) { + super(message); + } +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/mapper/PaymentDataAccessMapper.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/mapper/PaymentDataAccessMapper.java new file mode 100644 index 0000000..b1e7ac7 --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/mapper/PaymentDataAccessMapper.java @@ -0,0 +1,36 @@ +package com.food.order.system.payment.data.access.payment.mapper; + + +import com.food.order.system.payment.data.access.payment.entity.PaymentEntity; +import com.food.order.system.payment.service.domain.entity.Payment; +import com.food.order.system.payment.service.domain.valueobject.PaymentId; +import com.food.order.sysyem.valueobject.CustomerId; +import com.food.order.sysyem.valueobject.Money; +import com.food.order.sysyem.valueobject.OrderId; +import org.springframework.stereotype.Component; + +@Component +public class PaymentDataAccessMapper { + + public PaymentEntity paymentToPaymentEntity(Payment payment) { + return PaymentEntity.builder() + .id(payment.getId().getValue()) + .customerId(payment.getCustomerId().getValue()) + .orderId(payment.getOrderId().getValue()) + .price(payment.getPrice().getAmount()) + .status(payment.getStatus()) + .createdAt(payment.getCreatedAt()) + .build(); + } + + public Payment paymentEntityToPayment(PaymentEntity paymentEntity) { + return Payment.builder() + .id(new PaymentId(paymentEntity.getId())) + .customerId(new CustomerId(paymentEntity.getCustomerId())) + .orderId(new OrderId(paymentEntity.getOrderId())) + .price(new Money(paymentEntity.getPrice())) + .createdAt(paymentEntity.getCreatedAt()) + .build(); + } + +} diff --git a/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/repository/PaymentJpaRepository.java b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/repository/PaymentJpaRepository.java new file mode 100644 index 0000000..d651b9e --- /dev/null +++ b/payment-service/payment-dataaccess/src/main/java/com/food/order/system/payment/data/access/payment/repository/PaymentJpaRepository.java @@ -0,0 +1,16 @@ +package com.food.order.system.payment.data.access.payment.repository; + +import com.food.order.system.payment.data.access.payment.entity.PaymentEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; +import java.util.UUID; + +@Repository +public interface PaymentJpaRepository extends JpaRepository { + + Optional findByOrderId(UUID orderId); + + +} diff --git a/payment-service/payment-domain/payment-application-service/pom.xml b/payment-service/payment-domain/payment-application-service/pom.xml new file mode 100644 index 0000000..ea2f151 --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/pom.xml @@ -0,0 +1,45 @@ + + + + payment-domain + com.food.order + 1.0-SNAPSHOT + + 4.0.0 + + payment-application-service + + + + + com.food.order + payment-domain + + + + com.food.order + common-domain + + + + org.springframework.boot + spring-boot-starter-validation + + + + org.springframework + spring-tx + + + com.food.order + payment-domain-core + 1.0-SNAPSHOT + compile + + + + + + \ No newline at end of file diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/PaymentRequestHelper.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/PaymentRequestHelper.java new file mode 100644 index 0000000..0ba13d1 --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/PaymentRequestHelper.java @@ -0,0 +1,90 @@ +package com.food.order.system.payment.application.service; + +import com.food.order.system.payment.application.service.dto.PaymentRequest; +import com.food.order.system.payment.application.service.exception.PaymentApplicationServiceException; +import com.food.order.system.payment.application.service.mapper.PaymentDataMapper; +import com.food.order.system.payment.application.service.ports.output.repository.CreditEntryRepository; +import com.food.order.system.payment.application.service.ports.output.repository.CreditHistoryRepository; +import com.food.order.system.payment.application.service.ports.output.repository.PaymentRepository; +import com.food.order.system.payment.service.domain.PaymentDomainService; +import com.food.order.system.payment.service.domain.entity.CreditEntry; +import com.food.order.system.payment.service.domain.entity.CreditHistory; +import com.food.order.system.payment.service.domain.entity.Payment; +import com.food.order.system.payment.service.domain.event.PaymentCancelledEvent; +import com.food.order.system.payment.service.domain.event.PaymentCompletedEvent; +import com.food.order.system.payment.service.domain.event.PaymentEvent; +import com.food.order.system.payment.service.domain.event.PaymentFailedEvent; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; +import com.food.order.sysyem.valueobject.CustomerId; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +@Component +@Slf4j +@RequiredArgsConstructor +public class PaymentRequestHelper { + private final PaymentDomainService paymentDomainService; + private final PaymentDataMapper paymentDataMapper; + private final PaymentRepository paymentRepository; + private final CreditEntryRepository creditEntryRepository; + private final CreditHistoryRepository creditHistoryRepository; + + private final DomainEventPublisher publisher; + private final DomainEventPublisher publisherCancelled; + + private final DomainEventPublisher failedEventDomainEventPublisher; + + @Transactional + public PaymentEvent persistPayment(PaymentRequest paymentRequest) { + log.info("Received payment complete event for id : {}", paymentRequest.getOrderId()); + var payment = paymentDataMapper.paymentRequestModelToPayment(paymentRequest); + var creditEntry = getCreditEntry(payment.getCustomerId()); + var creditHistory = getCreditHistory(payment.getCustomerId()); + List failureMessage = new ArrayList<>(); + + var paymentEvent = paymentDomainService.validateAndInitializePayment + (payment, creditEntry, creditHistory, failureMessage,publisher,failedEventDomainEventPublisher); + + persistDbObject(payment, creditEntry, creditHistory, failureMessage); + return paymentEvent; + } + + + public PaymentEvent persistCancelPayment(PaymentRequest paymentRequest) { + log.info("Received payment cancel event for id : {}", paymentRequest.getOrderId()); + var payment = paymentRepository.findByOrderId + (UUID.fromString(paymentRequest.getOrderId())).orElseThrow( + () -> new PaymentApplicationServiceException("Payment not found")); + var creditEntry = getCreditEntry(payment.getCustomerId()); + var creditHistory = getCreditHistory(payment.getCustomerId()); + List failureMessage = new ArrayList<>(); + var paymentEvent = paymentDomainService.validateAndCancelledPayment + (payment, creditEntry, creditHistory, failureMessage,publisherCancelled,failedEventDomainEventPublisher); + + persistDbObject(payment, creditEntry, creditHistory, failureMessage); + return paymentEvent; + } + + private void persistDbObject(Payment payment, CreditEntry creditEntry, List creditHistory, List failureMessage) { + paymentRepository.save(payment); + if (failureMessage.isEmpty()) { + creditEntryRepository.save(creditEntry); + creditHistoryRepository.save(creditHistory.get(creditHistory.size() - 1)); + } + } + private List getCreditHistory(CustomerId customerId) { + return creditHistoryRepository.findByCustomerId(customerId).orElseThrow( + () -> new PaymentApplicationServiceException("No credit history found for customer id : " + customerId)); + } + + private CreditEntry getCreditEntry(CustomerId customerId) { + return creditEntryRepository.findByCustomerId(customerId).orElseThrow( + () -> new PaymentApplicationServiceException("Credit entry not found for customer id : " + customerId)); + } +} diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/PaymentRequestMessageListenerImpl.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/PaymentRequestMessageListenerImpl.java new file mode 100644 index 0000000..ce7ad55 --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/PaymentRequestMessageListenerImpl.java @@ -0,0 +1,35 @@ +package com.food.order.system.payment.application.service; + +import com.food.order.system.payment.application.service.dto.PaymentRequest; +import com.food.order.system.payment.application.service.ports.input.message.listener.PaymentRequestMessageListener; +import com.food.order.system.payment.service.domain.event.PaymentEvent; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +@RequiredArgsConstructor +public class PaymentRequestMessageListenerImpl implements PaymentRequestMessageListener { + + private final PaymentRequestHelper paymentRequestHelper; + + @Override + public void completePayment(PaymentRequest paymentRequest) { + var event = paymentRequestHelper.persistPayment(paymentRequest); + fireEvent(event); + } + @Override + public void cancelPayment(PaymentRequest paymentRequest) { + var event = paymentRequestHelper.persistCancelPayment(paymentRequest); + fireEvent(event); + } + private void fireEvent(PaymentEvent event) { + + log.info("Firing event : {}", event); + event.fire(); + + } + + +} diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/config/PaymentServiceConfigData.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/config/PaymentServiceConfigData.java new file mode 100644 index 0000000..10b34ec --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/config/PaymentServiceConfigData.java @@ -0,0 +1,15 @@ +package com.food.order.system.payment.application.service.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Data +@Configuration +@ConfigurationProperties(prefix = "payment-service") +public class PaymentServiceConfigData { + + private String paymentRequestTopicName; + private String paymentResponseTopicName; + +} diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/dto/PaymentRequest.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/dto/PaymentRequest.java new file mode 100644 index 0000000..d98c845 --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/dto/PaymentRequest.java @@ -0,0 +1,26 @@ +package com.food.order.system.payment.application.service.dto; + +import com.food.order.sysyem.valueobject.PaymentOrderStatus; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +import java.math.BigDecimal; +import java.time.Instant; + +@Getter +@Builder +@AllArgsConstructor +public class PaymentRequest { + private String id; + private String sagaId; + private String orderId; + private String customerId; + private BigDecimal price; + private Instant createdAt; + private PaymentOrderStatus status; + + public void setStatus(PaymentOrderStatus status) { + this.status = status; + } +} diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/exception/PaymentApplicationServiceException.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/exception/PaymentApplicationServiceException.java new file mode 100644 index 0000000..8ad2bec --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/exception/PaymentApplicationServiceException.java @@ -0,0 +1,14 @@ +package com.food.order.system.payment.application.service.exception; + +import com.food.order.sysyem.exception.DomainException; + +public class PaymentApplicationServiceException extends DomainException { + + public PaymentApplicationServiceException(String message) { + super(message); + } + + public PaymentApplicationServiceException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/mapper/PaymentDataMapper.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/mapper/PaymentDataMapper.java new file mode 100644 index 0000000..1de2426 --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/mapper/PaymentDataMapper.java @@ -0,0 +1,23 @@ +package com.food.order.system.payment.application.service.mapper; + +import com.food.order.system.payment.application.service.dto.PaymentRequest; +import com.food.order.system.payment.service.domain.entity.Payment; +import com.food.order.sysyem.valueobject.CustomerId; +import com.food.order.sysyem.valueobject.Money; +import com.food.order.sysyem.valueobject.OrderId; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component +public class PaymentDataMapper { + + + public Payment paymentRequestModelToPayment(PaymentRequest paymentRequest) { + return Payment.builder() + .customerId(new CustomerId(UUID.fromString(paymentRequest.getCustomerId()))) + .orderId(new OrderId(UUID.fromString(paymentRequest.getOrderId()))) + .price(new Money(paymentRequest.getPrice())) + .build(); + } +} diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/input/message/listener/PaymentRequestMessageListener.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/input/message/listener/PaymentRequestMessageListener.java new file mode 100644 index 0000000..b8abc9b --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/input/message/listener/PaymentRequestMessageListener.java @@ -0,0 +1,8 @@ +package com.food.order.system.payment.application.service.ports.input.message.listener; + +import com.food.order.system.payment.application.service.dto.PaymentRequest; + +public interface PaymentRequestMessageListener { + void completePayment(PaymentRequest paymentRequest); + void cancelPayment(PaymentRequest paymentRequest); +} diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/message/publisher/PaymentCancelledMessagePublisher.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/message/publisher/PaymentCancelledMessagePublisher.java new file mode 100644 index 0000000..6fb5925 --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/message/publisher/PaymentCancelledMessagePublisher.java @@ -0,0 +1,7 @@ +package com.food.order.system.payment.application.service.ports.output.message.publisher; + +import com.food.order.system.payment.service.domain.event.PaymentCancelledEvent; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; + +public interface PaymentCancelledMessagePublisher extends DomainEventPublisher { +} diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/message/publisher/PaymentCompletedMessagePublisher.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/message/publisher/PaymentCompletedMessagePublisher.java new file mode 100644 index 0000000..a50ede5 --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/message/publisher/PaymentCompletedMessagePublisher.java @@ -0,0 +1,7 @@ +package com.food.order.system.payment.application.service.ports.output.message.publisher; + +import com.food.order.system.payment.service.domain.event.PaymentCompletedEvent; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; + +public interface PaymentCompletedMessagePublisher extends DomainEventPublisher { +} diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/message/publisher/PaymentFailedMessagePublisher.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/message/publisher/PaymentFailedMessagePublisher.java new file mode 100644 index 0000000..5cf76ff --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/message/publisher/PaymentFailedMessagePublisher.java @@ -0,0 +1,7 @@ +package com.food.order.system.payment.application.service.ports.output.message.publisher; + +import com.food.order.system.payment.service.domain.event.PaymentFailedEvent; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; + +public interface PaymentFailedMessagePublisher extends DomainEventPublisher { +} diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/repository/CreditEntryRepository.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/repository/CreditEntryRepository.java new file mode 100644 index 0000000..87d2100 --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/repository/CreditEntryRepository.java @@ -0,0 +1,11 @@ +package com.food.order.system.payment.application.service.ports.output.repository; + +import com.food.order.system.payment.service.domain.entity.CreditEntry; +import com.food.order.sysyem.valueobject.CustomerId; + +import java.util.Optional; + +public interface CreditEntryRepository { + CreditEntry save(CreditEntry creditEntry); + Optional findByCustomerId(CustomerId orderId); +} diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/repository/CreditHistoryRepository.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/repository/CreditHistoryRepository.java new file mode 100644 index 0000000..443ed81 --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/repository/CreditHistoryRepository.java @@ -0,0 +1,12 @@ +package com.food.order.system.payment.application.service.ports.output.repository; + +import com.food.order.system.payment.service.domain.entity.CreditHistory; +import com.food.order.sysyem.valueobject.CustomerId; + +import java.util.List; +import java.util.Optional; + +public interface CreditHistoryRepository { + CreditHistory save(CreditHistory creditHistory); + Optional> findByCustomerId(CustomerId orderId); +} diff --git a/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/repository/PaymentRepository.java b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/repository/PaymentRepository.java new file mode 100644 index 0000000..e582155 --- /dev/null +++ b/payment-service/payment-domain/payment-application-service/src/main/java/com/food/order/system/payment/application/service/ports/output/repository/PaymentRepository.java @@ -0,0 +1,13 @@ +package com.food.order.system.payment.application.service.ports.output.repository; + +import com.food.order.system.payment.service.domain.entity.Payment; + +import java.util.Optional; +import java.util.UUID; + +public interface PaymentRepository { + Payment save(Payment payment); + Optional findByOrderId(UUID orderId); + + +} diff --git a/payment-service/payment-domain/payment-domain-core/pom.xml b/payment-service/payment-domain/payment-domain-core/pom.xml new file mode 100644 index 0000000..35ed9b1 --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/pom.xml @@ -0,0 +1,22 @@ + + + + payment-domain + com.food.order + 1.0-SNAPSHOT + + 4.0.0 + + payment-domain-core + + + + com.food.order + common-domain + + + + + \ No newline at end of file diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/PaymentDomainService.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/PaymentDomainService.java new file mode 100644 index 0000000..1c050a9 --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/PaymentDomainService.java @@ -0,0 +1,29 @@ +package com.food.order.system.payment.service.domain; + +import com.food.order.system.payment.service.domain.entity.CreditEntry; +import com.food.order.system.payment.service.domain.entity.CreditHistory; +import com.food.order.system.payment.service.domain.entity.Payment; +import com.food.order.system.payment.service.domain.event.PaymentCancelledEvent; +import com.food.order.system.payment.service.domain.event.PaymentCompletedEvent; +import com.food.order.system.payment.service.domain.event.PaymentEvent; +import com.food.order.system.payment.service.domain.event.PaymentFailedEvent; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; + +import java.util.List; + +public interface PaymentDomainService { + + PaymentEvent validateAndInitializePayment( Payment paymentEvent, + CreditEntry creditEntry, + List creditHistory, + List failureMessages, + DomainEventPublisher publisher, + DomainEventPublisher failedEventDomainEventPublisher); + + PaymentEvent validateAndCancelledPayment( Payment paymentEvent, + CreditEntry creditEntry, + List creditHistory, + List failureMessages, + DomainEventPublisher publisher, + DomainEventPublisher failedEventDomainEventPublisher); +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/PaymentDomainServiceImpl.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/PaymentDomainServiceImpl.java new file mode 100644 index 0000000..570dd55 --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/PaymentDomainServiceImpl.java @@ -0,0 +1,127 @@ +package com.food.order.system.payment.service.domain; + +import com.food.order.system.payment.service.domain.entity.CreditEntry; +import com.food.order.system.payment.service.domain.entity.CreditHistory; +import com.food.order.system.payment.service.domain.entity.Payment; +import com.food.order.system.payment.service.domain.event.PaymentCancelledEvent; +import com.food.order.system.payment.service.domain.event.PaymentCompletedEvent; +import com.food.order.system.payment.service.domain.event.PaymentEvent; +import com.food.order.system.payment.service.domain.event.PaymentFailedEvent; +import com.food.order.system.payment.service.domain.valueobject.CreditHistoryId; +import com.food.order.system.payment.service.domain.valueobject.TransactionType; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; +import com.food.order.sysyem.valueobject.Money; +import com.food.order.sysyem.valueobject.PaymentStatus; +import lombok.extern.slf4j.Slf4j; + +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.UUID; + +import static com.food.order.sysyem.DomainConstants.UTC; + +@Slf4j +public class PaymentDomainServiceImpl implements PaymentDomainService { + + + @Override + public PaymentEvent validateAndInitializePayment(Payment payment, + CreditEntry creditEntry, + List creditHistory, + List failureMessages, + DomainEventPublisher publisher, + DomainEventPublisher failedPublisher) { + payment.validatePayment(failureMessages); + payment.initializePayment(); + validateCreditEntry(payment,creditEntry,failureMessages); + subtractCreditEntry(payment,creditEntry); + updateCreditHistory(payment,creditHistory, TransactionType.DEBIT); + validateCreditHistory(creditEntry,creditHistory,failureMessages); + + if (failureMessages.isEmpty()) { + log.info("Payment is valid and initialized"); + payment.updateStatus(PaymentStatus.COMPLETED); + return new PaymentCompletedEvent(payment, ZonedDateTime.now(ZoneId.of(UTC)),publisher ); + } else { + log.info("Payment is invalid and not initialized"); + payment.updateStatus(PaymentStatus.FAILED); + return new PaymentFailedEvent(payment, ZonedDateTime.now(ZoneId.of(UTC)), failureMessages,failedPublisher); + } + + } + + @Override + public PaymentEvent validateAndCancelledPayment(Payment payment, + CreditEntry creditEntry, + List creditHistory, + List failureMessages, + DomainEventPublisher publisher, + DomainEventPublisher failedPublisher) { + + payment.validatePayment(failureMessages); + addCreditEntry(payment,creditEntry); + updateCreditHistory(payment,creditHistory, TransactionType.CREDIT); + + if (failureMessages.isEmpty()) { + log.info("Payment is valid and cancelled"); + payment.updateStatus(PaymentStatus.CANCELED); + return new PaymentCancelledEvent(payment, ZonedDateTime.now(ZoneId.of(UTC)),publisher); + } else { + log.info("Payment is invalid and not cancelled"); + payment.updateStatus(PaymentStatus.FAILED); + return new PaymentFailedEvent(payment, ZonedDateTime.now(ZoneId.of(UTC)), failureMessages,failedPublisher); + } + } + + private void addCreditEntry(Payment payment, CreditEntry creditEntry) { + creditEntry.addCreditAmount(payment.getPrice()); + } + + private void validateCreditHistory(CreditEntry creditEntry, List creditHistory, List failureMessages) { + var totalCreditHistory = getTotalHistoryAmount(creditHistory, TransactionType.CREDIT); + var totalDebitHistory = getTotalHistoryAmount(creditHistory, TransactionType.DEBIT); + + if (totalDebitHistory.isGreaterThan(totalCreditHistory)) { + failureMessages.add("Customer id " + creditEntry.getCustomerId() + " has insufficient credit"); + log.error("Customer id {} has insufficient credit", creditEntry.getCustomerId()); + } + + if (!creditEntry.getTotalCreditAmount().equals(totalCreditHistory.subtract(totalDebitHistory))) { + failureMessages.add("Customer id " + creditEntry.getCustomerId() + " has total is not equal to credit history"); + log.error("Customer id {} has total is not equal to credit history", creditEntry.getCustomerId()); + } + } + + private Money getTotalHistoryAmount(List creditHistory, TransactionType transactionType) { + return creditHistory.stream() + .filter(history -> transactionType.equals(history.getTransactionType())) + .map(CreditHistory::getAmount) + .reduce(Money.ZERO, Money::add); + } + + private void updateCreditHistory(Payment payment, List creditHistory, TransactionType transactionType) { + creditHistory.add( + CreditHistory.builder() + .id(new CreditHistoryId(UUID.randomUUID())) + .customerId(payment.getCustomerId()) + .amount(payment.getPrice()) + .transactionType(transactionType) + .build() + ); + } + + private void subtractCreditEntry(Payment payment, CreditEntry creditEntry) { + creditEntry.subtractCreditAmount(payment.getPrice()); + } + + private void validateCreditEntry(Payment payment, CreditEntry creditEntry, List failureMessages) { + if(payment.getPrice().isGreaterThan(creditEntry.getTotalCreditAmount())){ + failureMessages.add("Customer id "+ payment.getCustomerId() + " , has insufficient credit amount" + + creditEntry.getTotalCreditAmount() + " to pay for order id " + payment.getOrderId()); + log.error("Payment price is greater than credit"); + } + } + + +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/entity/CreditEntry.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/entity/CreditEntry.java new file mode 100644 index 0000000..2e03161 --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/entity/CreditEntry.java @@ -0,0 +1,70 @@ +package com.food.order.system.payment.service.domain.entity; + +import com.food.order.system.payment.service.domain.valueobject.CreditEntryId; +import com.food.order.sysyem.entity.BaseEntity; +import com.food.order.sysyem.valueobject.CustomerId; +import com.food.order.sysyem.valueobject.Money; + +public class CreditEntry extends BaseEntity { + + private final CustomerId customerId; + + private Money totalCreditAmount; + + public void addCreditAmount(Money creditAmount) { + totalCreditAmount = totalCreditAmount.add(creditAmount); + } + + public void subtractCreditAmount(Money creditAmount) { + totalCreditAmount = totalCreditAmount.subtract(creditAmount); + } + + + + private CreditEntry(Builder builder) { + setId(builder.creditEntryId); + customerId = builder.customerId; + totalCreditAmount = builder.totalCreditAmount; + } + + public static Builder builder() { + return new Builder(); + } + + public CustomerId getCustomerId() { + return customerId; + } + + public Money getTotalCreditAmount() { + return totalCreditAmount; + } + + + public static final class Builder { + private CreditEntryId creditEntryId; + private CustomerId customerId; + private Money totalCreditAmount; + + private Builder() { + } + + public Builder id(CreditEntryId val) { + creditEntryId = val; + return this; + } + + public Builder customerId(CustomerId val) { + customerId = val; + return this; + } + + public Builder totalCreditAmount(Money val) { + totalCreditAmount = val; + return this; + } + + public CreditEntry build() { + return new CreditEntry(this); + } + } +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/entity/CreditHistory.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/entity/CreditHistory.java new file mode 100644 index 0000000..9c1f1d0 --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/entity/CreditHistory.java @@ -0,0 +1,72 @@ +package com.food.order.system.payment.service.domain.entity; + +import com.food.order.system.payment.service.domain.valueobject.CreditHistoryId; +import com.food.order.system.payment.service.domain.valueobject.TransactionType; +import com.food.order.sysyem.entity.BaseEntity; +import com.food.order.sysyem.valueobject.CustomerId; +import com.food.order.sysyem.valueobject.Money; + +public class CreditHistory extends BaseEntity { + + private final CustomerId customerId; + private final Money amount; + private final TransactionType transactionType; + + private CreditHistory(Builder builder) { + setId(builder.creditHistoryId); + customerId = builder.customerId; + amount = builder.amount; + transactionType = builder.transactionType; + } + + public static Builder builder() { + return new Builder(); + } + + + public CustomerId getCustomerId() { + return customerId; + } + + public Money getAmount() { + return amount; + } + + public TransactionType getTransactionType() { + return transactionType; + } + + public static final class Builder { + private CreditHistoryId creditHistoryId; + private CustomerId customerId; + private Money amount; + private TransactionType transactionType; + + private Builder() { + } + + public Builder id(CreditHistoryId val) { + creditHistoryId = val; + return this; + } + + public Builder customerId(CustomerId val) { + customerId = val; + return this; + } + + public Builder amount(Money val) { + amount = val; + return this; + } + + public Builder transactionType(TransactionType val) { + transactionType = val; + return this; + } + + public CreditHistory build() { + return new CreditHistory(this); + } + } +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/entity/Payment.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/entity/Payment.java new file mode 100644 index 0000000..7577f02 --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/entity/Payment.java @@ -0,0 +1,119 @@ +package com.food.order.system.payment.service.domain.entity; + +import com.food.order.system.payment.service.domain.valueobject.PaymentId; +import com.food.order.sysyem.entity.AggregateRoot; +import com.food.order.sysyem.valueobject.CustomerId; +import com.food.order.sysyem.valueobject.Money; +import com.food.order.sysyem.valueobject.OrderId; +import com.food.order.sysyem.valueobject.PaymentStatus; + +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import java.util.UUID; + +public class Payment extends AggregateRoot { + + private final OrderId orderId; + private final CustomerId customerId; + private final Money price; + + private PaymentStatus status; + private ZonedDateTime createdAt; + + public void initializePayment(){ + setId(new PaymentId(UUID.randomUUID())); + createdAt = ZonedDateTime.now(ZoneId.of("UTC")); + } + + public void validatePayment(List failureMessages){ + if (Objects.isNull(price) || !price.isGreaterThanZero()){ + failureMessages.add("Payment price must be greater than zero"); + } + } + + public void updateStatus ( PaymentStatus status ) { + this.status = status; + } + + private Payment(Builder builder) { + setId(builder.paymentId); + orderId = builder.orderId; + customerId = builder.customerId; + price = builder.price; + status = builder.status; + createdAt = builder.createdAt; + } + + public static Builder builder() { + return new Builder(); + } + + + public OrderId getOrderId() { + return orderId; + } + + public CustomerId getCustomerId() { + return customerId; + } + + public Money getPrice() { + return price; + } + + public PaymentStatus getStatus() { + return status; + } + + public ZonedDateTime getCreatedAt() { + return createdAt; + } + + public static final class Builder { + private PaymentId paymentId; + private OrderId orderId; + private CustomerId customerId; + private Money price; + private PaymentStatus status; + private ZonedDateTime createdAt; + + private Builder() { + } + + public Builder id(PaymentId val) { + paymentId = val; + return this; + } + + public Builder orderId(OrderId val) { + orderId = val; + return this; + } + + public Builder customerId(CustomerId val) { + customerId = val; + return this; + } + + public Builder price(Money val) { + price = val; + return this; + } + + public Builder status(PaymentStatus val) { + status = val; + return this; + } + + public Builder createdAt(ZonedDateTime val) { + createdAt = val; + return this; + } + + public Payment build() { + return new Payment(this); + } + } +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/event/PaymentCancelledEvent.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/event/PaymentCancelledEvent.java new file mode 100644 index 0000000..835d5fa --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/event/PaymentCancelledEvent.java @@ -0,0 +1,23 @@ +package com.food.order.system.payment.service.domain.event; + +import com.food.order.system.payment.service.domain.entity.Payment; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; + +import java.time.ZonedDateTime; +import java.util.Collections; + +public class PaymentCancelledEvent extends PaymentEvent{ + + private final DomainEventPublisher publisher; + + public PaymentCancelledEvent(Payment payment, ZonedDateTime createdAt, DomainEventPublisher publisher) { + super(payment, createdAt, Collections.emptyList()); + this.publisher = publisher; + } + + + @Override + public void fire() { + publisher.publish(this); + } +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/event/PaymentCompletedEvent.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/event/PaymentCompletedEvent.java new file mode 100644 index 0000000..399b34d --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/event/PaymentCompletedEvent.java @@ -0,0 +1,25 @@ +package com.food.order.system.payment.service.domain.event; + +import com.food.order.system.payment.service.domain.entity.Payment; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; + +import java.time.ZonedDateTime; +import java.util.Collections; + +public class PaymentCompletedEvent extends PaymentEvent{ + + private final DomainEventPublisher publisher; + + public PaymentCompletedEvent(Payment payment, + ZonedDateTime createdAt, + DomainEventPublisher publisher) { + super(payment, createdAt , Collections.emptyList()); + this.publisher = publisher; + } + + + @Override + public void fire() { + publisher.publish(this); + } +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/event/PaymentEvent.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/event/PaymentEvent.java new file mode 100644 index 0000000..ce361d2 --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/event/PaymentEvent.java @@ -0,0 +1,31 @@ +package com.food.order.system.payment.service.domain.event; + +import com.food.order.system.payment.service.domain.entity.Payment; +import com.food.order.sysyem.event.DomainEvent; + +import java.time.ZonedDateTime; +import java.util.List; + +public abstract class PaymentEvent implements DomainEvent { + private final Payment payment; + private final ZonedDateTime createdAt; + private final List failureMessages; + + public PaymentEvent(Payment payment, ZonedDateTime createdAt, List failureMessages) { + this.payment = payment; + this.createdAt = createdAt; + this.failureMessages = failureMessages; + } + + public Payment getPayment() { + return payment; + } + + public ZonedDateTime getCreatedAt() { + return createdAt; + } + + public List getFailureMessages() { + return failureMessages; + } +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/event/PaymentFailedEvent.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/event/PaymentFailedEvent.java new file mode 100644 index 0000000..6838c43 --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/event/PaymentFailedEvent.java @@ -0,0 +1,23 @@ +package com.food.order.system.payment.service.domain.event; + +import com.food.order.system.payment.service.domain.entity.Payment; +import com.food.order.sysyem.event.publisher.DomainEventPublisher; + +import java.time.ZonedDateTime; +import java.util.List; + +public class PaymentFailedEvent extends PaymentEvent{ + + private final DomainEventPublisher publisher; + + public PaymentFailedEvent(Payment payment, ZonedDateTime createdAt, List failureMessages, + DomainEventPublisher publisher) { + super(payment, createdAt, failureMessages); + this.publisher = publisher; + } + + @Override + public void fire() { + publisher.publish(this); + } +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/exception/PayemntDomainException.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/exception/PayemntDomainException.java new file mode 100644 index 0000000..eaa11ba --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/exception/PayemntDomainException.java @@ -0,0 +1,13 @@ +package com.food.order.system.payment.service.domain.exception; + +import com.food.order.sysyem.exception.DomainException; + +public class PayemntDomainException extends DomainException { + public PayemntDomainException(String message) { + super(message); + } + + public PayemntDomainException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/exception/PaymentNotFoundException.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/exception/PaymentNotFoundException.java new file mode 100644 index 0000000..8f52ba1 --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/exception/PaymentNotFoundException.java @@ -0,0 +1,13 @@ +package com.food.order.system.payment.service.domain.exception; + +import com.food.order.sysyem.exception.DomainException; + +public class PaymentNotFoundException extends DomainException { + public PaymentNotFoundException(String message) { + super(message); + } + + public PaymentNotFoundException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/valueobject/CreditEntryId.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/valueobject/CreditEntryId.java new file mode 100644 index 0000000..043d8ac --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/valueobject/CreditEntryId.java @@ -0,0 +1,11 @@ +package com.food.order.system.payment.service.domain.valueobject; + +import com.food.order.sysyem.valueobject.BaseId; + +import java.util.UUID; + +public class CreditEntryId extends BaseId { + public CreditEntryId(UUID value) { + super(value); + } +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/valueobject/CreditHistoryId.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/valueobject/CreditHistoryId.java new file mode 100644 index 0000000..b37a105 --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/valueobject/CreditHistoryId.java @@ -0,0 +1,12 @@ +package com.food.order.system.payment.service.domain.valueobject; + +import com.food.order.sysyem.valueobject.BaseId; + +import java.util.UUID; + +public class CreditHistoryId extends BaseId { + + public CreditHistoryId(UUID value) { + super(value); + } +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/valueobject/PaymentId.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/valueobject/PaymentId.java new file mode 100644 index 0000000..3dc8d61 --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/valueobject/PaymentId.java @@ -0,0 +1,11 @@ +package com.food.order.system.payment.service.domain.valueobject; + +import com.food.order.sysyem.valueobject.BaseId; + +import java.util.UUID; + +public class PaymentId extends BaseId { + public PaymentId(UUID id) { + super(id); + } +} diff --git a/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/valueobject/TransactionType.java b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/valueobject/TransactionType.java new file mode 100644 index 0000000..09b8a79 --- /dev/null +++ b/payment-service/payment-domain/payment-domain-core/src/main/java/com/food/order/system/payment/service/domain/valueobject/TransactionType.java @@ -0,0 +1,5 @@ +package com.food.order.system.payment.service.domain.valueobject; + +public enum TransactionType { + DEBIT, CREDIT +} diff --git a/payment-service/payment-domain/pom.xml b/payment-service/payment-domain/pom.xml new file mode 100644 index 0000000..4f05e65 --- /dev/null +++ b/payment-service/payment-domain/pom.xml @@ -0,0 +1,20 @@ + + + + payment-service + com.food.order + 1.0-SNAPSHOT + + 4.0.0 + + payment-domain + pom + + payment-domain-core + payment-application-service + + + + \ No newline at end of file diff --git a/payment-service/payment-messaging/pom.xml b/payment-service/payment-messaging/pom.xml new file mode 100644 index 0000000..cd274e4 --- /dev/null +++ b/payment-service/payment-messaging/pom.xml @@ -0,0 +1,35 @@ + + + + payment-service + com.food.order + 1.0-SNAPSHOT + + 4.0.0 + + payment-messaging + + + + com.food.order + payment-application-service + + + + com.food.order + kafka-producer + + + + com.food.order + kafka-consumer + + + + com.food.order + kafka-model + + + \ No newline at end of file diff --git a/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/listener/kafka/PaymentRequestKafkaListener.java b/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/listener/kafka/PaymentRequestKafkaListener.java new file mode 100644 index 0000000..0a66271 --- /dev/null +++ b/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/listener/kafka/PaymentRequestKafkaListener.java @@ -0,0 +1,53 @@ +package com.food.order.system.payment.messaging.listener.kafka; + +import com.food.order.system.kafka.consumer.KafkaConsumer; +import com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel; +import com.food.order.system.payment.application.service.ports.input.message.listener.PaymentRequestMessageListener; +import com.food.order.system.payment.messaging.mapper.PaymentMessagingDataMapper; +import com.food.order.sysyem.valueobject.PaymentOrderStatus; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.kafka.support.KafkaHeaders; +import org.springframework.messaging.handler.annotation.Header; +import org.springframework.messaging.handler.annotation.Payload; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +@Slf4j +@RequiredArgsConstructor +public class PaymentRequestKafkaListener implements KafkaConsumer { + + private final PaymentMessagingDataMapper paymentMessagingDataMapper; + private final PaymentRequestMessageListener paymentRequestMessageListener; + + + @Override + @KafkaListener(id = "${kafka-consumer-config.payment-consumer-group-id}", + topics = "${payment-service.payment-request-topic-name}") + public void receive(@Payload List messages, + @Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) List keys, + @Header(KafkaHeaders.RECEIVED_PARTITION_ID) List partitions, + @Header(KafkaHeaders.OFFSET) List offsets) { + log.info("{} number of payment requests received with keys:{}, partitions:{} and offsets: {}", + messages.size(), + keys.toString(), + partitions.toString(), + offsets.toString()); + + messages.forEach(paymentRequestAvroModel -> { + if (PaymentOrderStatus.PENDING.name().equalsIgnoreCase(paymentRequestAvroModel.getPaymentOrderStatus().name())) { + log.info("Processing payment for order id: {}", paymentRequestAvroModel.getOrderId()); + paymentRequestMessageListener.completePayment(paymentMessagingDataMapper + .paymentRequestAvroModelToPaymentRequest(paymentRequestAvroModel)); + } else if(PaymentOrderStatus.CANCELLED.name().equalsIgnoreCase(paymentRequestAvroModel.getPaymentOrderStatus().name())) { + log.info("Cancelling payment for order id: {}", paymentRequestAvroModel.getOrderId()); + paymentRequestMessageListener.cancelPayment(paymentMessagingDataMapper + .paymentRequestAvroModelToPaymentRequest(paymentRequestAvroModel)); + } + }); + + } +} diff --git a/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/mapper/PaymentMessagingDataMapper.java b/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/mapper/PaymentMessagingDataMapper.java new file mode 100644 index 0000000..5569f56 --- /dev/null +++ b/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/mapper/PaymentMessagingDataMapper.java @@ -0,0 +1,74 @@ +package com.food.order.system.payment.messaging.mapper; + +import com.food.order.system.kafka.order.avro.model.PaymentRequestAvroModel; +import com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel; +import com.food.order.system.kafka.order.avro.model.PaymentStatus; +import com.food.order.system.payment.application.service.dto.PaymentRequest; +import com.food.order.system.payment.service.domain.event.PaymentCancelledEvent; +import com.food.order.system.payment.service.domain.event.PaymentCompletedEvent; +import com.food.order.system.payment.service.domain.event.PaymentFailedEvent; +import com.food.order.sysyem.valueobject.PaymentOrderStatus; +import org.springframework.stereotype.Component; + +import java.util.UUID; + +@Component +public class PaymentMessagingDataMapper { + + public PaymentResponseAvroModel paymentCompletedEventToPaymentResponseAvroModel(PaymentCompletedEvent paymentCompletedEvent) { + return PaymentResponseAvroModel.newBuilder() + .setId(UUID.randomUUID().toString()) + .setSagaId("") + .setPaymentId(paymentCompletedEvent.getPayment().getId().getValue().toString()) + .setCustomerId(paymentCompletedEvent.getPayment().getCustomerId().getValue().toString()) + .setOrderId(paymentCompletedEvent.getPayment().getOrderId().getValue().toString()) + .setPrice(paymentCompletedEvent.getPayment().getPrice().getAmount()) + .setCreatedAt(paymentCompletedEvent.getPayment().getCreatedAt().toInstant()) + .setPaymentStatus(PaymentStatus.valueOf(paymentCompletedEvent.getPayment().getStatus().name())) + .setFailureMessages(paymentCompletedEvent.getFailureMessages()) + .build(); + } + + public PaymentResponseAvroModel paymentCancelEventToPaymentResponseAvroModel(PaymentCancelledEvent paymentCancelledEvent) { + return PaymentResponseAvroModel.newBuilder() + .setId(UUID.randomUUID().toString()) + .setSagaId("") + .setPaymentId(paymentCancelledEvent.getPayment().getId().getValue().toString()) + .setCustomerId(paymentCancelledEvent.getPayment().getCustomerId().getValue().toString()) + .setOrderId(paymentCancelledEvent.getPayment().getOrderId().getValue().toString()) + .setPrice(paymentCancelledEvent.getPayment().getPrice().getAmount()) + .setCreatedAt(paymentCancelledEvent.getPayment().getCreatedAt().toInstant()) + .setPaymentStatus(PaymentStatus.valueOf(paymentCancelledEvent.getPayment().getStatus().name())) + .setFailureMessages(paymentCancelledEvent.getFailureMessages()) + .build(); + } + + public PaymentResponseAvroModel paymentFailedEventToPaymentResponseAvroModel(PaymentFailedEvent paymentFailedEvent) { + return PaymentResponseAvroModel.newBuilder() + .setId(UUID.randomUUID().toString()) + .setSagaId("") + .setPaymentId(paymentFailedEvent.getPayment().getId().getValue().toString()) + .setCustomerId(paymentFailedEvent.getPayment().getCustomerId().getValue().toString()) + .setOrderId(paymentFailedEvent.getPayment().getOrderId().getValue().toString()) + .setPrice(paymentFailedEvent.getPayment().getPrice().getAmount()) + .setCreatedAt(paymentFailedEvent.getPayment().getCreatedAt().toInstant()) + .setPaymentStatus(PaymentStatus.valueOf(paymentFailedEvent.getPayment().getStatus().name())) + .setFailureMessages(paymentFailedEvent.getFailureMessages()) + .build(); + } + + public PaymentRequest paymentRequestAvroModelToPaymentRequest(PaymentRequestAvroModel paymentRequestAvroModel) { + return PaymentRequest.builder() + .id(paymentRequestAvroModel.getId()) + .sagaId(paymentRequestAvroModel.getSagaId()) + .customerId(paymentRequestAvroModel.getCustomerId()) + .orderId(paymentRequestAvroModel.getOrderId()) + .price(paymentRequestAvroModel.getPrice()) + .createdAt(paymentRequestAvroModel.getCreatedAt()) + .status(PaymentOrderStatus.valueOf(paymentRequestAvroModel.getPaymentOrderStatus().name())) + .build(); + } + + + +} diff --git a/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/publisher/kafka/PaymentCancelledKafkaMessagePublisher.java b/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/publisher/kafka/PaymentCancelledKafkaMessagePublisher.java new file mode 100644 index 0000000..538b711 --- /dev/null +++ b/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/publisher/kafka/PaymentCancelledKafkaMessagePublisher.java @@ -0,0 +1,47 @@ +package com.food.order.system.payment.messaging.publisher.kafka; + +import com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel; +import com.food.order.system.kafka.producer.KafkaMessageHelper; +import com.food.order.system.kafka.producer.service.KafkaProducer; +import com.food.order.system.payment.application.service.config.PaymentServiceConfigData; +import com.food.order.system.payment.application.service.ports.output.message.publisher.PaymentCancelledMessagePublisher; +import com.food.order.system.payment.messaging.mapper.PaymentMessagingDataMapper; +import com.food.order.system.payment.service.domain.event.PaymentCancelledEvent; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +@RequiredArgsConstructor +public class PaymentCancelledKafkaMessagePublisher implements PaymentCancelledMessagePublisher { + + private final PaymentMessagingDataMapper paymentDataMapper; + private final KafkaProducer kafkaProducer; + private final PaymentServiceConfigData paymentServiceConfigData; + private final KafkaMessageHelper kafkaMessageHelper; + + + @Override + public void publish(PaymentCancelledEvent event) { + log.info("Publishing payment cancelled event to kafka"); + var orderId = event.getPayment().getOrderId().getValue().toString(); + try { + var paymentResponseAvroModel = + paymentDataMapper.paymentCancelEventToPaymentResponseAvroModel(event); + + kafkaProducer.send(paymentServiceConfigData.getPaymentResponseTopicName(), + orderId, + paymentResponseAvroModel, + kafkaMessageHelper.getKafkaCallBack( + paymentServiceConfigData.getPaymentResponseTopicName(), + paymentResponseAvroModel, + orderId, + "PaymentResponseAvroModel")); + + log.info("Published payment cancelled event to kafka"); + } catch (Exception e) { + log.error("Error while publishing payment cancelled event to kafka", e); + } + } +} diff --git a/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/publisher/kafka/PaymentCompletedKafkaMessagePublisher.java b/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/publisher/kafka/PaymentCompletedKafkaMessagePublisher.java new file mode 100644 index 0000000..4e38a67 --- /dev/null +++ b/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/publisher/kafka/PaymentCompletedKafkaMessagePublisher.java @@ -0,0 +1,48 @@ +package com.food.order.system.payment.messaging.publisher.kafka; + +import com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel; +import com.food.order.system.kafka.producer.KafkaMessageHelper; +import com.food.order.system.kafka.producer.service.KafkaProducer; +import com.food.order.system.payment.application.service.config.PaymentServiceConfigData; +import com.food.order.system.payment.application.service.ports.output.message.publisher.PaymentCompletedMessagePublisher; +import com.food.order.system.payment.messaging.mapper.PaymentMessagingDataMapper; +import com.food.order.system.payment.service.domain.event.PaymentCompletedEvent; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +@RequiredArgsConstructor +public class PaymentCompletedKafkaMessagePublisher implements PaymentCompletedMessagePublisher { + + private final PaymentMessagingDataMapper paymentDataMapper; + private final KafkaProducer kafkaProducer; + private final PaymentServiceConfigData paymentServiceConfigData; + + private final KafkaMessageHelper kafkaMessageHelper; + + + @Override + public void publish(PaymentCompletedEvent event) { + log.info("Publishing payment completed event to kafka"); + var orderId = event.getPayment().getOrderId().getValue().toString(); + try { + var paymentResponseAvroModel = + paymentDataMapper.paymentCompletedEventToPaymentResponseAvroModel(event); + + kafkaProducer.send(paymentServiceConfigData.getPaymentResponseTopicName(), + orderId, + paymentResponseAvroModel, + kafkaMessageHelper.getKafkaCallBack( + paymentServiceConfigData.getPaymentResponseTopicName(), + paymentResponseAvroModel, + orderId, + "PaymentResponseAvroModel")); + + log.info("Published payment completed event to kafka"); + } catch (Exception e) { + log.error("Error while publishing payment completed event to kafka", e); + } + } +} diff --git a/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/publisher/kafka/PaymentFailedKafkaMessagePublisher.java b/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/publisher/kafka/PaymentFailedKafkaMessagePublisher.java new file mode 100644 index 0000000..56a6f08 --- /dev/null +++ b/payment-service/payment-messaging/src/main/java/com/food/order/system/payment/messaging/publisher/kafka/PaymentFailedKafkaMessagePublisher.java @@ -0,0 +1,48 @@ +package com.food.order.system.payment.messaging.publisher.kafka; + +import com.food.order.system.kafka.order.avro.model.PaymentResponseAvroModel; +import com.food.order.system.kafka.producer.KafkaMessageHelper; +import com.food.order.system.kafka.producer.service.KafkaProducer; +import com.food.order.system.payment.application.service.config.PaymentServiceConfigData; +import com.food.order.system.payment.application.service.ports.output.message.publisher.PaymentFailedMessagePublisher; +import com.food.order.system.payment.messaging.mapper.PaymentMessagingDataMapper; +import com.food.order.system.payment.service.domain.event.PaymentFailedEvent; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +@RequiredArgsConstructor +public class PaymentFailedKafkaMessagePublisher implements PaymentFailedMessagePublisher { + + private final PaymentMessagingDataMapper paymentDataMapper; + private final KafkaProducer kafkaProducer; + private final PaymentServiceConfigData paymentServiceConfigData; + + private final KafkaMessageHelper kafkaMessageHelper; + + + @Override + public void publish(PaymentFailedEvent event) { + log.info("Publishing payment failed event to kafka"); + var orderId = event.getPayment().getOrderId().getValue().toString(); + try { + var paymentResponseAvroModel = + paymentDataMapper.paymentFailedEventToPaymentResponseAvroModel(event); + + kafkaProducer.send(paymentServiceConfigData.getPaymentResponseTopicName(), + orderId, + paymentResponseAvroModel, + kafkaMessageHelper.getKafkaCallBack( + paymentServiceConfigData.getPaymentResponseTopicName(), + paymentResponseAvroModel, + orderId, + "PaymentResponseAvroModel")); + + log.info("Published payment failed event to kafka"); + } catch (Exception e) { + log.error("Error while publishing payment failed event to kafka", e); + } + } +} diff --git a/payment-service/pom.xml b/payment-service/pom.xml new file mode 100644 index 0000000..3bae58c --- /dev/null +++ b/payment-service/pom.xml @@ -0,0 +1,22 @@ + + + + food-ordering-system + com.food.order + 1.0-SNAPSHOT + + 4.0.0 + + payment-service + pom + + payment-domain + payment-dataaccess + payment-messaging + payment-container + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5c05d3e..bf3e86b 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ spring-boot-starter-parent org.springframework.boot - 2.7.1 + 2.6.7 4.0.0 @@ -15,6 +15,7 @@ infrastructure infrastructure/kafka customer-service + payment-service @@ -41,12 +42,43 @@ ${project.version} + + com.food.order + payment-domain + ${project.version} + + com.food.order order-app ${project.version} + + com.food.order + payment-application-service + ${project.version} + + + + com.food.order + payment-domain-core + ${project.version} + + + + com.food.order + payment-dataaccess + ${project.version} + + + + com.food.order + payment-messaging + ${project.version} + + + com.food.order order-application-service