Get a unit type
This commit is contained in:
parent
431ba7ed91
commit
c2bfc8b93b
11 changed files with 260 additions and 0 deletions
|
@ -59,6 +59,8 @@ func Handler() *mux.Router {
|
|||
m.Get(router.UpdateTextMeasurementType).Handler(handler(serveUpdateTextMeasurementType))
|
||||
m.Get(router.DeleteTextMeasurementType).Handler(handler(serveDeleteTextMeasurementType))
|
||||
|
||||
m.Get(router.UnitType).Handler(handler(serveUnitType))
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
|
|
22
api/unit_types.go
Normal file
22
api/unit_types.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func serveUnitType(w http.ResponseWriter, r *http.Request) error {
|
||||
id, err := strconv.ParseInt(mux.Vars(r)["Id"], 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
unit_type, err := store.UnitTypes.Get(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return writeJSON(w, unit_type)
|
||||
}
|
40
api/unit_types_test.go
Normal file
40
api/unit_types_test.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/thermokarst/bactdb/models"
|
||||
)
|
||||
|
||||
func newUnitType() *models.UnitType {
|
||||
unit_type := models.NewUnitType()
|
||||
return unit_type
|
||||
}
|
||||
|
||||
func TestUnitType_Get(t *testing.T) {
|
||||
setup()
|
||||
|
||||
want := newUnitType()
|
||||
|
||||
calledGet := false
|
||||
|
||||
store.UnitTypes.(*models.MockUnitTypesService).Get_ = func(id int64) (*models.UnitType, error) {
|
||||
if id != want.Id {
|
||||
t.Errorf("wanted request for unit_type %d but got %d", want.Id, id)
|
||||
}
|
||||
calledGet = true
|
||||
return want, nil
|
||||
}
|
||||
|
||||
got, err := apiClient.UnitTypes.Get(want.Id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !calledGet {
|
||||
t.Error("!calledGet")
|
||||
}
|
||||
if !normalizeDeepEqual(want, got) {
|
||||
t.Errorf("got %+v but wanted %+v", got, want)
|
||||
}
|
||||
}
|
Reference in a new issue