Skip to content

Commit

Permalink
Add Order and OrderItems models
Browse files Browse the repository at this point in the history
Introduced Order and OrderItems structs to manage order-related data.
  • Loading branch information
mukulmantosh committed Sep 3, 2024
1 parent 630c612 commit f4af654
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/database/database.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package database

import (
"Go_Food_Delivery/pkg/database/models/order"
"Go_Food_Delivery/pkg/database/models/restaurant"
"Go_Food_Delivery/pkg/database/models/review"
"Go_Food_Delivery/pkg/database/models/user"
Expand Down Expand Up @@ -165,6 +166,8 @@ func (d *DB) Migrate() error {
(*restaurant.Restaurant)(nil),
(*restaurant.MenuItem)(nil),
(*review.Review)(nil),
(*order.Order)(nil),
(*order.OrderItems)(nil),
}

for _, model := range models {
Expand Down
33 changes: 33 additions & 0 deletions pkg/database/models/order/order.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package order

import (
"Go_Food_Delivery/pkg/database/models/restaurant"
userModel "Go_Food_Delivery/pkg/database/models/user"
"Go_Food_Delivery/pkg/database/models/utils"
"github.com/uptrace/bun"
)

type Order struct {
bun.BaseModel `bun:"table:orders"`
OrderID int64 `bun:",pk,autoincrement" json:"order_id"`
UserID int64 `bun:"user_id,notnull" json:"user_id"`
RestaurantID int64 `bun:"restaurant_id,notnull" json:"restaurant_id"`
OrderStatus string `bun:"order_status,notnull" json:"order_status"`
TotalAmount float64 `bun:"total_amount,notnull" json:"total_amount"`
DeliveryAddress string `bun:"delivery_address,notnull" json:"delivery_address"`
utils.Timestamp
Restaurant *restaurant.Restaurant `bun:"rel:belongs-to,join:restaurant_id=restaurant_id"`
User *userModel.User `bun:"rel:belongs-to,join:user_id=id"`
}

type OrderItems struct {
bun.BaseModel `bun:"table:order_items"`
OrderItemID int64 `bun:",pk,autoincrement" json:"order_item_id"`
OrderID int64 `bun:"order_id,notnull" json:"order_id"`
ItemID int64 `bun:"item_id,notnull" json:"item_id"`
Quantity int64 `bun:"quantity,notnull" json:"quantity"`
Price float64 `bun:"price,notnull" json:"price"`
utils.Timestamp
MenuItem *restaurant.MenuItem `bun:"rel:belongs-to,join:item_id=menu_id"`
Order *Order `bun:"rel:belongs-to,join:order_id=order_id"`
}

0 comments on commit f4af654

Please sign in to comment.