Skip to content
Snippets Groups Projects
Commit 35df0958 authored by albrecht's avatar albrecht
Browse files

fixing

parent dcc07d4e
No related branches found
No related tags found
No related merge requests found
...@@ -41,13 +41,13 @@ func main() { ...@@ -41,13 +41,13 @@ func main() {
router.GET("/ratings", RatingHandler.ReadRatings) //all Ratings router.GET("/ratings", RatingHandler.ReadRatings) //all Ratings
//Bankaccount //Bankaccount
router.POST("/bankaccounts", bankAccountHandler.CreateBankAccount) // new Bankaccount router.POST("/bankaccounts", bankAccountHandler.CreateBankAccount) // new Bankaccount
router.PUT("/bankaccounts", bankAccountHandler.UpdateBankAccount) // Transfer router.PUT("/bankaccounts/transfer", bankAccountHandler.UpdateBankAccount) // Transfer
//ShoppingCart //ShoppingCart
router.POST("/ShoppingCart", ShoppingCartHandler.CreateShoppingCart) //new ShoppingCart router.POST("/shoppingcart", ShoppingCartHandler.CreateShoppingCart) //new ShoppingCart
router.POST("/ShoppingCart/Product/:id", ShoppingCartHandler.AddProductToShoppingCart) //add Product router.POST("/shoppingcart/product/:id", ShoppingCartHandler.AddProductToShoppingCart) //add Product
router.POST("/ShoppingCart/pay", ShoppingCartHandler.TransferMoney) //pay router.POST("/shoppingcart/pay", ShoppingCartHandler.TransferMoney) //pay
router.Run(":8080") router.Run(":8080")
} }
...@@ -4,8 +4,10 @@ import "gorm.io/gorm" ...@@ -4,8 +4,10 @@ import "gorm.io/gorm"
type Position struct { type Position struct {
gorm.Model gorm.Model
Amount int `gorm:"notNull"` Amount int `gorm:"notNull"`
ProductId uint `gorm:"notNull"` ProductId uint `gorm:"notNull"`
Price float64 `gorm:"notNull"` Price float64 `gorm:"notNull"`
Totalprice float64 `gorm:"notNull"` Totalprice float64 `gorm:"notNull"`
ShoppingCartId uint `gorm:"notNull"`
ShoppingCart ShoppingCart `gorm:"-"`
} }
File moved
...@@ -7,5 +7,5 @@ type Rating struct { ...@@ -7,5 +7,5 @@ type Rating struct {
Username string `gorm:"notNull"` Username string `gorm:"notNull"`
Content string `gorm:"notNull"` Content string `gorm:"notNull"`
Rating int `gorm:"notNull"` Rating int `gorm:"notNull"`
ProductId uint ProductId uint `gorm:"notNull"`
} }
...@@ -56,10 +56,11 @@ func (s *ShoppingCartService) AddProductToShoppingCart(username string, ProductI ...@@ -56,10 +56,11 @@ func (s *ShoppingCartService) AddProductToShoppingCart(username string, ProductI
gesPrice := Product.Price * float64(amount) gesPrice := Product.Price * float64(amount)
position := model.Position{ position := model.Position{
Amount: amount, Amount: amount,
ProductId: Product.ID, ProductId: Product.ID,
Price: Product.Price, Price: Product.Price,
Totalprice: gesPrice, Totalprice: gesPrice,
ShoppingCartId: ShoppingCart.ID,
} }
// Add position to shoppingcart // Add position to shoppingcart
...@@ -112,6 +113,10 @@ func (s *ShoppingCartService) TransferMoney(username string) error { ...@@ -112,6 +113,10 @@ func (s *ShoppingCartService) TransferMoney(username string) error {
ShoppingCart.Totalprice = 0.0 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) result = db.DB.Save(ShoppingCart)
if result.Error != nil { if result.Error != nil {
log.Error("Could not save Shoppingcart") log.Error("Could not save Shoppingcart")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment