Ember data: convey species/strain relationships.
This commit is contained in:
parent
61c24fc843
commit
4be150f897
6 changed files with 32 additions and 23 deletions
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
// A Species is a high-level classifier in bactdb.
|
||||
type Species struct {
|
||||
type SpeciesBase struct {
|
||||
Id int64 `json:"id,omitempty"`
|
||||
GenusId int64 `db:"genus_id" json:"genus"`
|
||||
SpeciesName string `db:"species_name" json:"speciesName"`
|
||||
|
@ -20,6 +20,11 @@ type Species struct {
|
|||
DeletedAt NullTime `db:"deleted_at" json:"deletedAt"`
|
||||
}
|
||||
|
||||
type Species struct {
|
||||
*SpeciesBase
|
||||
Strain NullSliceInt64 `db:"strains" json:"strains"`
|
||||
}
|
||||
|
||||
type SpeciesJSON struct {
|
||||
Species *Species `json:"species"`
|
||||
}
|
||||
|
@ -33,7 +38,7 @@ func (m *Species) String() string {
|
|||
}
|
||||
|
||||
func NewSpecies() *Species {
|
||||
return &Species{SpeciesName: "Test Species"}
|
||||
return &Species{&SpeciesBase{SpeciesName: "Test Species"}, make([]int64, 0)}
|
||||
}
|
||||
|
||||
// SpeciesService interacts with the species-related endpoints in bactdb's API.
|
||||
|
|
|
@ -55,7 +55,7 @@ func TestSpeciesService_Create(t *testing.T) {
|
|||
mux.HandleFunc(urlPath(t, router.CreateSpecies, nil), func(w http.ResponseWriter, r *http.Request) {
|
||||
called = true
|
||||
testMethod(t, r, "POST")
|
||||
testBody(t, r, `{"species":{"id":1,"genus":1,"speciesName":"Test Species","createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","deletedAt":null}}`+"\n")
|
||||
testBody(t, r, `{"species":{"id":1,"genus":1,"speciesName":"Test Species","createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","deletedAt":null,"strains":[]}}`+"\n")
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
writeJSON(w, want)
|
||||
|
@ -124,7 +124,7 @@ func TestSpeciesService_Update(t *testing.T) {
|
|||
mux.HandleFunc(urlPath(t, router.UpdateSpecies, map[string]string{"Id": "1"}), func(w http.ResponseWriter, r *http.Request) {
|
||||
called = true
|
||||
testMethod(t, r, "PUT")
|
||||
testBody(t, r, `{"species":{"id":1,"genus":1,"speciesName":"Test Species Updated","createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","deletedAt":null}}`+"\n")
|
||||
testBody(t, r, `{"species":{"id":1,"genus":1,"speciesName":"Test Species Updated","createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","deletedAt":null,"strains":[]}}`+"\n")
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
writeJSON(w, want)
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
// A Strain is a subclass of species
|
||||
type Strain struct {
|
||||
Id int64 `json:"id,omitempty"`
|
||||
SpeciesId int64 `db:"species_id" json:"speciesId"`
|
||||
SpeciesId int64 `db:"species_id" json:"species"`
|
||||
StrainName string `db:"strain_name" json:"strainName"`
|
||||
StrainType string `db:"strain_type" json:"strainType"`
|
||||
Etymology NullString `db:"etymology" json:"etymology"`
|
||||
|
|
|
@ -55,7 +55,7 @@ func TestStrainService_Create(t *testing.T) {
|
|||
mux.HandleFunc(urlPath(t, router.CreateStrain, nil), func(w http.ResponseWriter, r *http.Request) {
|
||||
called = true
|
||||
testMethod(t, r, "POST")
|
||||
testBody(t, r, `{"strain":{"id":1,"speciesId":1,"strainName":"Test Strain","strainType":"Test Type","etymology":"Test Etymology","accessionBanks":"Test Accession","genbankEmblDdb":"Test Genbank","isolatedFrom":null,"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","deletedAt":null}}`+"\n")
|
||||
testBody(t, r, `{"strain":{"id":1,"species":1,"strainName":"Test Strain","strainType":"Test Type","etymology":"Test Etymology","accessionBanks":"Test Accession","genbankEmblDdb":"Test Genbank","isolatedFrom":null,"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","deletedAt":null}}`+"\n")
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
writeJSON(w, want)
|
||||
|
@ -124,7 +124,7 @@ func TestStrainService_Update(t *testing.T) {
|
|||
mux.HandleFunc(urlPath(t, router.UpdateStrain, map[string]string{"Id": "1"}), func(w http.ResponseWriter, r *http.Request) {
|
||||
called = true
|
||||
testMethod(t, r, "PUT")
|
||||
testBody(t, r, `{"strain":{"id":1,"speciesId":1,"strainName":"Test Strain Updated","strainType":"Test Type Updated","etymology":"Test Etymology","accessionBanks":"Test Accession Updated","genbankEmblDdb":"Test Genbank Updated","isolatedFrom":null,"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","deletedAt":null}}`+"\n")
|
||||
testBody(t, r, `{"strain":{"id":1,"species":1,"strainName":"Test Strain Updated","strainType":"Test Type Updated","etymology":"Test Etymology","accessionBanks":"Test Accession Updated","genbankEmblDdb":"Test Genbank Updated","isolatedFrom":null,"createdAt":"0001-01-01T00:00:00Z","updatedAt":"0001-01-01T00:00:00Z","deletedAt":null}}`+"\n")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
writeJSON(w, want)
|
||||
})
|
||||
|
|
Reference in a new issue