List Observation types

This commit is contained in:
Matthew Dillon 2014-11-07 16:45:46 -09:00
parent 9326a06699
commit 186edad1db
9 changed files with 152 additions and 0 deletions

View file

@ -34,3 +34,15 @@ func (s *observationTypesStore) Create(observation_type *models.ObservationType)
}
return true, nil
}
func (s *observationTypesStore) List(opt *models.ObservationTypeListOptions) ([]*models.ObservationType, error) {
if opt == nil {
opt = &models.ObservationTypeListOptions{}
}
var observation_types []*models.ObservationType
err := s.dbh.Select(&observation_types, `SELECT * FROM observation_types LIMIT $1 OFFSET $2;`, opt.PerPageOrDefault(), opt.Offset())
if err != nil {
return nil, err
}
return observation_types, nil
}

View file

@ -62,3 +62,26 @@ func TestObservationTypesStore_Create_db(t *testing.T) {
t.Error("want nonzero observation_type.Id after submitting")
}
}
func TestObservationTypesStore_List_db(t *testing.T) {
tx, _ := DB.Begin()
defer tx.Rollback()
want_observation_type := insertObservationType(t, tx)
want := []*models.ObservationType{want_observation_type}
d := NewDatastore(tx)
observation_types, err := d.ObservationTypes.List(&models.ObservationTypeListOptions{ListOptions: models.ListOptions{Page: 1, PerPage: 10}})
if err != nil {
t.Fatal(err)
}
for i := range want {
normalizeTime(&want[i].CreatedAt, &want[i].UpdatedAt, &want[i].DeletedAt)
normalizeTime(&observation_types[i].CreatedAt, &observation_types[i].UpdatedAt, &observation_types[i].DeletedAt)
}
if !reflect.DeepEqual(observation_types, want) {
t.Errorf("got observation_types %+v, want %+v", observation_types, want)
}
}