Skip to content

Commit

Permalink
Fix problems after updating gorm to 1.24
Browse files Browse the repository at this point in the history
  • Loading branch information
Alireza Ahmadi committed Feb 20, 2023
1 parent 3e550d7 commit 40ac7d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
22 changes: 11 additions & 11 deletions web/service/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *InboundService) getClients(inbound *model.Inbound) ([]model.Client, err
settings := map[string][]model.Client{}
json.Unmarshal([]byte(inbound.Settings), &settings)
if settings == nil {
return nil, fmt.Errorf("Setting is null")
return nil, fmt.Errorf("setting is null")
}

clients := settings["clients"]
Expand Down Expand Up @@ -238,9 +238,9 @@ func (s *InboundService) AddTraffic(traffics []*xray.Traffic) (err error) {
for _, traffic := range traffics {
if traffic.IsInbound {
err = tx.Where("tag = ?", traffic.Tag).
UpdateColumn("up", gorm.Expr("up + ?", traffic.Up)).
UpdateColumn("down", gorm.Expr("down + ?", traffic.Down)).
Error
UpdateColumns(map[string]interface{}{
"up": gorm.Expr("up + ?", traffic.Up),
"down": gorm.Expr("down + ?", traffic.Down)}).Error
if err != nil {
return
}
Expand Down Expand Up @@ -298,11 +298,12 @@ func (s *InboundService) AddClientTraffic(traffics []*xray.ClientTraffic) (err e
}
}
if tx.Where("inbound_id = ?", inbound.Id).Where("email = ?", traffic.Email).
UpdateColumn("enable", true).
UpdateColumn("expiry_time", traffic.ExpiryTime).
UpdateColumn("total", traffic.Total).
UpdateColumn("up", gorm.Expr("up + ?", traffic.Up)).
UpdateColumn("down", gorm.Expr("down + ?", traffic.Down)).RowsAffected == 0 {
UpdateColumns(map[string]interface{}{
"enable": true,
"expiry_time": traffic.ExpiryTime,
"total": traffic.Total,
"up": gorm.Expr("up + ?", traffic.Up),
"down": gorm.Expr("down + ?", traffic.Down)}).RowsAffected == 0 {
err = tx.Create(traffic).Error
}

Expand Down Expand Up @@ -374,8 +375,7 @@ func (s *InboundService) ResetClientTraffic(clientEmail string) error {

result := db.Model(xray.ClientTraffic{}).
Where("email = ?", clientEmail).
Update("up", 0).
Update("down", 0)
Updates(map[string]interface{}{"up": 0, "down": 0})

err := result.Error

Expand Down
3 changes: 1 addition & 2 deletions web/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ func (s *UserService) UpdateUser(id int, username string, password string) error
db := database.GetDB()
return db.Model(model.User{}).
Where("id = ?", id).
Update("username", username).
Update("password", password).
Updates(map[string]interface{}{"username": username, "password": password}).
Error
}

Expand Down

0 comments on commit 40ac7d4

Please sign in to comment.