Skip to content

Commit

Permalink
Added kafkaConsumer for inventory + InventoryEvent(dto)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdiJ2001 committed Nov 23, 2024
1 parent de190da commit f47bce7
Show file tree
Hide file tree
Showing 15 changed files with 363 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/projet-soa-ecommerce-enit-2024-3AINFO2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions catalog/catalog-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>


</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,102 +19,101 @@ public class Product {
@Column
private LocalDateTime createdAt = LocalDateTime.now();
@ManyToOne(optional = false)
@JoinColumn(name = "category_id",nullable = false)
@JoinColumn(name = "category_id", nullable = false)
private ProductCategory category;
private double basePrice;
private double shownPrice=basePrice;
private double shownPrice = basePrice;
private boolean disponibility;

public Product() {
}



public Product(String productName, String description, LocalDateTime createdAt, ProductCategory category,
double basePrice, double shownPrice) {
double basePrice, double shownPrice, boolean disponibility) {
this.productName = productName;
this.description = description;
this.createdAt = createdAt;
this.category = category;
this.basePrice = basePrice;
this.shownPrice = shownPrice;
this.disponibility = disponibility;
}



public Product(UUID id, String productName, String description, LocalDateTime createdAt, ProductCategory category,
double basePrice, double shownPrice) {
double basePrice, double shownPrice, boolean disponibility) {
this.id = id;
this.productName = productName;
this.description = description;
this.createdAt = createdAt;
this.category = category;
this.basePrice = basePrice;
this.shownPrice = shownPrice;
this.disponibility = disponibility;
}



public UUID getId() {
return id;
}

public void setId(UUID id) {
this.id = id;
}

public String getProductName() {
return productName;
}

public void setProductName(String productName) {
this.productName = productName;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public LocalDateTime getCreatedAt() {
return createdAt;
}

public void setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
}



public ProductCategory getCategory() {
return category;
}



public double getBasePrice() {
return basePrice;
}



public double getShownPrice() {
return shownPrice;
}



public void setCategory(ProductCategory category) {
this.category = category;
}


public double getBasePrice() {
return basePrice;
}

public void setBasePrice(double basePrice) {
this.basePrice = basePrice;
}


public double getShownPrice() {
return shownPrice;
}

public void setShownPrice(double shownPrice) {
this.shownPrice = shownPrice;
}

public boolean isDisponibility() {
return disponibility;
}

public void setDisponibility(boolean disponibility) {
this.disponibility = disponibility;
}

@Override
public int hashCode() {
Expand All @@ -130,11 +129,10 @@ public int hashCode() {
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(shownPrice);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + (disponibility ? 1231 : 1237);
return result;
}



@Override
public boolean equals(Object obj) {
if (this == obj)
Expand Down Expand Up @@ -173,17 +171,15 @@ public boolean equals(Object obj) {
return false;
if (Double.doubleToLongBits(shownPrice) != Double.doubleToLongBits(other.shownPrice))
return false;
if (disponibility != other.disponibility)
return false;
return true;
}



@Override
public String toString() {
return "Product [id=" + id + ", productName=" + productName + ", description=" + description + ", createdAt="
+ createdAt + ", category=" + category + ", basePrice=" + basePrice + ", shownPrice=" + shownPrice
+ "]";
+ ", disponibility=" + disponibility + "]";
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.ecommerce.dto;

public class InventoryEvent {

private String eventType;
private String productId;
private String description;
private String category;
private double basePrice;
private boolean disponibility;


public String getEventType() {
return eventType;
}

public void setEventType(String eventType) {
this.eventType = eventType;
}

public String getProductId() {
return productId;
}

public void setProductId(String productId) {
this.productId = productId;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public double getBasePrice() {
return basePrice;
}

public void setBasePrice(double basePrice) {
this.basePrice = basePrice;
}

public boolean isDisponibility() {
return disponibility;
}

public void setDisponibility(boolean disponibility) {
this.disponibility = disponibility;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;

import java.util.UUID;

import org.ecommerce.domain.ProductCategory;
import org.ecommerce.exceptions.EntityNotFoundException;

import java.util.UUID;

@ApplicationScoped
public class ProductCategoryRepository {

Expand All @@ -19,17 +18,35 @@ public class ProductCategoryRepository {
public ProductCategory findByName(String categoryName) throws EntityNotFoundException {
try {
return em.createQuery("SELECT c FROM ProductCategory c WHERE c.categoryName = :categoryName", ProductCategory.class)
.setParameter("categoryName", categoryName)
.getSingleResult();
.setParameter("categoryName", categoryName)
.getSingleResult();
} catch (Exception e) {
throw new EntityNotFoundException("Cannot find category with name: " + categoryName);
}
}

public ProductCategory findById(UUID id) throws EntityNotFoundException {
ProductCategory category = em.find(ProductCategory.class, id);
if (category == null) {
throw new EntityNotFoundException("Category not found for ID: " + id);
}
return category;
}

@Transactional
public ProductCategory insert(ProductCategory category) {
category.setId(UUID.randomUUID());
category.setId(UUID.randomUUID());
em.persist(category);
return category;
}

@Transactional
public ProductCategory update(ProductCategory category) {
return em.merge(category);
}

@Transactional
public void delete(ProductCategory category) {
em.remove(em.contains(category) ? category : em.merge(category));
}
}
Loading

0 comments on commit f47bce7

Please sign in to comment.