diff --git a/db.go b/db.go index 4300086..7ebca97 100644 --- a/db.go +++ b/db.go @@ -66,7 +66,7 @@ func (sdb *storageDB) Open(filePath string) error { sdb.dbOpen = false if _, err = os.Stat(filePath); err == nil { - // File exists, open and check integrity + // File exists, open and check the integrity sdb.sDB, err = sql.Open("sqlite3", "file:"+filePath+cDBOpenParms) if err != nil { return err @@ -79,7 +79,7 @@ func (sdb *storageDB) Open(filePath string) error { return nil } - // File does not exists + // File does not exist, create it sdb.sDB, err = sql.Open("sqlite3", "file:"+filePath+cDBOpenParms) if err != nil { return err diff --git a/db_fields.go b/db_fields.go index 553f166..6cfe641 100644 --- a/db_fields.go +++ b/db_fields.go @@ -34,7 +34,7 @@ const sqlInsertField = ` VALUES (?,?,?,?,?,?,?,0) ` -func (sdb *storageDB) dbInsertField(itemID int64, field BSField) (fieldId int64, err error) { +func (sdb *storageDB) dbInsertField(itemID int64, field OxiField) (fieldId int64, err error) { if sdb.sTX == nil { return 0, formError(BSERR00003DbTransactionFailed, "dbInsertField") @@ -72,7 +72,7 @@ const sqlListItemFields = ` WHERE deleted='0' and item_id=? ` -func (sdb *storageDB) dbSelectAllItemFields(itemId int64) (fields []BSField, err error) { +func (sdb *storageDB) dbSelectAllItemFields(itemId int64) (fields []OxiField, err error) { rows, err := sdb.sDB.Query(sqlListItemFields, itemId) if err != nil { @@ -85,22 +85,22 @@ func (sdb *storageDB) dbSelectAllItemFields(itemId int64) (fields []BSField, err } }() - var bsField BSField + var field OxiField for rows.Next() { - err = rows.Scan(&bsField.ID, - &bsField.Name, - &bsField.Icon, - &bsField.Value, - &bsField.ValueType, - &bsField.Created, - &bsField.Updated, - &bsField.Deleted) + err = rows.Scan(&field.ID, + &field.Name, + &field.Icon, + &field.Value, + &field.ValueType, + &field.Created, + &field.Updated, + &field.Deleted) if err != nil { return fields, err } - fields = append(fields, bsField) + fields = append(fields, field) } return fields, nil } @@ -138,7 +138,7 @@ const sqlGetField = ` WHERE field_id=? ` -func (sdb *storageDB) dbGetFieldById(fieldId int64) (field BSField, err error) { +func (sdb *storageDB) dbGetFieldById(fieldId int64) (field OxiField, err error) { rows, err := sdb.sDB.Query(sqlGetField, fieldId) if err != nil { @@ -151,18 +151,16 @@ func (sdb *storageDB) dbGetFieldById(fieldId int64) (field BSField, err error) { } }() - var bsField BSField - if rows.Next() { - err = rows.Scan(&bsField.ID, - &bsField.Name, - &bsField.Icon, - &bsField.Value, - &bsField.ValueType, - &bsField.Created, - &bsField.Updated, - &bsField.Deleted) - return bsField, err + err = rows.Scan(&field.ID, + &field.Name, + &field.Icon, + &field.Value, + &field.ValueType, + &field.Created, + &field.Updated, + &field.Deleted) + return field, err } return field, errors.New(BSERR00021FieldsReadFailed) } diff --git a/db_items.go b/db_items.go index 2002fd9..d8478bc 100644 --- a/db_items.go +++ b/db_items.go @@ -107,7 +107,7 @@ const sqlListItemsWithDeleted = ` FROM items ` -func (sdb *storageDB) dbSelectAllItems(returnDeleted bool) (items []BSItem, err error) { +func (sdb *storageDB) dbSelectAllItems(returnDeleted bool) (items []OxiItem, err error) { var sqlList string if returnDeleted { sqlList = sqlListItemsWithDeleted @@ -126,24 +126,24 @@ func (sdb *storageDB) dbSelectAllItems(returnDeleted bool) (items []BSItem, err }() - var bsItem BSItem + var item OxiItem for rows.Next() { - err = rows.Scan(&bsItem.ID, - &bsItem.Name, - &bsItem.Icon, - &bsItem.Created, - &bsItem.Updated, - &bsItem.Deleted) + err = rows.Scan(&item.ID, + &item.Name, + &item.Icon, + &item.Created, + &item.Updated, + &item.Deleted) if err != nil { return items, err } - if bsItem.Deleted && !returnDeleted { + if item.Deleted && !returnDeleted { continue } - items = append(items, bsItem) + items = append(items, item) } return items, nil } @@ -188,7 +188,7 @@ const sqlGetItemByIdWithDeleted = ` WHERE item_id=? ` -func (sdb *storageDB) dbGetItemById(itemId int64, withDeleted bool) (item BSItem, err error) { +func (sdb *storageDB) dbGetItemById(itemId int64, withDeleted bool) (item OxiItem, err error) { var sqlRequest string if withDeleted { sqlRequest = sqlGetItemByIdWithDeleted @@ -216,17 +216,17 @@ func (sdb *storageDB) dbGetItemById(itemId int64, withDeleted bool) (item BSItem }() if rows.Next() { - var bsItem BSItem - err = rows.Scan(&bsItem.ID, - &bsItem.Name, - &bsItem.Icon, - &bsItem.Created, - &bsItem.Updated, - &bsItem.Deleted) + + err = rows.Scan(&item.ID, + &item.Name, + &item.Icon, + &item.Created, + &item.Updated, + &item.Deleted) if err != nil { return item, err } - return bsItem, nil + return item, nil } return item, formError(BSERR00019ItemNotFound) } diff --git a/db_settings.go b/db_settings.go index bb1d431..5773ccd 100644 --- a/db_settings.go +++ b/db_settings.go @@ -11,10 +11,10 @@ type SettingInfo struct { const sqlCreateTableSettings = ` CREATE TABLE IF NOT EXISTS settings ( - database_id CHAR PRIMARY KEY NOT NULL, - keyword CHAR NOT NULL, - crypt_id CHAR NOT NULL, - database_version INT NOT NULL, + database_id VARCHAR PRIMARY KEY NOT NULL, + keyword VARCHAR NOT NULL, + crypt_id VARCHAR NOT NULL, + database_version INTEGER NOT NULL, update_timestamp DATETIME NOT NULL, sync_timestamp DATETIME NOT NULL ) diff --git a/db_tags.go b/db_tags.go index 50cf61b..d99a052 100644 --- a/db_tags.go +++ b/db_tags.go @@ -10,6 +10,7 @@ const sqlCreateTableTags = ` CREATE TABLE IF NOT EXISTS tags ( tag_id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR NOT NULL, + color VARCHAR NOT NULL, created DATETIME NOT NULL, updated DATETIME NOT NULL, deleted BOOLEAN NOT NULL CHECK (deleted IN (0,1)) default '0' @@ -19,8 +20,9 @@ const sqlCreateTableTags = ` const sqlCreateTableItemsTags = ` CREATE TABLE IF NOT EXISTS items_tags ( it_id INTEGER PRIMARY KEY AUTOINCREMENT, - item_id INT NOT NULL, - tag_id INT NOT NULL, + item_id INTEGER NOT NULL, + tag_id INTEGER NOT NULL, + created DATETIME NOT NULL, updated DATETIME NOT NULL, deleted BOOLEAN NOT NULL CHECK (deleted IN (0,1)) default '0', FOREIGN KEY (item_id) REFERENCES items(item_id), @@ -29,11 +31,11 @@ const sqlCreateTableItemsTags = ` ` const sqlInsertTag = ` - INSERT INTO tags (name,created,updated,deleted) - VALUES (?,?,?,0) + INSERT INTO tags (name,color,created,updated,deleted) + VALUES (?,?,?,?,0) ` -func (sdb *storageDB) dbInsertTag(tagName string) (tagId int64, err error) { +func (sdb *storageDB) dbInsertTag(tagName string, color string) (tagId int64, err error) { if sdb.sTX == nil { return 0, formError(BSERR00003DbTransactionFailed, "dbInsertTag") } @@ -45,6 +47,7 @@ func (sdb *storageDB) dbInsertTag(tagName string) (tagId int64, err error) { return 0, formError(BSERR00006DbInsertFailed, err.Error(), "dbInsertTag") } res, errStmt := stmt.Exec(tagName, + color, creationTime, creationTime) @@ -64,8 +67,8 @@ func (sdb *storageDB) dbInsertTag(tagName string) (tagId int64, err error) { } const sqlAssignTagToItem = ` - INSERT INTO items_tags (item_id, tag_id, updated, deleted) - VALUES (?,?,?,0) + INSERT INTO items_tags (item_id, tag_id, created, updated, deleted) + VALUES (?,?,?,?,0) ` func (sdb *storageDB) dbAssignTag(tagId int64, itemId int64) (itId int64, err error) { @@ -80,7 +83,7 @@ func (sdb *storageDB) dbAssignTag(tagId int64, itemId int64) (itId int64, err er return 0, formError(BSERR00006DbInsertFailed, err.Error(), "dbAssignTag") } res, errStmt := stmt.Exec(itemId, tagId, - creationTime) + creationTime, creationTime) if errStmt != nil { return 0, formError(BSERR00006DbInsertFailed, errStmt.Error(), "dbAssignTag") @@ -99,7 +102,7 @@ func (sdb *storageDB) dbAssignTag(tagId int64, itemId int64) (itId int64, err er // sqlListItemTags - List all non-deleted items const sqlListItemTags = ` - SELECT tags.tag_id, tags.name, tags.created, tags.updated, tags.deleted + SELECT tags.tag_id, tags.name, tags.color, tags.created, tags.updated, tags.deleted FROM tags INNER JOIN items_tags it on tags.tag_id = it.tag_id WHERE tags.deleted='0' @@ -109,13 +112,13 @@ const sqlListItemTags = ` // sqlListTags - List all available tags (excluding deleted) const sqlListTags = ` - SELECT tag_id, name, created, updated, deleted + SELECT tag_id, name, color, created, updated, deleted FROM tags WHERE tags.deleted='0' ` // dbSelectItemTags - select tags assigned to requested the item -func (sdb *storageDB) dbSelectItemTags(itemId int64) (tags []BSTag, err error) { +func (sdb *storageDB) dbSelectItemTags(itemId int64) (tags []OxiTag, err error) { var rows *sql.Rows if itemId == -1 { @@ -133,19 +136,20 @@ func (sdb *storageDB) dbSelectItemTags(itemId int64) (tags []BSTag, err error) { } }() - var bsTag BSTag + var tag OxiTag for rows.Next() { - err = rows.Scan(&bsTag.ID, - &bsTag.Name, - &bsTag.Created, - &bsTag.Updated, - &bsTag.Deleted) + err = rows.Scan(&tag.ID, + &tag.Name, + &tag.Color, + &tag.Created, + &tag.Updated, + &tag.Deleted) if err != nil { return tags, err } - tags = append(tags, bsTag) + tags = append(tags, tag) } sort.Slice(tags, func(i, j int) bool { return tags[i].Name < tags[j].Name @@ -155,6 +159,6 @@ func (sdb *storageDB) dbSelectItemTags(itemId int64) (tags []BSTag, err error) { } // dbSelectTags - select all available tags -func (sdb *storageDB) dbSelectTags() (tags []BSTag, err error) { +func (sdb *storageDB) dbSelectTags() (tags []OxiTag, err error) { return sdb.dbSelectItemTags(-1) } diff --git a/db_templates.go b/db_templates.go index a8453ac..645c5c9 100644 --- a/db_templates.go +++ b/db_templates.go @@ -77,7 +77,7 @@ const sqlInsertFieldTemplate = ` VALUES (?,?,?,?,?,?,0) ` -func (sdb *storageDB) dbInsertFieldTemplate(itemID int64, field BSField) (fieldId int64, err error) { +func (sdb *storageDB) dbInsertFieldTemplate(itemID int64, field OxiField) (fieldId int64, err error) { if sdb.sTX == nil { return 0, formError(BSERR00003DbTransactionFailed, "dbInsertFieldTemplate") diff --git a/bkvstorage_fields.go b/oxi_fields.go similarity index 93% rename from bkvstorage_fields.go rename to oxi_fields.go index 0306307..680c194 100644 --- a/bkvstorage_fields.go +++ b/oxi_fields.go @@ -31,13 +31,13 @@ func (storage *StorageSingleton) DeleteField(deleteFieldForm UpdateFieldForm) (r // AddNewItem - adds new item func (storage *StorageSingleton) AddNewField(addFieldForm UpdateFieldForm) (response FieldAddedResponse, err error) { - var field BSField + var field OxiField err = storage.checkReadiness() if err != nil { return response, err } - if err := ValidateField(addFieldForm.BSField); err != nil { + if err := ValidateField(addFieldForm.OxiField); err != nil { return response, formError(BSERR00006DbInsertFailed, err.Error()) } @@ -88,7 +88,7 @@ func (storage *StorageSingleton) AddNewField(addFieldForm UpdateFieldForm) (resp } // ReadFieldsByItemID - real all the fields by ItemId -func (storage *StorageSingleton) ReadFieldsByItemID(itemId int64) (fields []BSField, err error) { +func (storage *StorageSingleton) ReadFieldsByItemID(itemId int64) (fields []OxiField, err error) { fieldsEncrypted, err := storage.dbObject.dbSelectAllItemFields(itemId) if err != nil { return fields, err @@ -106,7 +106,7 @@ func (storage *StorageSingleton) ReadFieldsByItemID(itemId int64) (fields []BSFi } // AddNewItem - adds new item -func (storage *StorageSingleton) ReadFieldsByFieldID(fieldId int64) (field BSField, err error) { +func (storage *StorageSingleton) ReadFieldsByFieldID(fieldId int64) (field OxiField, err error) { fieldEncrypted, err := storage.dbObject.dbGetFieldById(fieldId) if err != nil { return field, err @@ -119,7 +119,7 @@ func (storage *StorageSingleton) ReadFieldsByFieldID(fieldId int64) (field BSFie return fieldReady, nil } -func (storage *StorageSingleton) DecryptField(fieldEncrypted BSField) (field BSField, err error) { +func (storage *StorageSingleton) DecryptField(fieldEncrypted OxiField) (field OxiField, err error) { field.Value, err = storage.encObject.Decrypt(fieldEncrypted.Value) if err != nil { return field, err diff --git a/bkvstorage_fields_test.go b/oxi_fields_test.go similarity index 98% rename from bkvstorage_fields_test.go rename to oxi_fields_test.go index 14adad8..9d25188 100644 --- a/bkvstorage_fields_test.go +++ b/oxi_fields_test.go @@ -18,7 +18,7 @@ func testHelperCreateField(itemId int64) (fieldId int64, err error) { fieldResult, errField := bsInstance.AddNewField( UpdateFieldForm{ ItemID: itemId, - BSField: BSField{ + OxiField: OxiField{ Name: cFieldName01, Icon: cFieldIcon01, ValueType: VTText, @@ -106,7 +106,7 @@ func TestDeleteField(t *testing.T) { } respDel, errDel := bsInstance.DeleteField(UpdateFieldForm{ - BSField: BSField{ + OxiField: OxiField{ ID: fieldId, }, }) diff --git a/bkvstorage_items.go b/oxi_items.go similarity index 98% rename from bkvstorage_items.go rename to oxi_items.go index ee029ad..a5d0c27 100644 --- a/bkvstorage_items.go +++ b/oxi_items.go @@ -150,7 +150,7 @@ func (storage *StorageSingleton) AddNewItem(addItemParams UpdateItemForm) (respo } // ReadAllItems - read all not deleted items from the database and decrypt them -func (storage *StorageSingleton) ReadAllItems(readTags bool, readDeleted bool) (items []BSItem, err error) { +func (storage *StorageSingleton) ReadAllItems(readTags bool, readDeleted bool) (items []OxiItem, err error) { err = storage.checkReadiness() if err != nil { return items, err @@ -182,7 +182,7 @@ func (storage *StorageSingleton) ReadAllItems(readTags bool, readDeleted bool) ( } // ReadItemById - read item by its Id -func (storage *StorageSingleton) ReadItemById(itemId int64, withDeleted bool) (item BSItem, err error) { +func (storage *StorageSingleton) ReadItemById(itemId int64, withDeleted bool) (item OxiItem, err error) { err = storage.checkReadiness() if err != nil { return item, err diff --git a/bkvstorage_items_test.go b/oxi_items_test.go similarity index 98% rename from bkvstorage_items_test.go rename to oxi_items_test.go index ca77f38..45df67e 100644 --- a/bkvstorage_items_test.go +++ b/oxi_items_test.go @@ -19,7 +19,7 @@ func testHelperCreateItem() (itemId int64, err error) { } response, err := bsInstance.AddNewItem( UpdateItemForm{ - BSItem: BSItem{ + OxiItem: OxiItem{ Name: cTestItemName01, Icon: cTestItemIcon01, }, @@ -57,7 +57,7 @@ func TestUpdateItemName(t *testing.T) { updateResponse, errUpdated := bsInstance.UpdateItem( UpdateItemForm{ - BSItem: BSItem{ + OxiItem: OxiItem{ ID: itemId, Name: cTestItemName02, }, @@ -128,7 +128,7 @@ func TestDeleteItem(t *testing.T) { delResponse, errDelete := bsInstance.DeleteItem( UpdateItemForm{ - BSItem: BSItem{ + OxiItem: OxiItem{ ID: itemId, }, }, @@ -210,7 +210,7 @@ func TestAddItemWithNonExistingIcon(t *testing.T) { response, err := bsInstance.AddNewItem( UpdateItemForm{ - BSItem: BSItem{ + OxiItem: OxiItem{ Name: cTestItemName01, Icon: cTestNonExistingIcon, }, @@ -278,7 +278,7 @@ func TestUpdateItemIcon(t *testing.T) { updateIconResponse, errIconUpdated := bsInstance.UpdateItem( UpdateItemForm{ - BSItem: BSItem{ + OxiItem: OxiItem{ ID: itemId, Icon: cTestItemIcon02, }, diff --git a/bkvstorage.go b/oxi_main.go similarity index 100% rename from bkvstorage.go rename to oxi_main.go diff --git a/bkvstorage_test.go b/oxi_main_test.go similarity index 100% rename from bkvstorage_test.go rename to oxi_main_test.go diff --git a/bkvstorage_password.go b/oxi_password.go similarity index 100% rename from bkvstorage_password.go rename to oxi_password.go diff --git a/bkvstorage_directory.go b/oxi_repository.go similarity index 100% rename from bkvstorage_directory.go rename to oxi_repository.go diff --git a/bkvstorage_directory_test.go b/oxi_repository_test.go similarity index 100% rename from bkvstorage_directory_test.go rename to oxi_repository_test.go diff --git a/bkvstorage_tags.go b/oxi_tags.go similarity index 81% rename from bkvstorage_tags.go rename to oxi_tags.go index 43e658f..238606f 100644 --- a/bkvstorage_tags.go +++ b/oxi_tags.go @@ -43,12 +43,17 @@ func (storage *StorageSingleton) AddNewTag(addTagParam UpdateTagForm) (response return response, formError(BSERR00006DbInsertFailed, err.Error()) } - encryptedTag, errEnc := storage.encObject.Encrypt(addTagParam.Name) - if errEnc != nil { - return response, formError(BSERR00006DbInsertFailed, errEnc.Error()) + encryptedTag, errEncT := storage.encObject.Encrypt(addTagParam.Name) + if errEncT != nil { + return response, formError(BSERR00006DbInsertFailed, errEncT.Error()) } - response.TagId, err = storage.dbObject.dbInsertTag(encryptedTag) + encryptedColor, errEncC := storage.encObject.Encrypt(addTagParam.Color) + if errEncC != nil { + return response, formError(BSERR00006DbInsertFailed, errEncC.Error()) + } + + response.TagId, err = storage.dbObject.dbInsertTag(encryptedTag, encryptedColor) if err != nil { errEndTX := storage.dbObject.RollbackTX() if errEndTX != nil { @@ -68,7 +73,7 @@ func (storage *StorageSingleton) AddNewTag(addTagParam UpdateTagForm) (response } // ReadFieldsByItemID - real all the fields by ItemId -func (storage *StorageSingleton) ReadTagsByItemID(itemId int64) (tags []BSTag, err error) { +func (storage *StorageSingleton) ReadTagsByItemID(itemId int64) (tags []OxiTag, err error) { fieldsEncrypted, err := storage.dbObject.dbSelectItemTags(itemId) if err != nil { return tags, err @@ -86,7 +91,7 @@ func (storage *StorageSingleton) ReadTagsByItemID(itemId int64) (tags []BSTag, e } // ReadFieldsByItemID - real all the fields by ItemId -func (storage *StorageSingleton) GetTags() (tags []BSTag, err error) { +func (storage *StorageSingleton) GetTags() (tags []OxiTag, err error) { fieldsEncrypted, err := storage.dbObject.dbSelectTags() if err != nil { return tags, err @@ -103,9 +108,10 @@ func (storage *StorageSingleton) GetTags() (tags []BSTag, err error) { return tags, nil } -func (storage *StorageSingleton) DecryptTag(tag BSTag) (decryptedTag BSTag, err error) { +func (storage *StorageSingleton) DecryptTag(tag OxiTag) (decryptedTag OxiTag, err error) { decryptedTag = tag decryptedTag.Name, err = storage.encObject.Decrypt(tag.Name) + decryptedTag.Color, err = storage.encObject.Decrypt(tag.Color) if err != nil { return decryptedTag, err } diff --git a/bkvstorage_tags_test.go b/oxi_tags_test.go similarity index 75% rename from bkvstorage_tags_test.go rename to oxi_tags_test.go index 55a3b7a..dd1f58b 100644 --- a/bkvstorage_tags_test.go +++ b/oxi_tags_test.go @@ -6,9 +6,11 @@ import ( ) const cTestTag1 = "test_tag1" +const cTestTagColor1 = "#ffff00" const cTestTag2 = "test_tag2" +const cTesttagColor2 = "#ff0000" -func testHelperCreateItemAndTag(testTag string) (itemId int64, tagId int64, err error) { +func testHelperCreateItemAndTag(testTag string, testColor string) (itemId int64, tagId int64, err error) { bsInstance := GetInstance() err = bsInstance.Unlock(dbPass) if err != nil { @@ -16,7 +18,7 @@ func testHelperCreateItemAndTag(testTag string) (itemId int64, tagId int64, err } response, err := bsInstance.AddNewItem( UpdateItemForm{ - BSItem: BSItem{ + OxiItem: OxiItem{ Name: cTestItemName01, Icon: cTestItemIcon01, }, @@ -32,8 +34,9 @@ func testHelperCreateItemAndTag(testTag string) (itemId int64, tagId int64, err responseTag, err := bsInstance.AddNewTag( UpdateTagForm{ 0, - BSTag{ - Name: testTag, + OxiTag{ + Name: testTag, + Color: testColor, }, }, ) @@ -53,7 +56,7 @@ func testHelperCreateItemAndTag(testTag string) (itemId int64, tagId int64, err } func TestCreateItemAndTag(t *testing.T) { - _, tagId, err := testHelperCreateItemAndTag(cTestTag1) + _, tagId, err := testHelperCreateItemAndTag(cTestTag1, cTestTagColor1) if err != nil { t.Error(err) @@ -78,7 +81,8 @@ func TestCreateItemAndTag(t *testing.T) { found := false for _, tag := range availableTags { - if tag.ID == tagId && tag.Name == cTestTag1 && tag.Deleted == false { + if tag.ID == tagId && tag.Name == cTestTag1 && + tag.Color == cTestTagColor1 && tag.Deleted == false { found = true break } @@ -91,8 +95,8 @@ func TestCreateItemAndTag(t *testing.T) { } func TestAssignTagToItems(t *testing.T) { - itemId1, tagId1, err := testHelperCreateItemAndTag(cTestTag1) - _, tagId2, err := testHelperCreateItemAndTag(cTestTag2) + itemId1, tagId1, err := testHelperCreateItemAndTag(cTestTag1, cTestTagColor1) + _, tagId2, err := testHelperCreateItemAndTag(cTestTag2, cTesttagColor2) if err != nil { t.Error(err) @@ -111,7 +115,7 @@ func TestAssignTagToItems(t *testing.T) { responseTA, errTA := bsInstance.AssignTag( UpdateTagForm{ ItemID: itemId1, - BSTag: BSTag{ + OxiTag: OxiTag{ ID: tagId1, }, }, @@ -131,7 +135,7 @@ func TestAssignTagToItems(t *testing.T) { responseTA2, errTA2 := bsInstance.AssignTag( UpdateTagForm{ ItemID: itemId1, - BSTag: BSTag{ + OxiTag: OxiTag{ ID: tagId2, }, }, @@ -156,10 +160,10 @@ func TestAssignTagToItems(t *testing.T) { return } for _, tag := range tags { - if tag.ID == tagId1 && tag.Name == cTestTag1 { + if tag.ID == tagId1 && tag.Name == cTestTag1 && tag.Color == cTestTagColor1 && tag.Deleted == false { foundTags++ } - if tag.ID == tagId2 && tag.Name == cTestTag2 { + if tag.ID == tagId2 && tag.Name == cTestTag2 && tag.Color == cTesttagColor2 && tag.Deleted == false { foundTags++ } } diff --git a/structures.go b/structures.go index 0152105..147a59a 100644 --- a/structures.go +++ b/structures.go @@ -1,19 +1,19 @@ package oxilib -// BSItem - item structure -type BSItem struct { - ID int64 `json:"item_id"` - Name string `json:"item_name"` - Icon string `json:"item_icon"` - Created string `json:"created"` - Updated string `json:"updated"` - Deleted bool `json:"deleted"` - Fields []BSField `json:"fields"` - Tags []BSTag `json:"tags"` -} - -// BSField - fields definitions -type BSField struct { +// OxiItem - item structure +type OxiItem struct { + ID int64 `json:"item_id"` + Name string `json:"item_name"` + Icon string `json:"item_icon"` + Created string `json:"created"` + Updated string `json:"updated"` + Deleted bool `json:"deleted"` + Fields []OxiField `json:"fields"` + Tags []OxiTag `json:"tags"` +} + +// OxiField - fields definitions +type OxiField struct { ID int64 `json:"field_id"` Name string `json:"field_name"` Icon string `json:"field_icon"` @@ -24,10 +24,11 @@ type BSField struct { Deleted bool `json:"deleted"` } -// BSTag - tags definitions -type BSTag struct { +// OxiTag - tags definitions +type OxiTag struct { ID int64 `json:"tag_id"` Name string `json:"tag_name"` + Color string `json:"color"` Created string `json:"created"` Updated string `json:"updated"` Deleted bool `json:"deleted"` @@ -43,19 +44,19 @@ type CommonResponse struct { // ItemResponse - response returning one item type ItemResponse struct { CommonResponse - BSItem + OxiItem } // ItemsResponse - response returning many items type ItemsResponse struct { CommonResponse - Items []BSItem `json:"items"` + Items []OxiItem `json:"items"` } // UpdateFieldForm - input structure to add or update the field type UpdateFieldForm struct { ItemID int64 `json:"item_id"` - BSField + OxiField } // FieldAddedResponse - response structure for adding field @@ -66,7 +67,7 @@ type FieldAddedResponse struct { // UpdateItemForm - input structure to add the item type UpdateItemForm struct { - BSItem + OxiItem } // TagAddedResponse - response structure for adding item @@ -77,7 +78,7 @@ type TagAddedResponse struct { type UpdateTagForm struct { ItemID int64 `json:"item_id"` - BSTag + OxiTag } type TagAssignedResponse struct { diff --git a/validators.go b/validators.go index cd6b38a..43f6228 100644 --- a/validators.go +++ b/validators.go @@ -2,7 +2,7 @@ package oxilib import "errors" -func ValidateField(field BSField) error { +func ValidateField(field OxiField) error { if !CheckIfExistsFontAwesome(field.Icon) { return errors.New(BSERR00022ValidationFailed + ": icon not found") } diff --git a/validators_test.go b/validators_test.go index 0fdde19..ef1b4f5 100644 --- a/validators_test.go +++ b/validators_test.go @@ -8,7 +8,7 @@ const cValidateFieldName01 = "my new field" const cValidateFieldType01wrong = "kjenwjdnwkjdnwk" func TestFieldValidator(t *testing.T) { - field := BSField{Name: cValidateFieldName01, ValueType: VTText, Icon: cValidateFieldIcon01} + field := OxiField{Name: cValidateFieldName01, ValueType: VTText, Icon: cValidateFieldIcon01} err := ValidateField(field) if err != nil { t.Errorf("Expected no error, retrived: %s", err.Error()) @@ -16,7 +16,7 @@ func TestFieldValidator(t *testing.T) { } func TestFieldValidatorEmptyName(t *testing.T) { - field := BSField{ValueType: VTText, Icon: cValidateFieldIcon01} + field := OxiField{ValueType: VTText, Icon: cValidateFieldIcon01} err := ValidateField(field) if err == nil { t.Errorf("Expected validation error because of empty field name") @@ -24,7 +24,7 @@ func TestFieldValidatorEmptyName(t *testing.T) { } func TestFieldValidatorWrongValueType(t *testing.T) { - field := BSField{Name: cValidateFieldName01, ValueType: cValidateFieldType01wrong, Icon: cValidateFieldIcon01} + field := OxiField{Name: cValidateFieldName01, ValueType: cValidateFieldType01wrong, Icon: cValidateFieldIcon01} err := ValidateField(field) if err == nil { t.Errorf("Expected validation error because of not supported value type") @@ -32,7 +32,7 @@ func TestFieldValidatorWrongValueType(t *testing.T) { } func TestFieldValidatorNotExistingIcon(t *testing.T) { - field := BSField{Name: cValidateFieldName01, ValueType: VTText, Icon: cValidateFieldIcon02wrong} + field := OxiField{Name: cValidateFieldName01, ValueType: VTText, Icon: cValidateFieldIcon02wrong} err := ValidateField(field) if err == nil { t.Errorf("Expected error because of non existing icon name ")