Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ spring:
uri: http://order-service:8081
predicates:
- Path=/api/orders/**

- id: restaurant-service
uri: http://restaurant-service:8082
predicates:
- Path=/api/restaurants/**

- id: delivery-service
uri: http://delivery-service:8083
predicates:
Expand Down
6 changes: 3 additions & 3 deletions scripts/delivery.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bash

# create new delivery
# create new delivery linked to an order
curl -X POST http://localhost:8080/api/deliveries \
-H "Content-Type: application/json" \
-d '{"orderId": 1, "driverName": "John Doe", "status": "Pending"}'
-d '{"orderId": 1, "driverName": "Jane Doe", "status": "In Transit"}'


# list all deliveries
Expand All @@ -14,7 +14,7 @@ curl -X PUT http://localhost:8080/api/deliveries/1/status \
-H "Content-Type: application/json" \
-d '"Delivered"'

# get specific delivery by id
# get delivery details with order info
curl http://localhost:8080/api/deliveries/1


3 changes: 1 addition & 2 deletions scripts/orders.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ curl -X POST http://localhost:8080/api/orders \
-H "Content-Type: application/json" \
-d '{"customerName": "John Doe", "dishName": "Margherita Pizza", "status": "Pending", "restaurantId": 1}'


# list all orders
curl http://localhost:8080/api/orders

# get a specific order by id
# get order details with restaurant info
curl http://localhost:8080/api/orders/1

# update order status
Expand Down
1 change: 1 addition & 0 deletions services/delivery-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.postgresql:postgresql'

compileOnly 'org.projectlombok:lombok:1.18.28'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ofds.delivery.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {

@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
import com.ofds.delivery.model.Delivery;
import com.ofds.delivery.repository.DeliveryRepository;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/deliveries")
public class DeliveryController {

private final DeliveryRepository deliveryRepository;
private final RestTemplate restTemplate;

public DeliveryController(DeliveryRepository deliveryRepository) {
this.deliveryRepository = deliveryRepository;
this.restTemplate = new RestTemplate();
}

@PostMapping
Expand All @@ -27,6 +31,21 @@ public List<Delivery> listDeliveries() {
return deliveryRepository.findAll();
}

@GetMapping("/{id}")
public Map<String, Object> getDeliveryWithOrder(@PathVariable Long id) {
return deliveryRepository.findById(id).map(delivery -> {
String orderUrl = "http://gateway:8080/api/orders/" + delivery.getOrderId();
Map<String, Object> order = restTemplate.getForObject(orderUrl, Map.class);

return Map.of(
"id", delivery.getId(),
"driverName", delivery.getDriverName(),
"status", delivery.getStatus(),
"order", order
);
}).orElse(null);
}

@PutMapping("/{id}/status")
public Delivery updateStatus(@PathVariable Long id, @RequestBody String status) {
return deliveryRepository.findById(id).map(delivery -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ofds.order.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {

@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}

1 change: 1 addition & 0 deletions services/restaurant-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.postgresql:postgresql'

compileOnly 'org.projectlombok:lombok:1.18.28'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ofds.restaurant.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {

@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}