diff --git a/.gitignore b/.gitignore index 524f096..269aa0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Compiled class file *.class +.gradle/ # Log file *.log diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..5d35070 --- /dev/null +++ b/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.1.0' apply false + id 'io.spring.dependency-management' version '1.1.0' apply false +} + +allprojects { + group = 'com.ofds' + version = '1.0.0-SNAPSHOT' + repositories { + mavenCentral() + } +} + +subprojects { + apply plugin: 'java' + apply plugin: 'io.spring.dependency-management' +} + diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..966603e --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,84 @@ +version: '3.8' + +services: + gateway: + build: + context: . + dockerfile: gateway/Dockerfile + container_name: gateway + ports: + - "8080:8080" + depends_on: + - order-service + - restaurant-service + - delivery-service + networks: + - ofds-network + + postgres: + image: postgres:15 + container_name: ofds-postgres + environment: + POSTGRES_USER: user + POSTGRES_PASSWORD: password + POSTGRES_DB: ofds + ports: + - "5432:5432" + networks: + - ofds-network + + order-service: + build: + context: . + dockerfile: services/order-service/Dockerfile + container_name: order-service + depends_on: + - postgres + environment: + SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/ofds + SPRING_DATASOURCE_USERNAME: user + SPRING_DATASOURCE_PASSWORD: password + SPRING_JPA_HIBERNATE_DDL_AUTO: update + SPRING_JPA_SHOW_SQL: "true" + SPRING_PROFILES_ACTIVE: docker + networks: + - ofds-network + + restaurant-service: + build: + context: . + dockerfile: services/restaurant-service/Dockerfile + container_name: restaurant-service + depends_on: + - postgres + environment: + SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/ofds + SPRING_DATASOURCE_USERNAME: user + SPRING_DATASOURCE_PASSWORD: password + SPRING_JPA_HIBERNATE_DDL_AUTO: update + SPRING_JPA_SHOW_SQL: "true" + SPRING_PROFILES_ACTIVE: docker + networks: + - ofds-network + + delivery-service: + build: + context: . + dockerfile: services/delivery-service/Dockerfile + container_name: delivery-service + depends_on: + - postgres + environment: + SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/ofds + SPRING_DATASOURCE_USERNAME: user + SPRING_DATASOURCE_PASSWORD: password + SPRING_JPA_HIBERNATE_DDL_AUTO: update + SPRING_JPA_SHOW_SQL: "true" + SPRING_PROFILES_ACTIVE: docker + networks: + - ofds-network + +networks: + ofds-network: + driver: bridge + diff --git a/gateway/Dockerfile b/gateway/Dockerfile new file mode 100644 index 0000000..fcab8bd --- /dev/null +++ b/gateway/Dockerfile @@ -0,0 +1,36 @@ +# Stage 1: Build the application +FROM gradle:8.1-jdk17 AS builder + +# Set the working directory +WORKDIR /app + +# Copy the root project files +COPY ../settings.gradle ../build.gradle ./ + +# Copy the entire project +COPY ../ . + +# Build the application using Gradle +RUN gradle :gateway:clean :gateway:bootJar -x test + +# Stage 2: Create a lightweight image to run the application +FROM openjdk:17-jdk-slim + +# Create a user to run the application +RUN useradd -m appuser + +# Set the working directory +WORKDIR /app + +# Copy the built JAR file from the build stage +COPY --from=builder /app/gateway/build/libs/*.jar app.jar + +# Expose the application port +EXPOSE 8080 + +# Run the application as the created user +USER appuser + +# Start the application +ENTRYPOINT ["java", "-jar", "app.jar"] + diff --git a/gateway/build.gradle b/gateway/build.gradle new file mode 100644 index 0000000..390e691 --- /dev/null +++ b/gateway/build.gradle @@ -0,0 +1,28 @@ +plugins { + id 'org.springframework.boot' version '3.1.0' + id 'io.spring.dependency-management' + id 'java' +} + +springBoot { + mainClass = 'com.ofds.gateway.GatewayApplication' +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-webflux' + implementation 'org.springframework.cloud:spring-cloud-starter-gateway' + implementation 'org.springframework.boot:spring-boot-starter-actuator' + + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} + +dependencyManagement { + imports { + mavenBom "org.springframework.cloud:spring-cloud-dependencies:2022.0.3" + } +} + diff --git a/gateway/src/main/java/com/odfs/gateway/GatewayApplication.java b/gateway/src/main/java/com/odfs/gateway/GatewayApplication.java new file mode 100644 index 0000000..5526a81 --- /dev/null +++ b/gateway/src/main/java/com/odfs/gateway/GatewayApplication.java @@ -0,0 +1,12 @@ +package com.ofds.gateway; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class GatewayApplication { + public static void main(String[] args) { + SpringApplication.run(GatewayApplication.class, args); + } +} + diff --git a/gateway/src/main/resources/application.yml b/gateway/src/main/resources/application.yml new file mode 100644 index 0000000..5273656 --- /dev/null +++ b/gateway/src/main/resources/application.yml @@ -0,0 +1,22 @@ +server: + port: 8080 + +spring: + application: + name: api-gateway + cloud: + gateway: + routes: + - id: order-service + 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: + - Path=/api/deliveries/** + diff --git a/scripts/delivery.sh b/scripts/delivery.sh new file mode 100644 index 0000000..d8fcd50 --- /dev/null +++ b/scripts/delivery.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# create new delivery +curl -X POST http://localhost:8080/api/deliveries \ + -H "Content-Type: application/json" \ + -d '{"orderId": 1, "driverName": "John Doe", "status": "Pending"}' + + +# list all deliveries +curl http://localhost:8080/api/deliveries + +# update delivery status +curl -X PUT http://localhost:8080/api/deliveries/1/status \ + -H "Content-Type: application/json" \ + -d '"Delivered"' + +# get specific delivery by id +curl http://localhost:8080/api/deliveries/1 + + diff --git a/scripts/orders.sh b/scripts/orders.sh new file mode 100644 index 0000000..6ed513a --- /dev/null +++ b/scripts/orders.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# create new order +curl -X POST http://localhost:8080/api/orders \ + -H "Content-Type: application/json" \ + -d '{"customerName": "John Doe", "dishName": "Margherita Pizza", "status": "Pending"}' + +# list all orders +curl http://localhost:8080/api/orders + +# get a specific order by id +curl http://localhost:8080/api/orders/1 + +# update order status +curl -X PUT http://localhost:8080/api/orders/1/status \ + -H "Content-Type: application/json" \ + -d '"Delivered"' + +# delete an order +curl -X DELETE http://localhost:8080/api/orders/1 + + diff --git a/scripts/restaurant.sh b/scripts/restaurant.sh new file mode 100644 index 0000000..7419fbb --- /dev/null +++ b/scripts/restaurant.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# create new restaurant +curl -X POST http://localhost:8080/api/restaurants \ + -H "Content-Type: application/json" \ + -d '{"name": "Pizza Palace", "location": "Cape Town", "cuisineType": "Italian"}' + + +#list all restaurants +curl http://localhost:8080/api/restaurants + + +# get a restaurant by id +curl http://localhost:8080/api/restaurants/1 + + diff --git a/services/delivery-service/Dockerfile b/services/delivery-service/Dockerfile new file mode 100644 index 0000000..3e4b7a0 --- /dev/null +++ b/services/delivery-service/Dockerfile @@ -0,0 +1,36 @@ +# Stage 1: Build the application +FROM gradle:8.1-jdk17 AS builder + +# Set the working directory +WORKDIR /app + +# Copy the root project files +COPY ../../settings.gradle ../../build.gradle ./ + +# Copy the entire project +COPY ../../ . + +# Build the application using Gradle +RUN gradle :services:delivery-service:clean :services:delivery-service:bootJar -x test + +# Stage 2: Create a lightweight image to run the application +FROM openjdk:17-jdk-slim + +# Create a user to run the application +RUN useradd -m appuser + +# Set the working directory +WORKDIR /app + +# Copy the built JAR file from the build stage +COPY --from=builder /app/services/delivery-service/build/libs/*.jar app.jar + +# Expose the application port +EXPOSE 8083 + +# Run the application as the created user +USER appuser + +# Start the application +ENTRYPOINT ["java", "-jar", "app.jar"] + diff --git a/services/delivery-service/build.gradle b/services/delivery-service/build.gradle new file mode 100644 index 0000000..cad2333 --- /dev/null +++ b/services/delivery-service/build.gradle @@ -0,0 +1,26 @@ +plugins { + id 'org.springframework.boot' version '3.1.0' + id 'io.spring.dependency-management' + id 'java' +} + +springBoot { + mainClass = 'com.ofds.delivery.DeliveryServiceApplication' +} + +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.postgresql:postgresql' + + compileOnly 'org.projectlombok:lombok:1.18.28' + annotationProcessor 'org.projectlombok:lombok:1.18.28' + + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} + diff --git a/services/delivery-service/src/main/java/com/ofds/delivery/DeliveryServiceApplication.java b/services/delivery-service/src/main/java/com/ofds/delivery/DeliveryServiceApplication.java new file mode 100644 index 0000000..15578ae --- /dev/null +++ b/services/delivery-service/src/main/java/com/ofds/delivery/DeliveryServiceApplication.java @@ -0,0 +1,12 @@ +package com.ofds.delivery; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DeliveryServiceApplication { + public static void main(String[] args) { + SpringApplication.run(DeliveryServiceApplication.class, args); + } +} + diff --git a/services/delivery-service/src/main/java/com/ofds/delivery/controller/DeliveryController.java b/services/delivery-service/src/main/java/com/ofds/delivery/controller/DeliveryController.java new file mode 100644 index 0000000..1640b5a --- /dev/null +++ b/services/delivery-service/src/main/java/com/ofds/delivery/controller/DeliveryController.java @@ -0,0 +1,38 @@ +package com.ofds.delivery.controller; + +import com.ofds.delivery.model.Delivery; +import com.ofds.delivery.repository.DeliveryRepository; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/deliveries") +public class DeliveryController { + + private final DeliveryRepository deliveryRepository; + + public DeliveryController(DeliveryRepository deliveryRepository) { + this.deliveryRepository = deliveryRepository; + } + + @PostMapping + public Delivery createDelivery(@RequestBody Delivery delivery) { + delivery.setStatus("Pending"); + return deliveryRepository.save(delivery); + } + + @GetMapping + public List listDeliveries() { + return deliveryRepository.findAll(); + } + + @PutMapping("/{id}/status") + public Delivery updateStatus(@PathVariable Long id, @RequestBody String status) { + return deliveryRepository.findById(id).map(delivery -> { + delivery.setStatus(status); + return deliveryRepository.save(delivery); + }).orElse(null); + } +} + diff --git a/services/delivery-service/src/main/java/com/ofds/delivery/model/Delivery.java b/services/delivery-service/src/main/java/com/ofds/delivery/model/Delivery.java new file mode 100644 index 0000000..8a86d83 --- /dev/null +++ b/services/delivery-service/src/main/java/com/ofds/delivery/model/Delivery.java @@ -0,0 +1,18 @@ +package com.ofds.delivery.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import lombok.Data; + +@Entity +@Data +public class Delivery { + @Id + @GeneratedValue + private Long id; + private Long orderId; + private String driverName; + private String status; +} + diff --git a/services/delivery-service/src/main/java/com/ofds/delivery/repository/DeliveryRepository.java b/services/delivery-service/src/main/java/com/ofds/delivery/repository/DeliveryRepository.java new file mode 100644 index 0000000..1d15108 --- /dev/null +++ b/services/delivery-service/src/main/java/com/ofds/delivery/repository/DeliveryRepository.java @@ -0,0 +1,8 @@ +package com.ofds.delivery.repository; + +import com.ofds.delivery.model.Delivery; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface DeliveryRepository extends JpaRepository { +} + diff --git a/services/delivery-service/src/main/resources/application.yml b/services/delivery-service/src/main/resources/application.yml new file mode 100644 index 0000000..876e107 --- /dev/null +++ b/services/delivery-service/src/main/resources/application.yml @@ -0,0 +1,13 @@ +server: + port: 8083 + +spring: + datasource: + url: jdbc:postgresql://postgres:5432/ofds + username: user + password: password + jpa: + hibernate: + ddl-auto: update + show-sql: true + diff --git a/services/order-service/Dockerfile b/services/order-service/Dockerfile new file mode 100644 index 0000000..c00fed7 --- /dev/null +++ b/services/order-service/Dockerfile @@ -0,0 +1,36 @@ +# Stage 1: Build the application using Gradle +FROM gradle:8.1-jdk17 AS builder + +# Set the working directory +WORKDIR /app + +# Copy the root project files +COPY ../../settings.gradle ../../build.gradle ./ + +# Copy the entire project (including submodules and services) +COPY ../../ . + +# Build only the order-service module +RUN gradle :services:order-service:clean :services:order-service:bootJar -x test + +# Stage 2: Create a lightweight image to run the application +FROM openjdk:17-jdk-slim + +# Create a user for running the application +RUN useradd -m appuser + +# Set the working directory +WORKDIR /app + +# Copy the built JAR file from the build stage +COPY --from=builder /app/services/order-service/build/libs/*.jar app.jar + +# Expose the application port +EXPOSE 8081 + +# Run the application as the created user +USER appuser + +# Start the application +ENTRYPOINT ["java", "-jar", "app.jar"] + diff --git a/services/order-service/build.gradle b/services/order-service/build.gradle new file mode 100644 index 0000000..fe62f6d --- /dev/null +++ b/services/order-service/build.gradle @@ -0,0 +1,26 @@ +plugins { + id 'org.springframework.boot' version '3.1.0' + id 'io.spring.dependency-management' + id 'java' +} + +springBoot { + mainClass = 'com.ofds.order.OrderServiceApplication' +} + +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.postgresql:postgresql' + + compileOnly 'org.projectlombok:lombok:1.18.28' + annotationProcessor 'org.projectlombok:lombok:1.18.28' + + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} + diff --git a/services/order-service/src/main/java/com/ofds/order/OrderServiceApplication.java b/services/order-service/src/main/java/com/ofds/order/OrderServiceApplication.java new file mode 100644 index 0000000..1987be8 --- /dev/null +++ b/services/order-service/src/main/java/com/ofds/order/OrderServiceApplication.java @@ -0,0 +1,12 @@ +package com.ofds.order; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class OrderServiceApplication { + public static void main(String[] args) { + SpringApplication.run(OrderServiceApplication.class, args); + } +} + diff --git a/services/order-service/src/main/java/com/ofds/order/controller/OrderController.java b/services/order-service/src/main/java/com/ofds/order/controller/OrderController.java new file mode 100644 index 0000000..c2eb378 --- /dev/null +++ b/services/order-service/src/main/java/com/ofds/order/controller/OrderController.java @@ -0,0 +1,43 @@ +package com.ofds.order.controller; + +import com.ofds.order.model.Order; +import com.ofds.order.repository.OrderRepository; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/orders") +public class OrderController { + + private final OrderRepository orderRepository; + + public OrderController(OrderRepository orderRepository) { + this.orderRepository = orderRepository; + } + + @PostMapping + public Order createOrder(@RequestBody Order order) { + order.setStatus("Pending"); + return orderRepository.save(order); + } + + @GetMapping + public List listOrders() { + return orderRepository.findAll(); + } + + @GetMapping("/{id}") + public Order getOrderById(@PathVariable Long id) { + return orderRepository.findById(id).orElse(null); + } + + @PutMapping("/{id}/status") + public Order updateOrderStatus(@PathVariable Long id, @RequestBody String status) { + return orderRepository.findById(id).map(order -> { + order.setStatus(status.replaceAll("\"", "")); // Remove extra quotes from JSON + return orderRepository.save(order); + }).orElse(null); + } +} + diff --git a/services/order-service/src/main/java/com/ofds/order/model/Order.java b/services/order-service/src/main/java/com/ofds/order/model/Order.java new file mode 100644 index 0000000..55e4bab --- /dev/null +++ b/services/order-service/src/main/java/com/ofds/order/model/Order.java @@ -0,0 +1,20 @@ +package com.ofds.order.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.Data; + +@Entity +@Table(name = "customer_order") +@Data +public class Order { + @Id + @GeneratedValue + private Long id; + private String customerName; + private String dishName; + private String status; +} + diff --git a/services/order-service/src/main/java/com/ofds/order/repository/OrderRepository.java b/services/order-service/src/main/java/com/ofds/order/repository/OrderRepository.java new file mode 100644 index 0000000..837cdac --- /dev/null +++ b/services/order-service/src/main/java/com/ofds/order/repository/OrderRepository.java @@ -0,0 +1,8 @@ +package com.ofds.order.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import com.ofds.order.model.Order; + +public interface OrderRepository extends JpaRepository { +} + diff --git a/services/order-service/src/main/java/com/ofds/order/service/OrderService.java b/services/order-service/src/main/java/com/ofds/order/service/OrderService.java new file mode 100644 index 0000000..fc69c12 --- /dev/null +++ b/services/order-service/src/main/java/com/ofds/order/service/OrderService.java @@ -0,0 +1,20 @@ +package com.ofds.order.service; + +import com.ofds.order.model.Order; +import com.ofds.order.repository.OrderRepository; +import org.springframework.stereotype.Service; + +@Service +public class OrderService { + private final OrderRepository orderRepository; + + public OrderService(OrderRepository orderRepository) { + this.orderRepository = orderRepository; + } + + public Order createOrder(Order order) { + order.setStatus("Pending"); + return orderRepository.save(order); + } +} + diff --git a/services/order-service/src/main/resources/application.yml b/services/order-service/src/main/resources/application.yml new file mode 100644 index 0000000..8d488b4 --- /dev/null +++ b/services/order-service/src/main/resources/application.yml @@ -0,0 +1,14 @@ +server: + port: 8081 + +spring: + datasource: + url: jdbc:postgresql://localhost:5432/ofds + username: user + password: password + jpa: + hibernate: + ddl-auto: update + show-sql: true + database-platform: org.hibernate.dialect.PostgreSQLDialect + diff --git a/services/restaurant-service/Dockerfile b/services/restaurant-service/Dockerfile new file mode 100644 index 0000000..64afd9f --- /dev/null +++ b/services/restaurant-service/Dockerfile @@ -0,0 +1,36 @@ +# Stage 1: Build the application +FROM gradle:8.1-jdk17 AS builder + +# Set the working directory +WORKDIR /app + +# Copy the root project files +COPY ../../settings.gradle ../../build.gradle ./ + +# Copy the entire project +COPY ../../ . + +# Build the application using Gradle +RUN gradle :services:restaurant-service:clean :services:restaurant-service:bootJar -x test + +# Stage 2: Create a lightweight image to run the application +FROM openjdk:17-jdk-slim + +# Create a user to run the application +RUN useradd -m appuser + +# Set the working directory +WORKDIR /app + +# Copy the built JAR file from the build stage +COPY --from=builder /app/services/restaurant-service/build/libs/*.jar app.jar + +# Expose the application port +EXPOSE 8082 + +# Run the application as the created user +USER appuser + +# Start the application +ENTRYPOINT ["java", "-jar", "app.jar"] + diff --git a/services/restaurant-service/build.gradle b/services/restaurant-service/build.gradle new file mode 100644 index 0000000..bcf4b23 --- /dev/null +++ b/services/restaurant-service/build.gradle @@ -0,0 +1,26 @@ +plugins { + id 'org.springframework.boot' version '3.1.0' + id 'io.spring.dependency-management' + id 'java' +} + +springBoot { + mainClass = 'com.ofds.restaurant.RestaurantServiceApplication' +} + +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.postgresql:postgresql' + + compileOnly 'org.projectlombok:lombok:1.18.28' + annotationProcessor 'org.projectlombok:lombok:1.18.28' + + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} + diff --git a/services/restaurant-service/src/main/java/com/ofds/restaurant/RestaurantServiceApplication.java b/services/restaurant-service/src/main/java/com/ofds/restaurant/RestaurantServiceApplication.java new file mode 100644 index 0000000..bc479d7 --- /dev/null +++ b/services/restaurant-service/src/main/java/com/ofds/restaurant/RestaurantServiceApplication.java @@ -0,0 +1,12 @@ +package com.ofds.restaurant; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RestaurantServiceApplication { + public static void main(String[] args) { + SpringApplication.run(RestaurantServiceApplication.class, args); + } +} + diff --git a/services/restaurant-service/src/main/java/com/ofds/restaurant/controller/RestaurantController.java b/services/restaurant-service/src/main/java/com/ofds/restaurant/controller/RestaurantController.java new file mode 100644 index 0000000..50ed9f1 --- /dev/null +++ b/services/restaurant-service/src/main/java/com/ofds/restaurant/controller/RestaurantController.java @@ -0,0 +1,34 @@ +package com.ofds.restaurant.controller; + +import com.ofds.restaurant.model.Restaurant; +import com.ofds.restaurant.repository.RestaurantRepository; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/restaurants") +public class RestaurantController { + + private final RestaurantRepository restaurantRepository; + + public RestaurantController(RestaurantRepository restaurantRepository) { + this.restaurantRepository = restaurantRepository; + } + + @PostMapping + public Restaurant addRestaurant(@RequestBody Restaurant restaurant) { + return restaurantRepository.save(restaurant); + } + + @GetMapping + public List listRestaurants() { + return restaurantRepository.findAll(); + } + + @GetMapping("/{id}") + public Restaurant getRestaurant(@PathVariable Long id) { + return restaurantRepository.findById(id).orElse(null); + } +} + diff --git a/services/restaurant-service/src/main/java/com/ofds/restaurant/model/Restaurant.java b/services/restaurant-service/src/main/java/com/ofds/restaurant/model/Restaurant.java new file mode 100644 index 0000000..dbe7f4e --- /dev/null +++ b/services/restaurant-service/src/main/java/com/ofds/restaurant/model/Restaurant.java @@ -0,0 +1,18 @@ +package com.ofds.restaurant.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import lombok.Data; + +@Entity +@Data +public class Restaurant { + @Id + @GeneratedValue + private Long id; + private String name; + private String location; + private String cuisineType; +} + diff --git a/services/restaurant-service/src/main/java/com/ofds/restaurant/repository/RestaurantRepository.java b/services/restaurant-service/src/main/java/com/ofds/restaurant/repository/RestaurantRepository.java new file mode 100644 index 0000000..2c43863 --- /dev/null +++ b/services/restaurant-service/src/main/java/com/ofds/restaurant/repository/RestaurantRepository.java @@ -0,0 +1,8 @@ +package com.ofds.restaurant.repository; + +import com.ofds.restaurant.model.Restaurant; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RestaurantRepository extends JpaRepository { +} + diff --git a/services/restaurant-service/src/main/resources/application.yml b/services/restaurant-service/src/main/resources/application.yml new file mode 100644 index 0000000..fd5bfc9 --- /dev/null +++ b/services/restaurant-service/src/main/resources/application.yml @@ -0,0 +1,13 @@ +server: + port: 8082 + +spring: + datasource: + url: jdbc:postgresql://postgres:5432/ofds + username: user + password: password + jpa: + hibernate: + ddl-auto: update + show-sql: true + diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..800d04f --- /dev/null +++ b/settings.gradle @@ -0,0 +1,3 @@ +rootProject.name = 'ofds' +include 'common', 'services:order-service', 'services:restaurant-service', 'services:delivery-service', 'gateway' +