parent
							
								
									299cd718b9
								
							
						
					
					
						commit
						62734899e2
					
				
					 6 changed files with 15 additions and 13 deletions
				
			
		|  | @ -175,9 +175,7 @@ func (c CharacteristicService) Create(e *types.Entity, genus string, claims *typ | ||||||
| 	} | 	} | ||||||
| 	payload.Characteristic.CharacteristicTypeID = id | 	payload.Characteristic.CharacteristicTypeID = id | ||||||
| 
 | 
 | ||||||
| 	// TODO: fix this | 	if err := models.Create(payload.Characteristic.CharacteristicBase); err != nil { | ||||||
| 	err = models.DBH.Insert(payload.Characteristic.CharacteristicBase) |  | ||||||
| 	if err != nil { |  | ||||||
| 		return newJSONError(err, http.StatusInternalServerError) | 		return newJSONError(err, http.StatusInternalServerError) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -129,8 +129,7 @@ func (m MeasurementService) Create(e *types.Entity, genus string, claims *types. | ||||||
| 	payload.Measurement.CreatedBy = claims.Sub | 	payload.Measurement.CreatedBy = claims.Sub | ||||||
| 	payload.Measurement.UpdatedBy = claims.Sub | 	payload.Measurement.UpdatedBy = claims.Sub | ||||||
| 
 | 
 | ||||||
| 	// TODO: fix this | 	if err := models.Create(payload.Measurement.MeasurementBase); err != nil { | ||||||
| 	if err := models.DBH.Insert(payload.Measurement.MeasurementBase); err != nil { |  | ||||||
| 		return newJSONError(err, http.StatusInternalServerError) | 		return newJSONError(err, http.StatusInternalServerError) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -132,9 +132,7 @@ func (s SpeciesService) Create(e *types.Entity, genus string, claims *types.Clai | ||||||
| 	} | 	} | ||||||
| 	payload.Species.SpeciesBase.GenusID = genusID | 	payload.Species.SpeciesBase.GenusID = genusID | ||||||
| 
 | 
 | ||||||
| 	// TODO: fix this | 	if err := models.Create(payload.Species.SpeciesBase); err != nil { | ||||||
| 	err = models.DBH.Insert(payload.Species.SpeciesBase) |  | ||||||
| 	if err != nil { |  | ||||||
| 		return newJSONError(err, http.StatusInternalServerError) | 		return newJSONError(err, http.StatusInternalServerError) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -189,8 +189,7 @@ func (s StrainService) Create(e *types.Entity, genus string, claims *types.Claim | ||||||
| 	payload.Strain.CreatedBy = claims.Sub | 	payload.Strain.CreatedBy = claims.Sub | ||||||
| 	payload.Strain.UpdatedBy = claims.Sub | 	payload.Strain.UpdatedBy = claims.Sub | ||||||
| 
 | 
 | ||||||
| 	// TODO: fix this | 	if err := models.Create(payload.Strain.StrainBase); err != nil { | ||||||
| 	if err := models.DBH.Insert(payload.Strain.StrainBase); err != nil { |  | ||||||
| 		return newJSONError(err, http.StatusInternalServerError) | 		return newJSONError(err, http.StatusInternalServerError) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -138,8 +138,7 @@ func (u UserService) Create(e *types.Entity, dummy string, claims *types.Claims) | ||||||
| 	user.Role = "R" | 	user.Role = "R" | ||||||
| 	user.Verified = false | 	user.Verified = false | ||||||
| 
 | 
 | ||||||
| 	// TODO: fix this | 	if err := models.Create(user.UserBase); err != nil { | ||||||
| 	if err := models.DBH.Insert(user.UserBase); err != nil { |  | ||||||
| 		if err, ok := err.(*pq.Error); ok { | 		if err, ok := err.(*pq.Error); ok { | ||||||
| 			if err.Code == "23505" { | 			if err.Code == "23505" { | ||||||
| 				return newJSONError(errors.ErrEmailAddressTaken, http.StatusInternalServerError) | 				return newJSONError(errors.ErrEmailAddressTaken, http.StatusInternalServerError) | ||||||
|  |  | ||||||
|  | @ -3,11 +3,20 @@ package models | ||||||
| import "github.com/thermokarst/bactdb/Godeps/_workspace/src/github.com/jmoiron/modl" | import "github.com/thermokarst/bactdb/Godeps/_workspace/src/github.com/jmoiron/modl" | ||||||
| 
 | 
 | ||||||
| type base interface { | type base interface { | ||||||
| 	PreCreate(modl.SqlExecutor) error | 	PreInsert(modl.SqlExecutor) error | ||||||
| 	PreUpdate(modl.SqlExecutor) error | 	PreUpdate(modl.SqlExecutor) error | ||||||
| 	UpdateError() error | 	UpdateError() error | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // Create will create a new DB record of a model. | ||||||
|  | func Create(b base) error { | ||||||
|  | 	if err := DBH.Insert(b); err != nil { | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | // Update runs a DB update on a model. | ||||||
| func Update(b base) error { | func Update(b base) error { | ||||||
| 	count, err := DBH.Update(b) | 	count, err := DBH.Update(b) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Matthew Dillon
						Matthew Dillon