Skip to content

Commit

Permalink
Add image field to product
Browse files Browse the repository at this point in the history
  • Loading branch information
blaz-cerpnjak committed Apr 10, 2024
1 parent c4a9939 commit d30197c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions API_GatewayWeb/DataStructures/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions API_GatewayWeb/DataStructures/order_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ message Product {
string id = 1;
string name = 2;
int32 price = 3;
string image = 4;
}

enum PaymentType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ 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 {
fun fromGrpc(productGrpc: OrderGrpc.Product): Product {
return Product(
id = ObjectId(productGrpc.id),
name = productGrpc.name,
price = productGrpc.price
price = productGrpc.price,
image = productGrpc.image
)
}

Expand All @@ -30,6 +33,7 @@ data class Product(
.setId(product.id.toString())
.setName(product.name)
.setPrice(product.price)
.setImage(product.image)
.build()
}
}
Expand Down
1 change: 1 addition & 0 deletions OrderProcessingAPI/src/main/proto/order_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ message Product {
string id = 1;
string name = 2;
int32 price = 3;
string image = 4;
}

enum PaymentType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class ProductController {
return productRepository.create(product)
}

@GET
@Produces(MediaType.APPLICATION_JSON)
fun getAllProducts(): Uni<List<Product>> {
return productRepository.listAll()
}

@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d30197c

Please sign in to comment.