diff --git a/src/gomazon/main.go b/src/gomazon/main.go index 4306b4a809131381590a4297330d73fc5937e1a4..c3cad8f3c03519c0114f344335ad82ee2c19adda 100644 --- a/src/gomazon/main.go +++ b/src/gomazon/main.go @@ -41,13 +41,13 @@ func main() { router.GET("/ratings", RatingHandler.ReadRatings) //all Ratings //Bankaccount - router.POST("/bankaccounts", bankAccountHandler.CreateBankAccount) // new Bankaccount - router.PUT("/bankaccounts", bankAccountHandler.UpdateBankAccount) // Transfer + router.POST("/bankaccounts", bankAccountHandler.CreateBankAccount) // new Bankaccount + router.PUT("/bankaccounts/transfer", bankAccountHandler.UpdateBankAccount) // Transfer //ShoppingCart - router.POST("/ShoppingCart", ShoppingCartHandler.CreateShoppingCart) //new ShoppingCart - router.POST("/ShoppingCart/Product/:id", ShoppingCartHandler.AddProductToShoppingCart) //add Product - router.POST("/ShoppingCart/pay", ShoppingCartHandler.TransferMoney) //pay + router.POST("/shoppingcart", ShoppingCartHandler.CreateShoppingCart) //new ShoppingCart + router.POST("/shoppingcart/product/:id", ShoppingCartHandler.AddProductToShoppingCart) //add Product + router.POST("/shoppingcart/pay", ShoppingCartHandler.TransferMoney) //pay router.Run(":8080") } diff --git a/src/gomazon/model/position.go b/src/gomazon/model/position.go index aa2bdd46ff191ed4231ca4d9cdeea4d368140f6f..3e67041728962ade368b590c85c05e79fba489e6 100644 --- a/src/gomazon/model/position.go +++ b/src/gomazon/model/position.go @@ -4,8 +4,10 @@ import "gorm.io/gorm" type Position struct { gorm.Model - Amount int `gorm:"notNull"` - ProductId uint `gorm:"notNull"` - Price float64 `gorm:"notNull"` - Totalprice float64 `gorm:"notNull"` + Amount int `gorm:"notNull"` + ProductId uint `gorm:"notNull"` + Price float64 `gorm:"notNull"` + Totalprice float64 `gorm:"notNull"` + ShoppingCartId uint `gorm:"notNull"` + ShoppingCart ShoppingCart `gorm:"-"` } diff --git a/src/gomazon/model/produkt.go b/src/gomazon/model/product.go similarity index 100% rename from src/gomazon/model/produkt.go rename to src/gomazon/model/product.go diff --git a/src/gomazon/model/rating.go b/src/gomazon/model/rating.go index 81d7386c15fe82d06f6173694f075bad66d1d65a..02400e8d38e66db8d03f2320c79c14d807fb3950 100644 --- a/src/gomazon/model/rating.go +++ b/src/gomazon/model/rating.go @@ -7,5 +7,5 @@ type Rating struct { Username string `gorm:"notNull"` Content string `gorm:"notNull"` Rating int `gorm:"notNull"` - ProductId uint + ProductId uint `gorm:"notNull"` } diff --git a/src/gomazon/service/shopping_cart.go b/src/gomazon/service/shopping_cart.go index 3dd8f6ad95424d3436086aa44821222d24c55e3e..e2db2c9b0a8ae415bfdf5a25d30191a9bd8b7438 100644 --- a/src/gomazon/service/shopping_cart.go +++ b/src/gomazon/service/shopping_cart.go @@ -56,10 +56,11 @@ func (s *ShoppingCartService) AddProductToShoppingCart(username string, ProductI gesPrice := Product.Price * float64(amount) position := model.Position{ - Amount: amount, - ProductId: Product.ID, - Price: Product.Price, - Totalprice: gesPrice, + Amount: amount, + ProductId: Product.ID, + Price: Product.Price, + Totalprice: gesPrice, + ShoppingCartId: ShoppingCart.ID, } // Add position to shoppingcart @@ -112,6 +113,10 @@ func (s *ShoppingCartService) TransferMoney(username string) error { ShoppingCart.Totalprice = 0.0 + if err := db.DB.Where("shopping_cart_id = ?", ShoppingCart.Username).Delete(&model.Position{}).Error; err != nil { + return err + } + result = db.DB.Save(ShoppingCart) if result.Error != nil { log.Error("Could not save Shoppingcart")