Update strain. Fixed EML/EMBL typo in json.
This commit is contained in:
parent
b8bda910cd
commit
ff0e37d2ef
9 changed files with 163 additions and 2 deletions
|
@ -39,3 +39,25 @@ func (s *strainsStore) List(opt *models.StrainListOptions) ([]*models.Strain, er
|
|||
}
|
||||
return strains, nil
|
||||
}
|
||||
|
||||
func (s *strainsStore) Update(id int64, strain *models.Strain) (bool, error) {
|
||||
_, err := s.Get(id)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if id != strain.Id {
|
||||
return false, models.ErrStrainNotFound
|
||||
}
|
||||
|
||||
changed, err := s.dbh.Update(strain)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if changed == 0 {
|
||||
return false, ErrNoRowsUpdated
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
@ -87,3 +87,23 @@ func TestStrainsStore_List_db(t *testing.T) {
|
|||
t.Errorf("got strains %+v, want %+v", strains, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStrainsStore_Update_db(t *testing.T) {
|
||||
tx, _ := DB.Begin()
|
||||
defer tx.Rollback()
|
||||
|
||||
strain := insertStrain(t, tx)
|
||||
|
||||
d := NewDatastore(tx)
|
||||
|
||||
// Tweak it
|
||||
strain.StrainName = "Updated Strain"
|
||||
updated, err := d.Strains.Update(strain.Id, strain)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !updated {
|
||||
t.Error("!updated")
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue