parent
62734899e2
commit
d46e721063
15 changed files with 71 additions and 14 deletions
|
@ -193,10 +193,14 @@ func (c CharacteristicService) Create(e *types.Entity, genus string, claims *typ
|
||||||
|
|
||||||
// Delete deletes a single characteristic
|
// Delete deletes a single characteristic
|
||||||
func (c CharacteristicService) Delete(id int64, genus string, claims *types.Claims) *types.AppError {
|
func (c CharacteristicService) Delete(id int64, genus string, claims *types.Claims) *types.AppError {
|
||||||
q := `DELETE FROM characteristics WHERE id=$1;`
|
characteristic, err := models.GetCharacteristic(id, genus, claims)
|
||||||
// TODO: fix this
|
if err != nil {
|
||||||
if _, err := models.DBH.Exec(q, id); err != nil {
|
|
||||||
return newJSONError(err, http.StatusInternalServerError)
|
return newJSONError(err, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := models.Delete(characteristic); err != nil {
|
||||||
|
return newJSONError(err, http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,12 +114,14 @@ func (m MeasurementService) Update(id int64, e *types.Entity, genus string, clai
|
||||||
|
|
||||||
// Delete deletes a single measurement.
|
// Delete deletes a single measurement.
|
||||||
func (m MeasurementService) Delete(id int64, genus string, claims *types.Claims) *types.AppError {
|
func (m MeasurementService) Delete(id int64, genus string, claims *types.Claims) *types.AppError {
|
||||||
q := `DELETE FROM measurements WHERE id=$1;`
|
measurement, err := models.GetMeasurement(id, genus, claims)
|
||||||
// TODO: fix this
|
|
||||||
_, err := models.DBH.Exec(q, id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newJSONError(err, http.StatusInternalServerError)
|
return newJSONError(err, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
if err := models.Delete(measurement); err != nil {
|
||||||
|
return newJSONError(err, http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -153,10 +153,14 @@ func (s SpeciesService) Create(e *types.Entity, genus string, claims *types.Clai
|
||||||
|
|
||||||
// Delete deletes a single species
|
// Delete deletes a single species
|
||||||
func (s SpeciesService) Delete(id int64, genus string, claims *types.Claims) *types.AppError {
|
func (s SpeciesService) Delete(id int64, genus string, claims *types.Claims) *types.AppError {
|
||||||
q := `DELETE FROM species WHERE id=$1;`
|
species, err := models.GetSpecies(id, genus, claims)
|
||||||
// TODO: fix this
|
if err != nil {
|
||||||
if _, err := models.DBH.Exec(q, id); err != nil {
|
|
||||||
return newJSONError(err, http.StatusInternalServerError)
|
return newJSONError(err, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := models.Delete(species.SpeciesBase); err != nil {
|
||||||
|
return newJSONError(err, http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -216,10 +216,14 @@ func (s StrainService) Create(e *types.Entity, genus string, claims *types.Claim
|
||||||
|
|
||||||
// Delete deletes a single strain
|
// Delete deletes a single strain
|
||||||
func (s StrainService) Delete(id int64, genus string, claims *types.Claims) *types.AppError {
|
func (s StrainService) Delete(id int64, genus string, claims *types.Claims) *types.AppError {
|
||||||
q := `DELETE FROM strains WHERE id=$1;`
|
strain, err := models.GetStrain(id, genus, claims)
|
||||||
// TODO: fix this
|
if err != nil {
|
||||||
if _, err := models.DBH.Exec(q, id); err != nil {
|
|
||||||
return newJSONError(err, http.StatusInternalServerError)
|
return newJSONError(err, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := models.Delete(strain); err != nil {
|
||||||
|
return newJSONError(err, http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,6 @@ var (
|
||||||
ErrCharacteristicNotFound = errors.New("Characteristic not found")
|
ErrCharacteristicNotFound = errors.New("Characteristic not found")
|
||||||
// ErrCharacteristicNotUpdated when not updated.
|
// ErrCharacteristicNotUpdated when not updated.
|
||||||
ErrCharacteristicNotUpdated = errors.New("Characteristic not updated")
|
ErrCharacteristicNotUpdated = errors.New("Characteristic not updated")
|
||||||
|
// ErrCharacteristicNotDeleted when not deleted.
|
||||||
|
ErrCharacteristicNotDeleted = errors.New("Characteristic not deleted")
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,6 +5,8 @@ import "errors"
|
||||||
var (
|
var (
|
||||||
// ErrMeasurementNotFound when not found.
|
// ErrMeasurementNotFound when not found.
|
||||||
ErrMeasurementNotFound = errors.New("Measurement not found")
|
ErrMeasurementNotFound = errors.New("Measurement not found")
|
||||||
// ErrMeasurementNotUpdate when not updated.
|
// ErrMeasurementNotUpdated when not updated.
|
||||||
ErrMeasurementNotUpdated = errors.New("Measurement not updated")
|
ErrMeasurementNotUpdated = errors.New("Measurement not updated")
|
||||||
|
// ErrMeasurementNotDeleted when not deleted.
|
||||||
|
ErrMeasurementNotDeleted = errors.New("Measurement not deleted")
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,4 +7,6 @@ var (
|
||||||
ErrSpeciesNotFound = errors.New("Species not found")
|
ErrSpeciesNotFound = errors.New("Species not found")
|
||||||
// ErrSpeciesNotUpdated when not updated.
|
// ErrSpeciesNotUpdated when not updated.
|
||||||
ErrSpeciesNotUpdated = errors.New("Species not updated")
|
ErrSpeciesNotUpdated = errors.New("Species not updated")
|
||||||
|
// ErrSpeciesNotDeleted when not deleted.
|
||||||
|
ErrSpeciesNotDeleted = errors.New("Species not deleted")
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,4 +7,6 @@ var (
|
||||||
ErrStrainNotFound = errors.New("Strain not found")
|
ErrStrainNotFound = errors.New("Strain not found")
|
||||||
// ErrStrainNotUpdated when not updated.
|
// ErrStrainNotUpdated when not updated.
|
||||||
ErrStrainNotUpdated = errors.New("Strain not updated")
|
ErrStrainNotUpdated = errors.New("Strain not updated")
|
||||||
|
// ErrStrainNotDeleted when not deleted.
|
||||||
|
ErrStrainNotDeleted = errors.New("Strain not deleted")
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,9 @@ var (
|
||||||
// ErrUserNotFound when not found.
|
// ErrUserNotFound when not found.
|
||||||
ErrUserNotFound = errors.New("No user found")
|
ErrUserNotFound = errors.New("No user found")
|
||||||
// ErrUserNotUpdated when not updated.
|
// ErrUserNotUpdated when not updated.
|
||||||
ErrUserNotUpdated = errors.New("Count 0")
|
ErrUserNotUpdated = errors.New("User not updated")
|
||||||
|
// ErrUserNotDeleted when not deleted.
|
||||||
|
ErrUserNotDeleted = errors.New("User not deleted")
|
||||||
// ErrUserMissingEmail when missing email.
|
// ErrUserMissingEmail when missing email.
|
||||||
ErrUserMissingEmail = errors.New("Missing email")
|
ErrUserMissingEmail = errors.New("Missing email")
|
||||||
// ErrInvalidEmailOrPassword when invalid login credentials.
|
// ErrInvalidEmailOrPassword when invalid login credentials.
|
||||||
|
|
|
@ -32,6 +32,10 @@ func (c *CharacteristicBase) UpdateError() error {
|
||||||
return errors.ErrCharacteristicNotUpdated
|
return errors.ErrCharacteristicNotUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CharacteristicBase) DeleteError() error {
|
||||||
|
return errors.ErrCharacteristicNotDeleted
|
||||||
|
}
|
||||||
|
|
||||||
// CharacteristicBase is what the DB expects for write operations
|
// CharacteristicBase is what the DB expects for write operations
|
||||||
type CharacteristicBase struct {
|
type CharacteristicBase struct {
|
||||||
ID int64 `json:"id,omitempty"`
|
ID int64 `json:"id,omitempty"`
|
||||||
|
|
|
@ -6,6 +6,7 @@ type base interface {
|
||||||
PreInsert(modl.SqlExecutor) error
|
PreInsert(modl.SqlExecutor) error
|
||||||
PreUpdate(modl.SqlExecutor) error
|
PreUpdate(modl.SqlExecutor) error
|
||||||
UpdateError() error
|
UpdateError() error
|
||||||
|
DeleteError() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create will create a new DB record of a model.
|
// Create will create a new DB record of a model.
|
||||||
|
@ -27,3 +28,15 @@ func Update(b base) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete runs a DB delete on a model.
|
||||||
|
func Delete(b base) error {
|
||||||
|
count, err := DBH.Delete(b)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if count != 1 {
|
||||||
|
return b.DeleteError()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -33,6 +33,10 @@ func (m *MeasurementBase) UpdateError() error {
|
||||||
return errors.ErrMeasurementNotUpdated
|
return errors.ErrMeasurementNotUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MeasurementBase) DeleteError() error {
|
||||||
|
return errors.ErrMeasurementNotDeleted
|
||||||
|
}
|
||||||
|
|
||||||
// MeasurementBase is what the DB expects for write operations
|
// MeasurementBase is what the DB expects for write operations
|
||||||
// There are three types of supported measurements: fixed-text, free-text,
|
// There are three types of supported measurements: fixed-text, free-text,
|
||||||
// & numerical. The table has a constraint that will allow at most one
|
// & numerical. The table has a constraint that will allow at most one
|
||||||
|
|
|
@ -33,6 +33,10 @@ func (s *SpeciesBase) UpdateError() error {
|
||||||
return errors.ErrSpeciesNotUpdated
|
return errors.ErrSpeciesNotUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SpeciesBase) DeleteError() error {
|
||||||
|
return errors.ErrSpeciesNotDeleted
|
||||||
|
}
|
||||||
|
|
||||||
// SpeciesBase is what the DB expects for write operations.
|
// SpeciesBase is what the DB expects for write operations.
|
||||||
type SpeciesBase struct {
|
type SpeciesBase struct {
|
||||||
ID int64 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
|
|
|
@ -33,6 +33,10 @@ func (s *StrainBase) UpdateError() error {
|
||||||
return errors.ErrStrainNotUpdated
|
return errors.ErrStrainNotUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StrainBase) DeleteError() error {
|
||||||
|
return errors.ErrStrainNotDeleted
|
||||||
|
}
|
||||||
|
|
||||||
// StrainBase is what the DB expects for write operations.
|
// StrainBase is what the DB expects for write operations.
|
||||||
type StrainBase struct {
|
type StrainBase struct {
|
||||||
ID int64 `db:"id" json:"id"`
|
ID int64 `db:"id" json:"id"`
|
||||||
|
|
|
@ -34,6 +34,10 @@ func (u *UserBase) UpdateError() error {
|
||||||
return errors.ErrUserNotUpdated
|
return errors.ErrUserNotUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *UserBase) DeleteError() error {
|
||||||
|
return errors.ErrUserNotDeleted
|
||||||
|
}
|
||||||
|
|
||||||
// UserBase is what the DB expects to see for write operations.
|
// UserBase is what the DB expects to see for write operations.
|
||||||
type UserBase struct {
|
type UserBase struct {
|
||||||
ID int64 `json:"id,omitempty"`
|
ID int64 `json:"id,omitempty"`
|
||||||
|
|
Reference in a new issue