Refactor delete handlers

Fixes #18.
This commit is contained in:
Matthew Dillon 2015-10-13 13:42:19 -07:00
parent 62734899e2
commit d46e721063
15 changed files with 71 additions and 14 deletions

View file

@ -193,10 +193,14 @@ func (c CharacteristicService) Create(e *types.Entity, genus string, claims *typ
// Delete deletes a single characteristic
func (c CharacteristicService) Delete(id int64, genus string, claims *types.Claims) *types.AppError {
q := `DELETE FROM characteristics WHERE id=$1;`
// TODO: fix this
if _, err := models.DBH.Exec(q, id); err != nil {
characteristic, err := models.GetCharacteristic(id, genus, claims)
if err != nil {
return newJSONError(err, http.StatusInternalServerError)
}
if err := models.Delete(characteristic); err != nil {
return newJSONError(err, http.StatusInternalServerError)
}
return nil
}

View file

@ -114,12 +114,14 @@ func (m MeasurementService) Update(id int64, e *types.Entity, genus string, clai
// Delete deletes a single measurement.
func (m MeasurementService) Delete(id int64, genus string, claims *types.Claims) *types.AppError {
q := `DELETE FROM measurements WHERE id=$1;`
// TODO: fix this
_, err := models.DBH.Exec(q, id)
measurement, err := models.GetMeasurement(id, genus, claims)
if err != nil {
return newJSONError(err, http.StatusInternalServerError)
}
if err := models.Delete(measurement); err != nil {
return newJSONError(err, http.StatusInternalServerError)
}
return nil
}

View file

@ -153,10 +153,14 @@ func (s SpeciesService) Create(e *types.Entity, genus string, claims *types.Clai
// 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 {
species, err := models.GetSpecies(id, genus, claims)
if err != nil {
return newJSONError(err, http.StatusInternalServerError)
}
if err := models.Delete(species.SpeciesBase); err != nil {
return newJSONError(err, http.StatusInternalServerError)
}
return nil
}

View file

@ -216,10 +216,14 @@ func (s StrainService) Create(e *types.Entity, genus string, claims *types.Claim
// Delete deletes a single strain
func (s StrainService) Delete(id int64, genus string, claims *types.Claims) *types.AppError {
q := `DELETE FROM strains WHERE id=$1;`
// TODO: fix this
if _, err := models.DBH.Exec(q, id); err != nil {
strain, err := models.GetStrain(id, genus, claims)
if err != nil {
return newJSONError(err, http.StatusInternalServerError)
}
if err := models.Delete(strain); err != nil {
return newJSONError(err, http.StatusInternalServerError)
}
return nil
}