@@ -34,7 +34,6 @@ type handler struct {
34
34
// marshaller more complex
35
35
type unit struct {
36
36
MefeUnitID string `json:"mefe_unit_id"`
37
- MefeUnitIDint int `json:"mefeUnitIdIntValue"`
38
37
MefeCreatorUserID string `json:"mefe_creator_user_id,omitempty"`
39
38
BzfeCreatorUserID int `json:"bzfe_creator_user_id,omitempty"`
40
39
ClassificationID int `json:"classification_id,omitempty"`
@@ -58,15 +57,13 @@ func init() {
58
57
func (h handler ) step1Insert (unit unit ) (err error ) {
59
58
_ , err = h .db .Exec (
60
59
`INSERT INTO ut_data_to_create_units (mefe_unit_id,
61
- mefe_unit_id_int_value,
62
60
mefe_creator_user_id,
63
61
bzfe_creator_user_id,
64
62
classification_id,
65
63
unit_name,
66
64
unit_description_details
67
- ) VALUES (?,?,?,?,?,?,? )` ,
65
+ ) VALUES (?,?,?,?,?,?)` ,
68
66
unit .MefeUnitID ,
69
- unit .MefeUnitIDint ,
70
67
unit .MefeCreatorUserID ,
71
68
unit .BzfeCreatorUserID ,
72
69
unit .ClassificationID ,
@@ -163,9 +160,6 @@ func (h handler) runsqlUnit(sqlfile string, u unit) (res sql.Result, err error)
163
160
if u .MefeUnitID == "" {
164
161
return res , fmt .Errorf ("mefe_unit_id is unset" )
165
162
}
166
- if u .MefeUnitIDint == 0 {
167
- return res , fmt .Errorf ("mefeUnitIdIntValue is unset" )
168
- }
169
163
sqlscript , err := ioutil .ReadFile (fmt .Sprintf ("sql/%s" , sqlfile ))
170
164
if err != nil {
171
165
return
@@ -176,7 +170,7 @@ func (h handler) runsqlUnit(sqlfile string, u unit) (res sql.Result, err error)
176
170
"sql" : sqlfile ,
177
171
}).Info ("exec" )
178
172
179
- res , err = h .db .Exec (fmt .Sprintf (string (sqlscript ), u .MefeUnitID , u . MefeUnitIDint , h .Code ))
173
+ res , err = h .db .Exec (fmt .Sprintf (string (sqlscript ), u .MefeUnitID , h .Code ))
180
174
return res , err
181
175
}
182
176
@@ -268,6 +262,8 @@ func (h handler) createUnit(w http.ResponseWriter, r *http.Request) {
268
262
return
269
263
}
270
264
265
+ // This fails if a record already exists
266
+ // TODO check if already exists, if it does continue
271
267
err := h .step1Insert (unit )
272
268
if err != nil {
273
269
ctx .WithError (err ).Error ("failed to run step1Insert" )
@@ -284,8 +280,9 @@ func (h handler) createUnit(w http.ResponseWriter, r *http.Request) {
284
280
response .BadRequest (w , err .Error ())
285
281
return
286
282
}
287
- ctx .WithField ("duration" , time .Since (start )).Infof ("ran unit_create_new.sql" )
288
- ProductID , err := h .getProductID (unit .MefeUnitIDint )
283
+
284
+ ctx .WithField ("duration" , time .Since (start ).String ()).Infof ("ran unit_create_new.sql" )
285
+ ProductID , err := h .getProductID (unit .MefeUnitID )
289
286
if err != nil {
290
287
ctx .WithError (err ).Errorf ("unit_create_new.sql failed" )
291
288
response .BadRequest (w , err .Error ())
@@ -298,8 +295,8 @@ func (h handler) createUnit(w http.ResponseWriter, r *http.Request) {
298
295
299
296
}
300
297
301
- func (h handler ) getProductID (MefeUnitIDint int ) (newUnit unitCreated , err error ) {
302
- err = h .db .QueryRow ("SELECT product_id FROM ut_data_to_create_units WHERE mefe_unit_id_int_value =?" , MefeUnitIDint ).
298
+ func (h handler ) getProductID (MefeUnitID string ) (newUnit unitCreated , err error ) {
299
+ err = h .db .QueryRow ("SELECT product_id FROM ut_data_to_create_units WHERE mefe_unit_id =?" , MefeUnitID ).
303
300
Scan (& newUnit .ProductID )
304
301
if err != nil {
305
302
return newUnit , err
0 commit comments