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() {
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")
}
......@@ -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:"-"`
}
File moved
......@@ -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"`
}
......@@ -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")
......
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