Measurements — adding notes, changing schema
This commit is contained in:
parent
4eecb36e34
commit
f33205e721
4 changed files with 13 additions and 14 deletions
|
@ -48,8 +48,8 @@ func TestMeasurementsStore_Get_db(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
normalizeTime(&want.CreatedAt, &want.UpdatedAt, &want.DeletedAt)
|
normalizeTime(&want.CreatedAt, &want.UpdatedAt)
|
||||||
normalizeTime(&measurement.CreatedAt, &measurement.UpdatedAt, &measurement.DeletedAt)
|
normalizeTime(&measurement.CreatedAt, &measurement.UpdatedAt)
|
||||||
|
|
||||||
if !reflect.DeepEqual(measurement, want) {
|
if !reflect.DeepEqual(measurement, want) {
|
||||||
t.Errorf("got measurement %+v, want %+v", measurement, want)
|
t.Errorf("got measurement %+v, want %+v", measurement, want)
|
||||||
|
@ -91,8 +91,8 @@ func TestMeasurementsStore_List_db(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range want {
|
for i := range want {
|
||||||
normalizeTime(&want[i].CreatedAt, &want[i].UpdatedAt, &want[i].DeletedAt)
|
normalizeTime(&want[i].CreatedAt, &want[i].UpdatedAt)
|
||||||
normalizeTime(&measurements[i].CreatedAt, &measurements[i].UpdatedAt, &measurements[i].DeletedAt)
|
normalizeTime(&measurements[i].CreatedAt, &measurements[i].UpdatedAt)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(measurements, want) {
|
if !reflect.DeepEqual(measurements, want) {
|
||||||
t.Errorf("got measurements %+v, want %+v", measurements, want)
|
t.Errorf("got measurements %+v, want %+v", measurements, want)
|
||||||
|
|
|
@ -6,13 +6,13 @@ CREATE TABLE measurements (
|
||||||
strain_id BIGINT,
|
strain_id BIGINT,
|
||||||
observation_id BIGINT,
|
observation_id BIGINT,
|
||||||
text_measurement_type_id BIGINT NULL,
|
text_measurement_type_id BIGINT NULL,
|
||||||
measurement_value NUMERIC(6, 4) NULL,
|
measurement_value NUMERIC(8, 3) NULL,
|
||||||
confidence_interval NUMERIC(6, 4) NULL,
|
confidence_interval NUMERIC(8, 3) NULL,
|
||||||
unit_type_id BIGINT NULL,
|
unit_type_id BIGINT NULL,
|
||||||
|
notes CHARACTER VARYING(255) NULL,
|
||||||
|
|
||||||
created_at TIMESTAMP WITH TIME ZONE,
|
created_at TIMESTAMP WITH TIME ZONE,
|
||||||
updated_at TIMESTAMP WITH TIME ZONE,
|
updated_at TIMESTAMP WITH TIME ZONE,
|
||||||
deleted_at TIMESTAMP WITH TIME ZONE,
|
|
||||||
|
|
||||||
CONSTRAINT strainsobsmeasurements_pkey PRIMARY KEY (id),
|
CONSTRAINT strainsobsmeasurements_pkey PRIMARY KEY (id),
|
||||||
FOREIGN KEY (strain_id) REFERENCES strains(id),
|
FOREIGN KEY (strain_id) REFERENCES strains(id),
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lib/pq"
|
|
||||||
"github.com/thermokarst/bactdb/router"
|
"github.com/thermokarst/bactdb/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,9 +22,9 @@ type Measurement struct {
|
||||||
MeasurementValue sql.NullFloat64 `db:"measurement_value" json:"measurementValue"`
|
MeasurementValue sql.NullFloat64 `db:"measurement_value" json:"measurementValue"`
|
||||||
ConfidenceInterval sql.NullFloat64 `db:"confidence_interval" json:"confidenceInterval"`
|
ConfidenceInterval sql.NullFloat64 `db:"confidence_interval" json:"confidenceInterval"`
|
||||||
UnitTypeId sql.NullInt64 `db:"unit_type_id" json:"unitTypeId"`
|
UnitTypeId sql.NullInt64 `db:"unit_type_id" json:"unitTypeId"`
|
||||||
|
Notes sql.NullString `db:"notes" json:"notes"`
|
||||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||||
DeletedAt pq.NullTime `db:"deleted_at" json:"deletedAt"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMeasurement() *Measurement {
|
func NewMeasurement() *Measurement {
|
||||||
|
|
|
@ -41,7 +41,7 @@ func TestMeasurementService_Get(t *testing.T) {
|
||||||
t.Fatal("!called")
|
t.Fatal("!called")
|
||||||
}
|
}
|
||||||
|
|
||||||
normalizeTime(&want.CreatedAt, &want.UpdatedAt, &want.DeletedAt)
|
normalizeTime(&want.CreatedAt, &want.UpdatedAt)
|
||||||
|
|
||||||
if !reflect.DeepEqual(measurement, want) {
|
if !reflect.DeepEqual(measurement, want) {
|
||||||
t.Errorf("Measurements.Get return %+v, want %+v", measurement, want)
|
t.Errorf("Measurements.Get return %+v, want %+v", measurement, want)
|
||||||
|
@ -58,7 +58,7 @@ func TestMeasurementService_Create(t *testing.T) {
|
||||||
mux.HandleFunc(urlPath(t, router.CreateMeasurement, nil), func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc(urlPath(t, router.CreateMeasurement, nil), func(w http.ResponseWriter, r *http.Request) {
|
||||||
called = true
|
called = true
|
||||||
testMethod(t, r, "POST")
|
testMethod(t, r, "POST")
|
||||||
testBody(t, r, `{"id":1,"strainId":1,"observationId":1,"textMeasurementTypeId":{"Int64":0,"Valid":false},"measurementValue":{"Float64":1.23,"Valid":true},"confidenceInterval":{"Float64":0,"Valid":false},"unitTypeId":{"Int64":1,"Valid":true},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","deletedAt":{"Time":"0001-01-01T00:00:00Z","Valid":false}}`+"\n")
|
testBody(t, r, `{"id":1,"strainId":1,"observationId":1,"textMeasurementTypeId":{"Int64":0,"Valid":false},"measurementValue":{"Float64":1.23,"Valid":true},"confidenceInterval":{"Float64":0,"Valid":false},"unitTypeId":{"Int64":1,"Valid":true},"notes":{"String":"","Valid":false},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"}`+"\n")
|
||||||
|
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
writeJSON(w, want)
|
writeJSON(w, want)
|
||||||
|
@ -78,7 +78,7 @@ func TestMeasurementService_Create(t *testing.T) {
|
||||||
t.Fatal("!called")
|
t.Fatal("!called")
|
||||||
}
|
}
|
||||||
|
|
||||||
normalizeTime(&want.CreatedAt, &want.UpdatedAt, &want.DeletedAt)
|
normalizeTime(&want.CreatedAt, &want.UpdatedAt)
|
||||||
if !reflect.DeepEqual(measurement, want) {
|
if !reflect.DeepEqual(measurement, want) {
|
||||||
t.Errorf("Measurements.Create returned %+v, want %+v", measurement, want)
|
t.Errorf("Measurements.Create returned %+v, want %+v", measurement, want)
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ func TestMeasurementService_List(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, u := range want {
|
for _, u := range want {
|
||||||
normalizeTime(&u.CreatedAt, &u.UpdatedAt, &u.DeletedAt)
|
normalizeTime(&u.CreatedAt, &u.UpdatedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(measurements, want) {
|
if !reflect.DeepEqual(measurements, want) {
|
||||||
|
@ -127,7 +127,7 @@ func TestMeasurementService_Update(t *testing.T) {
|
||||||
mux.HandleFunc(urlPath(t, router.UpdateMeasurement, map[string]string{"Id": "1"}), func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc(urlPath(t, router.UpdateMeasurement, map[string]string{"Id": "1"}), func(w http.ResponseWriter, r *http.Request) {
|
||||||
called = true
|
called = true
|
||||||
testMethod(t, r, "PUT")
|
testMethod(t, r, "PUT")
|
||||||
testBody(t, r, `{"id":1,"strainId":1,"observationId":1,"textMeasurementTypeId":{"Int64":0,"Valid":false},"measurementValue":{"Float64":4.56,"Valid":true},"confidenceInterval":{"Float64":0,"Valid":false},"unitTypeId":{"Int64":1,"Valid":true},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","deletedAt":{"Time":"0001-01-01T00:00:00Z","Valid":false}}`+"\n")
|
testBody(t, r, `{"id":1,"strainId":1,"observationId":1,"textMeasurementTypeId":{"Int64":0,"Valid":false},"measurementValue":{"Float64":4.56,"Valid":true},"confidenceInterval":{"Float64":0,"Valid":false},"unitTypeId":{"Int64":1,"Valid":true},"notes":{"String":"","Valid":false},"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z"}`+"\n")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
writeJSON(w, want)
|
writeJSON(w, want)
|
||||||
})
|
})
|
||||||
|
|
Reference in a new issue