diff --git a/auth_utility.go b/auth_utility.go index c70a893..7833b40 100644 --- a/auth_utility.go +++ b/auth_utility.go @@ -40,6 +40,7 @@ type TokenClaims struct { type CredentialsStruct struct { Username string `json:"username"` Password string `json:"password"` + RoleID uint32 `json:"roleID"` } // ValidateCredentials hashes pass and salt and returns comparison result with resultHash diff --git a/json_utility.go b/json_utility.go index c74202b..da109e1 100644 --- a/json_utility.go +++ b/json_utility.go @@ -88,7 +88,11 @@ func QueEntityModelUpdate(entityType string, v interface{}) { updateQue[entityType], _ = json.Marshal(v) } -func UpdateEntityModels(forceUpdate bool) (total, upd, add int, err error) { +func UpdateEntityModels(command string) (total, upd, add int, err error) { + if command != "force" && command != "missing" { + return total, 0, 0, errors.New("uknown command: " + command) + } + if !inited { return 0, 0, 0, errors.New("webutil: metadata not initialized but update was tried.") } @@ -100,7 +104,7 @@ func UpdateEntityModels(forceUpdate bool) (total, upd, add int, err error) { for k, _ := range updateQue { if _, exists := metadata[k]; exists { - if forceUpdate { + if command == "force" { forUpdate = append(forUpdate, k) } } else { @@ -109,8 +113,6 @@ func UpdateEntityModels(forceUpdate bool) (total, upd, add int, err error) { } for _, k := range forUpdate { - fmt.Printf("for update: %s\n", k) - _, err := metadataDB.PrepAndExe(`update entities set entity_model = :1 where entity_type = :2`, @@ -122,12 +124,11 @@ func UpdateEntityModels(forceUpdate bool) (total, upd, add int, err error) { continue } upd++ + fmt.Printf("webutility: updated %s payload model\n", k) } blankPayload, _ := json.Marshal(Payload{}) for _, k := range forAdd { - fmt.Printf("for add: %s\n", k) - _, err := metadataDB.PrepAndExe(`insert into entities (projekat, metadata, entity_type, entity_model) values(:1, :2, :3, :4)`, @@ -142,6 +143,8 @@ func UpdateEntityModels(forceUpdate bool) (total, upd, add int, err error) { } metadata[k] = Payload{} add++ + fmt.Printf("webutility: added %s to the payload models\n", k) + } return total, upd, add, nil