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

files umbenannt

parent a05cda03
No related branches found
No related tags found
No related merge requests found
File moved
File moved
File moved
......@@ -4,7 +4,7 @@ import "gorm.io/gorm"
type ShoppingCart struct {
gorm.Model
Positionen []Position `gorm:"foreignKey:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Positions []Position `gorm:"foreignKey:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Totalprice float64 `gorm:"notNull;default:0.0"`
Username string `gorm:"unique"`
}
File moved
File moved
......@@ -38,7 +38,7 @@ func (s *ShoppingCartService) CreateShoppingCart(ShoppingCart model.ShoppingCart
func (s *ShoppingCartService) AddProductToShoppingCart(username string, ProductID uint, amount int) (*model.ShoppingCart, error) {
//Get ShoppingCart
ShoppingCart := &model.ShoppingCart{}
result := db.DB.Preload("Positionen").Where("username = ?", username).First(ShoppingCart)
result := db.DB.Preload("Positions").Where("username = ?", username).First(ShoppingCart)
if result.Error != nil {
log.Errorf("Could not find Shoppingcart of User %v", username)
return nil, result.Error
......@@ -63,7 +63,7 @@ func (s *ShoppingCartService) AddProductToShoppingCart(username string, ProductI
}
// Add position to shoppingcart
ShoppingCart.Positionen = append(ShoppingCart.Positionen, position)
ShoppingCart.Positions = append(ShoppingCart.Positions, position)
ShoppingCart.Totalprice += position.Totalprice
result = db.DB.Save(ShoppingCart)
......@@ -80,7 +80,7 @@ func (s *ShoppingCartService) AddProductToShoppingCart(username string, ProductI
func (s *ShoppingCartService) TransferMoney(username string) error {
// Get shoppingcart from user
ShoppingCart := &model.ShoppingCart{}
result := db.DB.Preload("Positionen").Where("username = ?", username).First(ShoppingCart)
result := db.DB.Preload("Positions").Where("username = ?", username).First(ShoppingCart)
if result.Error != nil {
log.Errorf("Could not find Shoppingcart of User %v", username)
return result.Error
......@@ -106,8 +106,8 @@ func (s *ShoppingCartService) TransferMoney(username string) error {
}
// Set Shoppingcart to default
for i := range ShoppingCart.Positionen {
ShoppingCart.Positionen[i].Amount = 0
for i := range ShoppingCart.Positions {
ShoppingCart.Positions[i].Amount = 0
}
ShoppingCart.Totalprice = 0.0
......
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