// Model
type Whatsapp struct {
ID uint `json:"id" gorm:"primaryKey;column:id"`
Label string `json:"label" gorm:"column:label"`
Code string `json:"code" gorm:"column:code"`
ApiKey string `json:"api_key" gorm:"column:apikey"`
Status string `json:"status" gorm:"column:status;default:'disconnected'"`
IsAuth bool `json:"is_auth" gorm:"column:is_auth"`
PhoneNumber string `json:"phone" gorm:"column:phone;default:null"`
Photo string `json:"photo" gorm:"column:photo;default:null"`
CreatedAt time.Time `json:"created_at" gorm:"column:created_at;default:null"`
UpdatedAt time.Time `json:"updated_at" gorm:"column:updated_at;default:null"`
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"column:deleted_at;default:null"`
}
// -----------------------------------------------------
// Ucase
whatsapp := dari database model.Whatsapp
whatsapp.Status = strings.ToLower(string(dataDevice.Device.Status)) // <- yang ini bisa
whatsapp.IsAuth = dataDevice.Device.IsAuth // <- gak bisa update
whatsapp.Photo = dataDevice.Device.Socket.PhotoProfile // <- gak bisa update
whatsapp.PhoneNumber = dataDevice.Device.Socket.PhoneNumber // <- gak bisa update
// byteJson, _ := json.Marshal(whatsapp)
// fmt.Println("whatsapp", string(byteJson))
_, uc := uc.waRepo.UpdateById(ctx, &whatsapp.ID, whatsapp)
//....
// -----------------------------------------------------
// bagian reponya
func (r *gormWhatsappRepo) UpdateById(ctx context.Context, whatsappID *uint, whatsapp *model.Whatsapp) (rowsAffected int64, err error) {
res := r.db.Model(whatsapp).Where("id = ?", whatsappID).Updates(whatsapp)
rowsAffected = res.RowsAffected
err = res.Error
return
}