From d30197c4eadc348c74c722f81e0da88edff475ea Mon Sep 17 00:00:00 2001 From: blaz-cerpnjak Date: Wed, 10 Apr 2024 09:23:02 +0200 Subject: [PATCH] Add image field to product --- API_GatewayWeb/DataStructures/main.go | 1 + API_GatewayWeb/DataStructures/order_service.proto | 1 + .../src/main/kotlin/com/blazc/model/product/Product.kt | 10 +++++++--- OrderProcessingAPI/src/main/proto/order_service.proto | 1 + .../kotlin/com/blazc/controller/ProductController.kt | 6 ++++++ .../src/main/kotlin/com/blazc/model/Product.kt | 1 + 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/API_GatewayWeb/DataStructures/main.go b/API_GatewayWeb/DataStructures/main.go index 8b02098..4003968 100644 --- a/API_GatewayWeb/DataStructures/main.go +++ b/API_GatewayWeb/DataStructures/main.go @@ -26,6 +26,7 @@ type Product struct { RestaurantId primitive.ObjectID `json:"restaurantId" bson:"restaurantId"` Name string `json:"name" bson:"name"` Price int32 `json:"price" bson:"price"` // in cents + Image string `json:"image" bson:"image"` } type Order struct { diff --git a/API_GatewayWeb/DataStructures/order_service.proto b/API_GatewayWeb/DataStructures/order_service.proto index 18cc237..b13936b 100644 --- a/API_GatewayWeb/DataStructures/order_service.proto +++ b/API_GatewayWeb/DataStructures/order_service.proto @@ -57,6 +57,7 @@ message Product { string id = 1; string name = 2; int32 price = 3; + string image = 4; } enum PaymentType { diff --git a/OrderProcessingAPI/src/main/kotlin/com/blazc/model/product/Product.kt b/OrderProcessingAPI/src/main/kotlin/com/blazc/model/product/Product.kt index 8857a6f..b60d2df 100644 --- a/OrderProcessingAPI/src/main/kotlin/com/blazc/model/product/Product.kt +++ b/OrderProcessingAPI/src/main/kotlin/com/blazc/model/product/Product.kt @@ -7,13 +7,15 @@ import org.bson.types.ObjectId data class Product( var id: ObjectId? = null, var name: String, - var price: Int // 100 = 1 + var price: Int, // 100 = 1 + var image: String ) { constructor() : this( id = ObjectId(), name = "", - price = 0 + price = 0, + image = "" ) companion object { @@ -21,7 +23,8 @@ data class Product( return Product( id = ObjectId(productGrpc.id), name = productGrpc.name, - price = productGrpc.price + price = productGrpc.price, + image = productGrpc.image ) } @@ -30,6 +33,7 @@ data class Product( .setId(product.id.toString()) .setName(product.name) .setPrice(product.price) + .setImage(product.image) .build() } } diff --git a/OrderProcessingAPI/src/main/proto/order_service.proto b/OrderProcessingAPI/src/main/proto/order_service.proto index 32487b7..6675345 100644 --- a/OrderProcessingAPI/src/main/proto/order_service.proto +++ b/OrderProcessingAPI/src/main/proto/order_service.proto @@ -57,6 +57,7 @@ message Product { string id = 1; string name = 2; int32 price = 3; + string image = 4; } enum PaymentType { diff --git a/RestaurantManagementAPI/src/main/kotlin/com/blazc/controller/ProductController.kt b/RestaurantManagementAPI/src/main/kotlin/com/blazc/controller/ProductController.kt index 993aa5c..6dc69df 100644 --- a/RestaurantManagementAPI/src/main/kotlin/com/blazc/controller/ProductController.kt +++ b/RestaurantManagementAPI/src/main/kotlin/com/blazc/controller/ProductController.kt @@ -26,6 +26,12 @@ class ProductController { return productRepository.create(product) } + @GET + @Produces(MediaType.APPLICATION_JSON) + fun getAllProducts(): Uni> { + return productRepository.listAll() + } + @GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) diff --git a/RestaurantManagementAPI/src/main/kotlin/com/blazc/model/Product.kt b/RestaurantManagementAPI/src/main/kotlin/com/blazc/model/Product.kt index 80af36c..bde868c 100644 --- a/RestaurantManagementAPI/src/main/kotlin/com/blazc/model/Product.kt +++ b/RestaurantManagementAPI/src/main/kotlin/com/blazc/model/Product.kt @@ -6,5 +6,6 @@ class Product { var id: ObjectId? = null lateinit var restaurantId: ObjectId lateinit var name: String + lateinit var image: String var price: Int = 0 // 100 = 1 } \ No newline at end of file