Delete species

This commit is contained in:
Matthew Dillon 2015-10-12 10:40:47 -07:00
parent 50bee9ab88
commit 20026ebfd9
4 changed files with 13 additions and 2 deletions

View file

@ -155,3 +155,13 @@ func (s SpeciesService) Create(e *types.Entity, genus string, claims *types.Clai
}
return nil
}
// Delete deletes a single species
func (s SpeciesService) Delete(id int64, genus string, claims *types.Claims) *types.AppError {
q := `DELETE FROM species WHERE id=$1;`
// TODO: fix this
if _, err := models.DBH.Exec(q, id); err != nil {
return newJSONError(err, http.StatusInternalServerError)
}
return nil
}

View file

@ -74,6 +74,7 @@ func Handler() http.Handler {
r{handleCreater(speciesService), "POST", "/species"},
r{handleGetter(speciesService), "GET", "/species/{ID:.+}"},
r{handleUpdater(speciesService), "PUT", "/species/{ID:.+}"},
r{handleDeleter(speciesService), "DELETE", "/species/{ID:.+}"},
r{handleLister(strainService), "GET", "/strains"},
r{handleCreater(strainService), "POST", "/strains"},
r{handleGetter(strainService), "GET", "/strains/{ID:.+}"},

View file

@ -21,7 +21,7 @@ CREATE TABLE strains (
deleted_by BIGINT NULL,
CONSTRAINT strain_pkey PRIMARY KEY (id),
FOREIGN KEY (species_id) REFERENCES species(id),
FOREIGN KEY (species_id) REFERENCES species(id) ON DELETE CASCADE,
FOREIGN KEY (created_by) REFERENCES users(id),
FOREIGN KEY (updated_by) REFERENCES users(id),
FOREIGN KEY (deleted_by) REFERENCES users(id)

View file

@ -20,7 +20,7 @@ CREATE TABLE measurements (
updated_by BIGINT NOT NULL,
CONSTRAINT strainscharmeasurements_pkey PRIMARY KEY (id),
FOREIGN KEY (strain_id) REFERENCES strains(id),
FOREIGN KEY (strain_id) REFERENCES strains(id) ON DELETE CASCADE,
FOREIGN KEY (characteristic_id) REFERENCES characteristics(id) ON DELETE CASCADE,
FOREIGN KEY (text_measurement_type_id) REFERENCES text_measurement_types(id),
FOREIGN KEY (unit_type_id) REFERENCES unit_types(id),