Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3c7318e
added project base
MohammmedAhmed8 May 2, 2025
b0734f8
added .github file
MohammmedAhmed8 May 2, 2025
280a921
fixed linter issue
MohammmedAhmed8 May 2, 2025
c059be8
fixed linter issue
MohammmedAhmed8 May 2, 2025
d27f2e1
added order model, repository, service and controller
MohammmedAhmed8 May 3, 2025
05f9c90
fixed linter issues
MohammmedAhmed8 May 3, 2025
c26372d
Add endpoints to get orders by user ID, cancel orders, and update ord…
oaly2 May 4, 2025
da784fc
Fix linter issue
oaly2 May 4, 2025
5d20343
Resolve Comments
oaly2 May 4, 2025
8cc4b16
Adjusted lint checks
oaly2 May 4, 2025
7191cb3
added swagger and logger in the controller
MohammmedAhmed8 May 6, 2025
3542af2
Merge branch 'dev' into Crud-Operations
MohammmedAhmed8 May 6, 2025
fd5c1e5
fixed linter issues
MohammmedAhmed8 May 6, 2025
a5423a9
Added Global Exception Handler and Endpoint to Check out an order
oaly2 May 8, 2025
71d8612
Create docker-compose.yml
oaly2 May 10, 2025
ae077b0
Add DockerFile
oaly2 May 11, 2025
5e4bb96
Removed Checkout endpoint and Adjusted OrderStatus enum
oaly2 May 12, 2025
94a14a8
added order address
MohammmedAhmed8 May 12, 2025
afcea40
fixed linter issues
MohammmedAhmed8 May 12, 2025
7a36737
Merge branch 'dev' into Omar/3-endpoints
oaly2 May 12, 2025
306e5a9
Merge branch 'Crud-Operations' into Omar/3-endpoints
oaly2 May 12, 2025
d8dd9ff
Merge pull request #3 from Podzilla/Omar/3-endpoints
oaly2 May 12, 2025
e881d83
fixed errors
MohammmedAhmed8 May 12, 2025
c911c79
Chnage long -> UUID in OrderService
oaly2 May 12, 2025
3bf3427
Merge branch 'Crud-Operations' of https://github.com/Podzilla/order i…
oaly2 May 12, 2025
667adea
long -> UUID in OrderController
oaly2 May 12, 2025
5950a26
Add stock reservation and order placed messaging via RabbitMQ
oaly2 May 13, 2025
7d6888d
modified order consumer and order producer
MohammmedAhmed8 May 17, 2025
61eb999
removed unused classes
MohammmedAhmed8 May 17, 2025
b7c78d0
fixed linter issues
MohammmedAhmed8 May 17, 2025
d5ac88e
added track order
MohammmedAhmed8 May 17, 2025
db27a0b
modified get location url
MohammmedAhmed8 May 17, 2025
de6f836
Merge branch 'dev' into Crud-Operations
MohammmedAhmed8 May 17, 2025
784d7d4
fixed linter issue
MohammmedAhmed8 May 17, 2025
76687d4
added confirmation type, fixed linter issue
MohammmedAhmed8 May 17, 2025
4ffb195
added order long - lat
MohammmedAhmed8 May 17, 2025
bbeff45
fixed linter issue
MohammmedAhmed8 May 17, 2025
b5740a3
fixed run errors
MohammmedAhmed8 May 17, 2025
cbebb5b
Merge branch 'dev' into Crud-Operations
MohammmedAhmed8 May 17, 2025
21594a8
Added Builder design pattern
oaly2 May 17, 2025
3653097
deleted rabbitmq file
MohammmedAhmed8 May 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
- order_db
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://order_db:5432/orderDB
- SPRING_DATASOURCE_USERNAME=postgres
- SPRING_DATASOURCE_PASSWORD=1234
volumes:
- ./target:/app
- ./logs:/logs
Expand All @@ -30,25 +32,6 @@ services:
- "15672:15672"
- "5672:5672"
environment:
RABBITMQ_DEFAULT_USER: user
RABBITMQ_DEFAULT_PASS: password
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest

loki:
image: grafana/loki:3.5.0
container_name: loki
ports:
- "3100:3100"
command: -config.file=/etc/loki/local-config.yaml

grafana:
image: grafana/grafana:10.4.1
container_name: grafana
ports:
- "3000:3000"
depends_on:
- loki
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
volumes:
- grafana_data:/var/lib/grafana
17 changes: 6 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,15 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-security</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
Expand All @@ -12,22 +10,6 @@
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {


@ExceptionHandler(AccessDeniedException.class)
public ResponseEntity<ErrorResponse> handleAccessDeniedException(
final AccessDeniedException exception) {
return ResponseEntity.status(HttpStatus.FORBIDDEN)
.body(new ErrorResponse(exception.getMessage(),
HttpStatus.FORBIDDEN));
}

@ExceptionHandler(AuthenticationException.class)
public ResponseEntity<ErrorResponse> handleAuthenticationException(
final AuthenticationException exception) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
.body(new ErrorResponse(exception.getMessage(),
HttpStatus.UNAUTHORIZED));
}

