Finishing up changes from previous commit
This commit is contained in:
parent
c8d1d0a84f
commit
22d2b8b41d
5 changed files with 74 additions and 2 deletions
|
@ -39,3 +39,25 @@ func (s *speciesStore) List(opt *models.SpeciesListOptions) ([]*models.Species,
|
|||
}
|
||||
return species, nil
|
||||
}
|
||||
|
||||
func (s *speciesStore) Update(id int64, species *models.Species) (bool, error) {
|
||||
_, err := s.Get(id)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if id != species.Id {
|
||||
return false, models.ErrSpeciesNotFound
|
||||
}
|
||||
|
||||
changed, err := s.dbh.Update(species)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if changed == 0 {
|
||||
return false, ErrNoRowsUpdated
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
@ -111,8 +111,8 @@ func TestSpeciesStore_Update_db(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
created := &model.Species{GenusId: genus.Id, SpeciesName: "Test Species"}
|
||||
_, err := d.Species.Create(created)
|
||||
species := &models.Species{GenusId: genus.Id, SpeciesName: "Test Species"}
|
||||
created, err := d.Species.Create(species)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
Reference in a new issue