Change update behaviour
This commit is contained in:
parent
ded0e8e1c8
commit
6a632238d5
18
surveys.go
18
surveys.go
@ -157,13 +157,13 @@ func getSurvey(id int) (s Survey, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSurvey(title string, promo uint, shown bool, startAvailability time.Time, endAvailability time.Time) (Survey, error) {
|
func NewSurvey(title string, promo uint, shown bool, startAvailability time.Time, endAvailability time.Time) (*Survey, error) {
|
||||||
if res, err := DBExec("INSERT INTO surveys (title, promo, shown, start_availability, end_availability) VALUES (?, ?, ?, ?, ?)", title, promo, shown, startAvailability, endAvailability); err != nil {
|
if res, err := DBExec("INSERT INTO surveys (title, promo, shown, start_availability, end_availability) VALUES (?, ?, ?, ?, ?)", title, promo, shown, startAvailability, endAvailability); err != nil {
|
||||||
return Survey{}, err
|
return nil, err
|
||||||
} else if sid, err := res.LastInsertId(); err != nil {
|
} else if sid, err := res.LastInsertId(); err != nil {
|
||||||
return Survey{}, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
return Survey{sid, title, promo, shown, false, startAvailability, endAvailability}, nil
|
return &Survey{sid, title, promo, shown, false, startAvailability, endAvailability}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,13 +200,11 @@ func (s Survey) GetScores() (scores map[int64]*float64, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Survey) Update() (int64, error) {
|
func (s *Survey) Update() (*Survey, error) {
|
||||||
if res, err := DBExec("UPDATE surveys SET title = ?, promo = ?, shown = ?, corrected = ?, start_availability = ?, end_availability = ? WHERE id_survey = ?", s.Title, s.Promo, s.Shown, s.Corrected, s.StartAvailability, s.EndAvailability, s.Id); err != nil {
|
if _, err := DBExec("UPDATE surveys SET title = ?, promo = ?, shown = ?, corrected = ?, start_availability = ?, end_availability = ? WHERE id_survey = ?", s.Title, s.Promo, s.Shown, s.Corrected, s.StartAvailability, s.EndAvailability, s.Id); err != nil {
|
||||||
return 0, err
|
return nil, err
|
||||||
} else if nb, err := res.RowsAffected(); err != nil {
|
|
||||||
return 0, err
|
|
||||||
} else {
|
} else {
|
||||||
return nb, err
|
return s, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user