Skip to content

Commit d8d0d9d

Browse files
author
Kai Hendry
committed
Remove int ID
1 parent 60c88ba commit d8d0d9d

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

main.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ type handler struct {
3434
// marshaller more complex
3535
type unit struct {
3636
MefeUnitID string `json:"mefe_unit_id"`
37-
MefeUnitIDint int `json:"mefeUnitIdIntValue"`
3837
MefeCreatorUserID string `json:"mefe_creator_user_id,omitempty"`
3938
BzfeCreatorUserID int `json:"bzfe_creator_user_id,omitempty"`
4039
ClassificationID int `json:"classification_id,omitempty"`
@@ -58,15 +57,13 @@ func init() {
5857
func (h handler) step1Insert(unit unit) (err error) {
5958
_, err = h.db.Exec(
6059
`INSERT INTO ut_data_to_create_units (mefe_unit_id,
61-
mefe_unit_id_int_value,
6260
mefe_creator_user_id,
6361
bzfe_creator_user_id,
6462
classification_id,
6563
unit_name,
6664
unit_description_details
67-
) VALUES (?,?,?,?,?,?,?)`,
65+
) VALUES (?,?,?,?,?,?)`,
6866
unit.MefeUnitID,
69-
unit.MefeUnitIDint,
7067
unit.MefeCreatorUserID,
7168
unit.BzfeCreatorUserID,
7269
unit.ClassificationID,
@@ -163,9 +160,6 @@ func (h handler) runsqlUnit(sqlfile string, u unit) (res sql.Result, err error)
163160
if u.MefeUnitID == "" {
164161
return res, fmt.Errorf("mefe_unit_id is unset")
165162
}
166-
if u.MefeUnitIDint == 0 {
167-
return res, fmt.Errorf("mefeUnitIdIntValue is unset")
168-
}
169163
sqlscript, err := ioutil.ReadFile(fmt.Sprintf("sql/%s", sqlfile))
170164
if err != nil {
171165
return
@@ -176,7 +170,7 @@ func (h handler) runsqlUnit(sqlfile string, u unit) (res sql.Result, err error)
176170
"sql": sqlfile,
177171
}).Info("exec")
178172

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))
180174
return res, err
181175
}
182176

@@ -268,6 +262,8 @@ func (h handler) createUnit(w http.ResponseWriter, r *http.Request) {
268262
return
269263
}
270264

265+
// This fails if a record already exists
266+
// TODO check if already exists, if it does continue
271267
err := h.step1Insert(unit)
272268
if err != nil {
273269
ctx.WithError(err).Error("failed to run step1Insert")
@@ -284,8 +280,9 @@ func (h handler) createUnit(w http.ResponseWriter, r *http.Request) {
284280
response.BadRequest(w, err.Error())
285281
return
286282
}
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)
289286
if err != nil {
290287
ctx.WithError(err).Errorf("unit_create_new.sql failed")
291288
response.BadRequest(w, err.Error())
@@ -298,8 +295,8 @@ func (h handler) createUnit(w http.ResponseWriter, r *http.Request) {
298295

299296
}
300297

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).
303300
Scan(&newUnit.ProductID)
304301
if err != nil {
305302
return newUnit, err

sql/unit_create_new.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#
1616
# The unit: What is the id of the unit in the table 'ut_data_to_create_units'
1717
SET @mefe_unit_id = '%s';
18-
SET @mefe_unit_id_int_value := %d;
1918
#
2019
# Environment: Which environment are you creating the unit in?
2120
# - 1 is for the DEV/Staging

0 commit comments

Comments
 (0)