@ExceptionHandler(NotFoundException.class)
public ResponseEntity<ErrorResponse> handleNotFoundException(
final NotFoundException exception) {
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/com/podzilla/order/messaging/OrderConsumer.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,17 @@ private void handleCartCheckoutEvent(
product.setPricePerUnit(orderProduct.getPricePerUnit());
return product;
}).toList();
Order order = new Order();
order.setUserId(UUID.fromString(cartCheckedoutEvent.getCustomerId()));
order.setTotalAmount(cartCheckedoutEvent.getTotalAmount());
order.setStatus(OrderStatus.PENDING);
order.setShippingAddress(address);
order.setOrderProducts(orderProducts);
order.setConfirmationType(cartCheckedoutEvent.getConfirmationType());
order.setSignature(cartCheckedoutEvent.getSignature());
order.setOrderLatitude(cartCheckedoutEvent.getOrderLatitude());
order.setOrderLongitude(cartCheckedoutEvent.getOrderLongitude());
Order order = new Order.Builder()
.userId(UUID.fromString(cartCheckedoutEvent.getCustomerId()))
.totalAmount(cartCheckedoutEvent.getTotalAmount())
.status(OrderStatus.PENDING)
.shippingAddress(address)
.orderProducts(orderProducts)
.confirmationType(cartCheckedoutEvent.getConfirmationType())
.signature(cartCheckedoutEvent.getSignature())
.orderLatitude(cartCheckedoutEvent.getOrderLatitude())
.orderLongitude(cartCheckedoutEvent.getOrderLongitude())
.build();
orderService.createOrder(order);
}

Expand All @@ -130,7 +131,7 @@ private void handleOrderAssignedToCourierEvent(final OrderAssignedToCourierEvent
orderAssignedToCourierEvent.getOrderId());
orderService.updateOrder(
UUID.fromString(orderAssignedToCourierEvent.getOrderId()),
Order.builder()
new Order.Builder()
.courierId(UUID.fromString(orderAssignedToCourierEvent.getCourierId()))
.status(OrderStatus.ORDER_ASSIGNED_TO_COURIER)
.build());
Expand All @@ -147,7 +148,7 @@ private void handleOrderOutForDeliveryEvent(final OrderOutForDeliveryEvent order
log.info("✅ Order out for delivery for order: {}", orderOutForDeliveryEvent.getOrderId());
orderService.updateOrder(
UUID.fromString(orderOutForDeliveryEvent.getOrderId()),
Order.builder()
new Order.Builder()
.courierId(UUID.fromString(orderOutForDeliveryEvent.getCourierId()))
.status(OrderStatus.OUT_FOR_DELIVERY)
.build());
Expand Down
68 changes: 0 additions & 68 deletions src/main/java/com/podzilla/order/messaging/RabbitMQConfig.java

This file was deleted.

101 changes: 99 additions & 2 deletions src/main/java/com/podzilla/order/model/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import jakarta.persistence.GenerationType;
import com.podzilla.mq.events.ConfirmationType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
Expand All @@ -30,7 +29,6 @@
@AllArgsConstructor
@Getter
@Setter
@Builder
public class Order {

@Id
Expand Down Expand Up @@ -64,4 +62,103 @@ public class Order {
@OneToMany(mappedBy = "order", cascade = CascadeType.ALL,
orphanRemoval = true)
private List<OrderProduct> orderProducts = new ArrayList<>();

public static class Builder {
private UUID id;
private UUID userId;
private UUID courierId;
private BigDecimal totalAmount;
private Address shippingAddress;
private OrderStatus status;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private ConfirmationType confirmationType;
private String signature;
private double orderLatitude;
private double orderLongitude;
private List<OrderProduct> orderProducts = new ArrayList<>();

public Builder id(final UUID id) {
this.id = id;
return this;
}

public Builder userId(final UUID userId) {
this.userId = userId;
return this;
}

public Builder courierId(final UUID courierId) {
this.courierId = courierId;
return this;
}

public Builder totalAmount(final BigDecimal totalAmount) {
this.totalAmount = totalAmount;
return this;
}

public Builder shippingAddress(final Address shippingAddress) {
this.shippingAddress = shippingAddress;
return this;
}

public Builder status(final OrderStatus status) {
this.status = status;
return this;
}

public Builder createdAt(final LocalDateTime createdAt) {
this.createdAt = createdAt;
return this;
}

public Builder updatedAt(final LocalDateTime updatedAt) {
this.updatedAt = updatedAt;
return this;
}

public Builder confirmationType(final ConfirmationType confirmationType) {
this.confirmationType = confirmationType;
return this;
}

public Builder signature(final String signature) {
this.signature = signature;
return this;
}

public Builder orderLatitude(final double orderLatitude) {
this.orderLatitude = orderLatitude;
return this;
}

public Builder orderLongitude(final double orderLongitude) {
this.orderLongitude = orderLongitude;
return this;
}

public Builder orderProducts(final List<OrderProduct> orderProducts) {
this.orderProducts = orderProducts;
return this;
}

public Order build() {
Order order = new Order();
order.setId(id);
order.setUserId(userId);
order.setCourierId(courierId);
order.setTotalAmount(totalAmount);
order.setShippingAddress(shippingAddress);
order.setStatus(status);
order.setCreatedAt(createdAt);
order.setUpdatedAt(updatedAt);
order.setConfirmationType(confirmationType);
order.setSignature(signature);
order.setOrderLatitude(orderLatitude);
order.setOrderLongitude(orderLongitude);
order.setOrderProducts(orderProducts);
return order;
}
}
}
6 changes: 5 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
spring.application.name=order
api.gateway.url=http://localhost:8080
api.gateway.url=http://localhost:8080
spring.rabbitmq.host=rabbitmq
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
4 changes: 2 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ spring:
rabbitmq:
host: rabbitmq # container name
port: 5672
username: user
password: password
username: guest
password: guest