diff --git a/api/species.go b/api/species.go index 0e5adcc..e80b5b5 100644 --- a/api/species.go +++ b/api/species.go @@ -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 +} diff --git a/handlers/handlers.go b/handlers/handlers.go index 09a1ae6..f5eda7b 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -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:.+}"}, diff --git a/migrations/00004_AddStrain_up.sql b/migrations/00004_AddStrain_up.sql index cc42675..b0f8c04 100644 --- a/migrations/00004_AddStrain_up.sql +++ b/migrations/00004_AddStrain_up.sql @@ -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) diff --git a/migrations/00010_AddMeasurements_up.sql b/migrations/00010_AddMeasurements_up.sql index ca3674c..07cf6fa 100644 --- a/migrations/00010_AddMeasurements_up.sql +++ b/migrations/00010_AddMeasurements_up.sql @@ -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),