Create measurement
This commit is contained in:
		
							parent
							
								
									f646437f73
								
							
						
					
					
						commit
						62bc917d07
					
				
					 3 changed files with 15 additions and 1 deletions
				
			
		|  | @ -120,6 +120,7 @@ func Handler() http.Handler { | ||||||
| 		r{handleGetter(characteristicService), "GET", "/characteristics/{Id:.+}"}, | 		r{handleGetter(characteristicService), "GET", "/characteristics/{Id:.+}"}, | ||||||
| 		r{handleUpdater(characteristicService), "PUT", "/characteristics/{Id:.+}"}, | 		r{handleUpdater(characteristicService), "PUT", "/characteristics/{Id:.+}"}, | ||||||
| 		r{handleLister(measurementService), "GET", "/measurements"}, | 		r{handleLister(measurementService), "GET", "/measurements"}, | ||||||
|  | 		r{handleCreater(measurementService), "POST", "/measurements"}, | ||||||
| 		r{handleGetter(measurementService), "GET", "/measurements/{Id:.+}"}, | 		r{handleGetter(measurementService), "GET", "/measurements/{Id:.+}"}, | ||||||
| 		r{handleUpdater(measurementService), "PUT", "/measurements/{Id:.+}"}, | 		r{handleUpdater(measurementService), "PUT", "/measurements/{Id:.+}"}, | ||||||
| 		r{handleDeleter(measurementService), "DELETE", "/measurements/{Id:.+}"}, | 		r{handleDeleter(measurementService), "DELETE", "/measurements/{Id:.+}"}, | ||||||
|  |  | ||||||
|  | @ -255,6 +255,19 @@ func (m MeasurementService) delete(id int64, genus string, claims *Claims) *appE | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func (m MeasurementService) create(e *entity, genus string, claims *Claims) *appError { | ||||||
|  | 	payload := (*e).(*MeasurementPayload) | ||||||
|  | 	payload.Measurement.CreatedBy = claims.Sub | ||||||
|  | 	payload.Measurement.UpdatedBy = claims.Sub | ||||||
|  | 
 | ||||||
|  | 	if err := DBH.Insert(payload.Measurement.MeasurementBase); err != nil { | ||||||
|  | 		return newJSONError(err, http.StatusInternalServerError) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	return nil | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func listMeasurements(opt MeasurementListOptions, claims *Claims) (*Measurements, error) { | func listMeasurements(opt MeasurementListOptions, claims *Claims) (*Measurements, error) { | ||||||
| 	var vals []interface{} | 	var vals []interface{} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -343,7 +343,7 @@ func getStrain(id int64, genus string, claims *Claims) (*Strain, error) { | ||||||
| 		FROM strains st | 		FROM strains st | ||||||
| 		INNER JOIN species sp ON sp.id=st.species_id | 		INNER JOIN species sp ON sp.id=st.species_id | ||||||
| 		INNER JOIN genera g ON g.id=sp.genus_id AND LOWER(g.genus_name)=LOWER($1) | 		INNER JOIN genera g ON g.id=sp.genus_id AND LOWER(g.genus_name)=LOWER($1) | ||||||
| 		INNER JOIN measurements m ON m.strain_id=st.id | 		LEFT OUTER JOIN measurements m ON m.strain_id=st.id | ||||||
| 		WHERE st.id=$2 | 		WHERE st.id=$2 | ||||||
| 		GROUP BY st.id;` | 		GROUP BY st.id;` | ||||||
| 	if err := DBH.SelectOne(&strain, q, genus, id); err != nil { | 	if err := DBH.SelectOne(&strain, q, genus, id); err != nil { | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Matthew Dillon
						Matthew Dillon