diff --git a/api.go b/api.go index 3a45722..b2ad1c7 100644 --- a/api.go +++ b/api.go @@ -98,12 +98,13 @@ type TextNote struct { //Note Note type Note struct { - ID int64 `json:"id"` - Title string `json:"title"` - Type string `json:"type"` - OwnerEmail string `json:"ownerEmail"` - NoteItems interface{} `json:"noteItems"` - LastUsed time.Time `json:"lastUsed"` + ID int64 `json:"id"` + Title string `json:"title"` + Type string `json:"type"` + OwnerEmail string `json:"ownerEmail"` + NoteTextItems []NoteItem `json:"noteTextItems"` + NoteCheckboxItems []CheckboxNoteItem `json:"noteCheckboxItems"` + LastUsed time.Time `json:"lastUsed"` } //NoteItem NoteItem diff --git a/checkboxItem.go b/checkboxItem.go index aaeeb1b..7f7e3ec 100644 --- a/checkboxItem.go +++ b/checkboxItem.go @@ -96,18 +96,16 @@ func (a *NotesAPI) setSavedCheckboxItem(cbi *CheckboxNoteItem) { a.log.Debug("saving in updating in for loop: ", a.noteList[i]) if a.noteList[i].ID == cbi.NoteID { a.log.Debug("found cb and updating: ", a.noteList[i]) - ilst := a.noteList[i].NoteItems.([]CheckboxNoteItem) - for ii := range ilst { - a.log.Debug("found cb item: ", ilst[ii]) - if ilst[ii].ID == cbi.ID { - a.log.Debug("found cb item and updating: ", ilst[ii]) + for ii := range a.noteList[i].NoteCheckboxItems { + a.log.Debug("found cb item: ", a.noteList[i].NoteCheckboxItems[ii]) + if a.noteList[i].NoteCheckboxItems[ii].ID == cbi.ID { + a.log.Debug("found cb item and updating: ", a.noteList[i].NoteCheckboxItems[ii]) a.log.Debug("updating to: ", *cbi) - ilst[ii].Checked = cbi.Checked - ilst[ii].Text = cbi.Text + a.noteList[i].NoteCheckboxItems[ii].Checked = cbi.Checked + a.noteList[i].NoteCheckboxItems[ii].Text = cbi.Text break } } - a.noteList[i].NoteItems = ilst break } } @@ -119,10 +117,10 @@ func (a *NotesAPI) setSavedCheckboxItem(cbi *CheckboxNoteItem) { for i := range a.noteList { if a.noteList[i].ID == cbi.NoteID { a.log.Debug("adding new cb item: ", *cbi) - ilst := a.noteList[i].NoteItems.([]CheckboxNoteItem) - a.log.Debug("existing cb item: ", ilst) - ilst = append(ilst, *cbi) - a.noteList[i].NoteItems = ilst + //ilst := a.noteList[i].NoteItems.([]CheckboxNoteItem) + //a.log.Debug("existing cb item: ", ilst) + a.noteList[i].NoteCheckboxItems = append(a.noteList[i].NoteCheckboxItems, *cbi) + //a.noteList[i].NoteItems = ilst break } } diff --git a/checkboxItem_test.go b/checkboxItem_test.go index f00d104..049eec2 100644 --- a/checkboxItem_test.go +++ b/checkboxItem_test.go @@ -259,7 +259,7 @@ func TestNotesAPI_setSavedCheckboxItem(t *testing.T) { n1.ID = 5 n1.LastUsed = time.Now() n1.OwnerEmail = "tester@tst.com" - n1.NoteItems = cbilst + n1.NoteCheckboxItems = cbilst n1.Title = "cb note 1" n1.Type = "checkbox" ntlst = append(ntlst, n1) @@ -274,9 +274,9 @@ func TestNotesAPI_setSavedCheckboxItem(t *testing.T) { api.setSavedCheckboxItem(&cbi3) - ilst := sapi.noteList[0].NoteItems.([]CheckboxNoteItem) + //ilst := sapi.noteList[0].NoteItems.([]CheckboxNoteItem) - if len(ilst) != 3 { + if len(sapi.noteList[0].NoteCheckboxItems) != 3 { t.Fail() } @@ -309,13 +309,12 @@ func TestNotesAPI_setSavedCheckboxItem2(t *testing.T) { cb.Type = "checkbox" api := sapi.GetNew() - var ntlst []Note var n1 Note n1.ID = 5 n1.LastUsed = time.Now() n1.OwnerEmail = "tester@tst.com" - n1.NoteItems = cbilst + n1.NoteCheckboxItems = cbilst n1.Title = "cb note 1" n1.Type = "checkbox" ntlst = append(ntlst, n1) @@ -331,9 +330,9 @@ func TestNotesAPI_setSavedCheckboxItem2(t *testing.T) { api.setSavedCheckboxItem(&cbi3) - ilst := sapi.noteList[0].NoteItems.([]CheckboxNoteItem) + //ilst := sapi.noteList[0].NoteCheckboxItems.([]CheckboxNoteItem) - if len(ilst) != 2 { + if len(sapi.noteList[0].NoteCheckboxItems) != 2 { t.Fail() } diff --git a/coverage.out b/coverage.out index 7ddc200..f9db68f 100644 --- a/coverage.out +++ b/coverage.out @@ -15,14 +15,14 @@ github.com/Ulbora/cocka2notesApi/noteItem.go:78.55,89.2 9 1 github.com/Ulbora/cocka2notesApi/noteItem.go:91.52,93.17 1 1 github.com/Ulbora/cocka2notesApi/noteItem.go:93.17,94.29 1 1 github.com/Ulbora/cocka2notesApi/noteItem.go:94.29,96.38 2 1 -github.com/Ulbora/cocka2notesApi/noteItem.go:96.38,99.26 3 1 -github.com/Ulbora/cocka2notesApi/noteItem.go:108.5,109.10 2 1 -github.com/Ulbora/cocka2notesApi/noteItem.go:99.26,101.31 2 1 -github.com/Ulbora/cocka2notesApi/noteItem.go:101.31,105.12 4 1 +github.com/Ulbora/cocka2notesApi/noteItem.go:96.38,99.49 2 1 +github.com/Ulbora/cocka2notesApi/noteItem.go:109.5,109.10 1 1 +github.com/Ulbora/cocka2notesApi/noteItem.go:99.49,101.54 2 1 +github.com/Ulbora/cocka2notesApi/noteItem.go:101.54,105.12 4 1 github.com/Ulbora/cocka2notesApi/noteItem.go:112.8,112.28 1 1 github.com/Ulbora/cocka2notesApi/noteItem.go:112.28,117.29 4 1 github.com/Ulbora/cocka2notesApi/noteItem.go:117.29,118.38 1 1 -github.com/Ulbora/cocka2notesApi/noteItem.go:118.38,124.10 6 1 +github.com/Ulbora/cocka2notesApi/noteItem.go:118.38,124.10 4 1 github.com/Ulbora/cocka2notesApi/noteItem.go:131.56,133.2 1 1 github.com/Ulbora/cocka2notesApi/noteItem.go:136.59,138.2 1 1 github.com/Ulbora/cocka2notesApi/notesApi.go:47.33,56.2 6 1 @@ -81,16 +81,16 @@ github.com/Ulbora/cocka2notesApi/checkboxItem.go:78.59,89.2 9 1 github.com/Ulbora/cocka2notesApi/checkboxItem.go:91.64,94.17 2 1 github.com/Ulbora/cocka2notesApi/checkboxItem.go:94.17,95.29 1 1 github.com/Ulbora/cocka2notesApi/checkboxItem.go:95.29,97.38 2 1 -github.com/Ulbora/cocka2notesApi/checkboxItem.go:97.38,100.26 3 1 -github.com/Ulbora/cocka2notesApi/checkboxItem.go:110.5,111.10 2 1 -github.com/Ulbora/cocka2notesApi/checkboxItem.go:100.26,102.31 2 1 -github.com/Ulbora/cocka2notesApi/checkboxItem.go:102.31,107.12 5 1 -github.com/Ulbora/cocka2notesApi/checkboxItem.go:114.8,114.28 1 1 -github.com/Ulbora/cocka2notesApi/checkboxItem.go:114.28,119.29 4 1 -github.com/Ulbora/cocka2notesApi/checkboxItem.go:119.29,120.38 1 1 -github.com/Ulbora/cocka2notesApi/checkboxItem.go:120.38,126.10 6 1 -github.com/Ulbora/cocka2notesApi/checkboxItem.go:133.72,135.2 1 1 -github.com/Ulbora/cocka2notesApi/checkboxItem.go:138.75,140.2 1 1 +github.com/Ulbora/cocka2notesApi/checkboxItem.go:97.38,99.53 2 1 +github.com/Ulbora/cocka2notesApi/checkboxItem.go:109.5,109.10 1 1 +github.com/Ulbora/cocka2notesApi/checkboxItem.go:99.53,101.58 2 1 +github.com/Ulbora/cocka2notesApi/checkboxItem.go:101.58,106.12 5 1 +github.com/Ulbora/cocka2notesApi/checkboxItem.go:112.8,112.28 1 1 +github.com/Ulbora/cocka2notesApi/checkboxItem.go:112.28,117.29 4 1 +github.com/Ulbora/cocka2notesApi/checkboxItem.go:117.29,118.38 1 1 +github.com/Ulbora/cocka2notesApi/checkboxItem.go:118.38,124.10 3 1 +github.com/Ulbora/cocka2notesApi/checkboxItem.go:131.72,133.2 1 1 +github.com/Ulbora/cocka2notesApi/checkboxItem.go:136.75,138.2 1 1 github.com/Ulbora/cocka2notesApi/note.go:30.49,35.16 5 1 github.com/Ulbora/cocka2notesApi/note.go:44.2,45.13 2 1 github.com/Ulbora/cocka2notesApi/note.go:35.16,40.15 5 1 @@ -116,31 +116,14 @@ github.com/Ulbora/cocka2notesApi/note.go:148.59,149.28 1 1 github.com/Ulbora/cocka2notesApi/note.go:149.28,150.32 1 1 github.com/Ulbora/cocka2notesApi/note.go:150.32,154.9 4 1 github.com/Ulbora/cocka2notesApi/note.go:159.65,161.28 2 1 -github.com/Ulbora/cocka2notesApi/note.go:200.2,200.13 1 1 +github.com/Ulbora/cocka2notesApi/note.go:201.2,201.13 1 1 github.com/Ulbora/cocka2notesApi/note.go:161.28,163.29 2 1 -github.com/Ulbora/cocka2notesApi/note.go:163.29,171.73 8 1 -github.com/Ulbora/cocka2notesApi/note.go:197.4,197.9 1 1 -github.com/Ulbora/cocka2notesApi/note.go:171.73,172.27 1 0 -github.com/Ulbora/cocka2notesApi/note.go:189.5,189.25 1 0 -github.com/Ulbora/cocka2notesApi/note.go:172.27,174.30 2 0 -github.com/Ulbora/cocka2notesApi/note.go:187.6,187.29 1 0 -github.com/Ulbora/cocka2notesApi/note.go:174.30,175.22 1 0 -github.com/Ulbora/cocka2notesApi/note.go:184.7,185.32 2 0 -github.com/Ulbora/cocka2notesApi/note.go:175.22,177.8 1 0 -github.com/Ulbora/cocka2notesApi/note.go:177.13,177.33 1 0 -github.com/Ulbora/cocka2notesApi/note.go:177.33,179.8 1 0 -github.com/Ulbora/cocka2notesApi/note.go:179.13,179.34 1 0 -github.com/Ulbora/cocka2notesApi/note.go:179.34,181.8 1 0 -github.com/Ulbora/cocka2notesApi/note.go:181.13,181.31 1 0 -github.com/Ulbora/cocka2notesApi/note.go:181.31,183.8 1 0 -github.com/Ulbora/cocka2notesApi/note.go:190.10,194.5 2 1 -github.com/Ulbora/cocka2notesApi/note.go:203.51,204.28 1 1 -github.com/Ulbora/cocka2notesApi/note.go:204.28,205.32 1 1 -github.com/Ulbora/cocka2notesApi/note.go:205.32,209.9 4 1 -github.com/Ulbora/cocka2notesApi/note.go:214.57,216.28 2 1 -github.com/Ulbora/cocka2notesApi/note.go:231.2,231.13 1 1 -github.com/Ulbora/cocka2notesApi/note.go:216.28,217.29 1 1 -github.com/Ulbora/cocka2notesApi/note.go:217.29,225.28 8 1 -github.com/Ulbora/cocka2notesApi/note.go:228.4,228.9 1 1 -github.com/Ulbora/cocka2notesApi/note.go:225.28,227.5 1 1 -github.com/Ulbora/cocka2notesApi/note.go:235.49,237.2 1 1 +github.com/Ulbora/cocka2notesApi/note.go:163.29,198.9 8 1 +github.com/Ulbora/cocka2notesApi/note.go:204.51,205.28 1 1 +github.com/Ulbora/cocka2notesApi/note.go:205.28,206.32 1 1 +github.com/Ulbora/cocka2notesApi/note.go:206.32,211.9 5 1 +github.com/Ulbora/cocka2notesApi/note.go:216.57,218.28 2 1 +github.com/Ulbora/cocka2notesApi/note.go:230.2,230.13 1 1 +github.com/Ulbora/cocka2notesApi/note.go:218.28,219.29 1 1 +github.com/Ulbora/cocka2notesApi/note.go:219.29,227.9 8 1 +github.com/Ulbora/cocka2notesApi/note.go:234.49,236.2 1 1 diff --git a/note.go b/note.go index ba4f420..cf712bb 100644 --- a/note.go +++ b/note.go @@ -167,32 +167,33 @@ func (a *NotesAPI) getSavedCheckboxNote(id int64) *CheckboxNote { cbn.OwnerEmail = a.noteList[i].OwnerEmail cbn.Title = a.noteList[i].Title cbn.Type = a.noteList[i].Type - var ilst []CheckboxNoteItem - if rec, ok := a.noteList[i].NoteItems.([]map[string]interface{}); ok { - for _, r := range rec { - var ci CheckboxNoteItem - for key, val := range r { - if key == "id" { - ci.ID = val.(int64) - } else if key == "noteId" { - ci.NoteID = val.(int64) - } else if key == "checked" { - ci.Checked = val.(bool) - } else if key == "text" { - ci.Text = val.(string) - } - a.log.Debug("key: ", key) - a.log.Debug("val: ", val) - } - ilst = append(ilst, ci) - } - cbn.NoteItems = ilst - } else { - ilst = a.noteList[i].NoteItems.([]CheckboxNoteItem) - cbn.NoteItems = ilst - //fmt.Printf("record not a map[string]interface{}: %v\n", record) - } - //ilst := a.noteList[i].NoteItems.([]CheckboxNoteItem) + cbn.NoteItems = a.noteList[i].NoteCheckboxItems + // var ilst []CheckboxNoteItem + // if rec, ok := a.noteList[i].NoteItems.([]map[string]interface{}); ok { + // for _, r := range rec { + // var ci CheckboxNoteItem + // for key, val := range r { + // if key == "id" { + // ci.ID = val.(int64) + // } else if key == "noteId" { + // ci.NoteID = val.(int64) + // } else if key == "checked" { + // ci.Checked = val.(bool) + // } else if key == "text" { + // ci.Text = val.(string) + // } + // a.log.Debug("key: ", key) + // a.log.Debug("val: ", val) + // } + // ilst = append(ilst, ci) + // } + // cbn.NoteItems = ilst + // } else { + // ilst = a.noteList[i].NoteItems.([]CheckboxNoteItem) + // cbn.NoteItems = ilst + // //fmt.Printf("record not a map[string]interface{}: %v\n", record) + // } + // //ilst := a.noteList[i].NoteItems.([]CheckboxNoteItem) break } @@ -205,6 +206,7 @@ func (a *NotesAPI) setSavedTextNote(tn *TextNote) { if a.noteList[i].ID == tn.ID { a.log.Debug("found : ", a.noteList[i]) a.noteList[i].Title = tn.Title + a.noteList[i].NoteTextItems = tn.NoteItems a.log.Debug("updated : ", a.noteList[i]) break } @@ -221,10 +223,7 @@ func (a *NotesAPI) getSavedTextNote(id int64) *TextNote { txn.OwnerEmail = a.noteList[i].OwnerEmail txn.Title = a.noteList[i].Title txn.Type = a.noteList[i].Type - ilst := a.noteList[i].NoteItems.([]NoteItem) - for _, ti := range ilst { - txn.NoteItems = append(txn.NoteItems, ti) - } + txn.NoteItems = a.noteList[i].NoteTextItems break } } diff --git a/noteItem.go b/noteItem.go index f59a19a..36def7a 100644 --- a/noteItem.go +++ b/noteItem.go @@ -95,17 +95,17 @@ func (a *NotesAPI) setSavedTextItem(cbi *NoteItem) { a.log.Debug("saving in updating in for loop: ", a.noteList[i]) if a.noteList[i].ID == cbi.NoteID { a.log.Debug("found text and updating: ", a.noteList[i]) - ilst := a.noteList[i].NoteItems.([]NoteItem) - for ii := range ilst { - a.log.Debug("found cb item: ", ilst[ii]) - if ilst[ii].ID == cbi.ID { - a.log.Debug("found cb item and updating: ", ilst[ii]) + //ilst := a.noteList[i].NoteItems.([]NoteItem) + for ii := range a.noteList[i].NoteTextItems { + a.log.Debug("found cb item: ", a.noteList[i].NoteTextItems[ii]) + if a.noteList[i].NoteTextItems[ii].ID == cbi.ID { + a.log.Debug("found cb item and updating: ", a.noteList[i].NoteTextItems[ii]) a.log.Debug("updating to: ", *cbi) - ilst[ii].Text = cbi.Text + a.noteList[i].NoteTextItems[ii].Text = cbi.Text break } } - a.noteList[i].NoteItems = ilst + //a.noteList[i].NoteItems = ilst break } } @@ -117,10 +117,10 @@ func (a *NotesAPI) setSavedTextItem(cbi *NoteItem) { for i := range a.noteList { if a.noteList[i].ID == cbi.NoteID { a.log.Debug("adding new text item: ", *cbi) - ilst := a.noteList[i].NoteItems.([]NoteItem) - a.log.Debug("existing cb item: ", ilst) - ilst = append(ilst, *cbi) - a.noteList[i].NoteItems = ilst + //ilst := a.noteList[i].NoteItems.([]NoteItem) + a.log.Debug("existing cb items: ", a.noteList[i].NoteTextItems) + a.noteList[i].NoteTextItems = append(a.noteList[i].NoteTextItems, *cbi) + //a.noteList[i].NoteItems = ilst break } } diff --git a/noteItem_test.go b/noteItem_test.go index 437d1e3..39cbde9 100644 --- a/noteItem_test.go +++ b/noteItem_test.go @@ -254,7 +254,7 @@ func TestNotesAPI_setSavedTextItem(t *testing.T) { n1.ID = 5 n1.LastUsed = time.Now() n1.OwnerEmail = "tester@tst.com" - n1.NoteItems = cbilst + n1.NoteTextItems = cbilst n1.Title = "cb note 1" n1.Type = "checkbox" ntlst = append(ntlst, n1) @@ -268,9 +268,9 @@ func TestNotesAPI_setSavedTextItem(t *testing.T) { api.setSavedTextItem(&cbi3) - ilst := sapi.noteList[0].NoteItems.([]NoteItem) + //ilst := sapi.noteList[0].NoteItems.([]NoteItem) - if len(ilst) != 3 { + if len(sapi.noteList[0].NoteTextItems) != 3 { t.Fail() } @@ -306,7 +306,7 @@ func TestNotesAPI_setSavedTextItem2(t *testing.T) { n1.ID = 5 n1.LastUsed = time.Now() n1.OwnerEmail = "tester@tst.com" - n1.NoteItems = cbilst + n1.NoteTextItems = cbilst n1.Title = "cb note 1" n1.Type = "checkbox" ntlst = append(ntlst, n1) @@ -321,9 +321,9 @@ func TestNotesAPI_setSavedTextItem2(t *testing.T) { api.setSavedTextItem(&cbi3) - ilst := sapi.noteList[0].NoteItems.([]NoteItem) + //ilst := sapi.noteList[0].NoteItems.([]NoteItem) - if len(ilst) != 2 { + if len(sapi.noteList[0].NoteTextItems) != 2 { t.Fail() } diff --git a/note_test.go b/note_test.go index 8401703..ef24483 100644 --- a/note_test.go +++ b/note_test.go @@ -650,7 +650,7 @@ func TestNotesAPI_setSavedCheckboxNote(t *testing.T) { n1.ID = 5 n1.LastUsed = time.Now() n1.OwnerEmail = "tester@tst.com" - n1.NoteItems = cbilst + n1.NoteCheckboxItems = cbilst n1.Title = "cb note 1" n1.Type = "checkbox" ntlst = append(ntlst, n1) @@ -700,7 +700,7 @@ func TestNotesAPI_getSavedCheckboxNote(t *testing.T) { n1.ID = 5 n1.LastUsed = time.Now() n1.OwnerEmail = "tester@tst.com" - n1.NoteItems = cbilst + n1.NoteCheckboxItems = cbilst n1.Title = "cb note 1" n1.Type = "checkbox" ntlst = append(ntlst, n1) @@ -745,7 +745,7 @@ func TestNotesAPI_setSavedTextNote(t *testing.T) { n1.ID = 5 n1.LastUsed = time.Now() n1.OwnerEmail = "tester@tst.com" - n1.NoteItems = cbilst + n1.NoteTextItems = cbilst n1.Title = "cb note 1" n1.Type = "checkbox" ntlst = append(ntlst, n1) @@ -756,9 +756,9 @@ func TestNotesAPI_setSavedTextNote(t *testing.T) { api.setSavedTextNote(&cb) - ilst := sapi.noteList[0].NoteItems.([]NoteItem) - fmt.Println("text note list: ", ilst[0]) - if len(ilst) != 2 { + //ilst := sapi.noteList[0].NoteTextItems.([]NoteItem) + fmt.Println("text note list: ", sapi.noteList[0].NoteTextItems[0]) + if len(sapi.noteList[0].NoteTextItems) != 2 { t.Fail() } @@ -794,7 +794,7 @@ func TestNotesAPI_getSavedTextNote(t *testing.T) { n1.ID = 5 n1.LastUsed = time.Now() n1.OwnerEmail = "tester@tst.com" - n1.NoteItems = cbilst + n1.NoteTextItems = cbilst n1.Title = "text note 1" n1.Type = "note" ntlst = append(ntlst, n1) @@ -838,7 +838,7 @@ func TestNotesAPI_SetNoteList(t *testing.T) { n1.ID = 5 n1.LastUsed = time.Now() n1.OwnerEmail = "tester@tst.com" - n1.NoteItems = cbilst + n1.NoteTextItems = cbilst n1.Title = "text note 1" n1.Type = "note" ntlst = append(ntlst, n1)