Skip to content

Commit

Permalink
Operations API - make LabelID int to align with workflow DB
Browse files Browse the repository at this point in the history
  • Loading branch information
edoshor committed Apr 30, 2019
1 parent 06a71d3 commit 360729f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ func handleCaptureStop(exec boil.Executor, input interface{}) (*models.Operation

log.Info("Creating file")
fProps := make(map[string]interface{})
if r.LabelID != "" {
fProps["label_id"] = r.LabelID
if r.LabelID.Valid {
fProps["label_id"] = r.LabelID.Int
}
file, err := CreateFile(exec, parent, r.File, fProps)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions api/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (suite *HandlersSuite) TestHandleCaptureStop() {
CaptureSource: "mltcap",
CollectionUID: "abcdefgh",
Part: "part",
LabelID: "label",
LabelID: null.IntFrom(123),
}

op, evnts, err := handleCaptureStop(suite.tx, input)
Expand Down Expand Up @@ -157,7 +157,7 @@ func (suite *HandlersSuite) TestHandleCaptureStop() {

err = f.Properties.Unmarshal(&props)
suite.Require().Nil(err)
suite.Equal(input.LabelID, props["label_id"], "file properties: label_id")
suite.Equal(input.LabelID.Int, int(props["label_id"].(float64)), "file properties: label_id")
}

func (suite *HandlersSuite) TestHandleDemux() {
Expand Down
2 changes: 1 addition & 1 deletion api/metadata_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func doProcess(exec boil.Executor, metadata CITMetadata, original, proxy *models
}

if metadata.LabelID.Valid {
props["label_id"] = metadata.LabelID.String
props["label_id"] = metadata.LabelID.Int
}
if metadata.Number.Valid {
props["number"] = metadata.Number.Int
Expand Down
10 changes: 5 additions & 5 deletions api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type (
Episode null.String `json:"episode"`
PartType null.Int `json:"part_type"`
Major *CITMetadataMajor `json:"major" binding:"omitempty"`
LabelID null.String `json:"label_id"`
LabelID null.Int `json:"label_id"`
FilmDate *Date `json:"film_date"`
UnitToFixUID null.String `json:"fix_unit_uid" binding:"omitempty,len=8"`
}
Expand All @@ -97,10 +97,10 @@ type (
CaptureStopRequest struct {
Operation
File
CaptureSource string `json:"capture_source"`
CollectionUID string `json:"collection_uid"`
Part string `json:"part"`
LabelID string `json:"label_id"`
CaptureSource string `json:"capture_source"`
CollectionUID string `json:"collection_uid"`
Part string `json:"part"`
LabelID null.Int `json:"label_id"`
}

DemuxRequest struct {
Expand Down
11 changes: 9 additions & 2 deletions importer/dgima/import.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dgima

import (
"strconv"
"time"

log "github.com/Sirupsen/logrus"
Expand Down Expand Up @@ -36,9 +37,15 @@ func doImport() error {
continue
}

err = api.UpdateFileProperties(mdb, f, map[string]interface{}{"label_id": records[i][1]})
labelID, err := strconv.Atoi(records[i][1])
if err != nil {
log.Errorf("UpdateFileProperties err %s [%s] => %s", err.Error(), records[i][0], records[i][1])
log.Warnf("labelID parse error %s: %s", err.Error(), records[i][1])
continue
}

err = api.UpdateFileProperties(mdb, f, map[string]interface{}{"label_id": labelID})
if err != nil {
log.Errorf("UpdateFileProperties err %s: %v", err.Error(), records[i])
}
}

Expand Down

0 comments on commit 360729f

Please sign in to comment.