Skip to content

Commit

Permalink
updates to offline functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
KenWilliamson committed Feb 1, 2021
1 parent 8978e38 commit 60896f9
Show file tree
Hide file tree
Showing 9 changed files with 354 additions and 185 deletions.
35 changes: 24 additions & 11 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ type NoteUsers struct {
UserEmail string `json:"userEmail"`
}

//Note Note
type Note struct {
//TextNote TextNote
type TextNote struct {
ID int64 `json:"id"`
Title string `json:"title"`
Type string `json:"type"`
Expand All @@ -96,6 +96,16 @@ type Note struct {
LastUsed time.Time `json:"lastUsed"`
}

//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"`
}

//NoteItem NoteItem
type NoteItem struct {
ID int64 `json:"id"`
Expand Down Expand Up @@ -145,28 +155,31 @@ type API interface {
AddNote(n *Note) *ResponseID
UpdateNote(n *Note) *Response
GetCheckboxNote(id int64) *CheckboxNote
GetNote(id int64) *Note
GetUsersNotes(email string) *[]Note
GetNote(id int64) *TextNote
GetUsersNotes(email string) (*[]Note, bool)
DeleteNote(id int64, ownerEmail string) *Response

setSavedCheckboxNote(cb *CheckboxNote)
getSavedCheckboxNote(id int64) *CheckboxNote
setSavedTextNote(tx *Note)
getSavedTextNote(id int64) *Note
setSavedTextNote(tx *TextNote)
getSavedTextNote(id int64) *TextNote

setSavedCheckboxItem(cb *CheckboxNoteItem)
setSavedTextItem(cb *NoteItem)

GetFailAddCheckboxNoteItemList() []CheckboxNoteItem
GetFailUpdateCheckboxNoteItemList() []CheckboxNoteItem
GetFailAddNoteItemList() []NoteItem
GetFailUpdateNoteItemList() []NoteItem

AddCheckboxItem(ni *CheckboxNoteItem) *ResponseID
UpdateCheckboxItem(ni *CheckboxNoteItem) *Response
DeleteCheckboxItem(id int64) *Response

AddNoteItem(ni *NoteItem) *ResponseID
UpdateNoteItem(ni *NoteItem) *Response
DeleteNoteItem(id int64) *Response

//Offline functionality below
GetFailAddCheckboxNoteItemList() []CheckboxNoteItem
GetFailUpdateCheckboxNoteItemList() []CheckboxNoteItem
GetFailAddNoteItemList() []NoteItem
GetFailUpdateNoteItemList() []NoteItem

SetNoteList(noteList []Note)
}
31 changes: 18 additions & 13 deletions checkboxItem.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,22 @@ func (a *NotesAPI) setSavedCheckboxItem(cbi *CheckboxNoteItem) {
//update existing item
a.log.Debug("saving in updating: ", *cbi)
if cbi.ID != 0 {
for _, cb := range a.checkboxNoteList {
a.log.Debug("saving in updating in for loop: ", *cb)
if cb.ID == cbi.NoteID {
a.log.Debug("found cb and updating: ", *cb)
for i := range cb.NoteItems {
a.log.Debug("found cb item: ", cb.NoteItems[i])
if cb.NoteItems[i].ID == cbi.ID {
a.log.Debug("found cb item and updating: ", cb.NoteItems[i])
for i := range a.noteList {
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])
a.log.Debug("updating to: ", *cbi)
cb.NoteItems[i].Checked = cbi.Checked
cb.NoteItems[i].Text = cbi.Text
ilst[ii].Checked = cbi.Checked
ilst[ii].Text = cbi.Text
break
}
}
a.noteList[i].NoteItems = ilst
break
}
}
Expand All @@ -114,10 +116,13 @@ func (a *NotesAPI) setSavedCheckboxItem(cbi *CheckboxNoteItem) {
rand.Seed(time.Now().UnixNano())
var nid = rand.Int63n(30000)
cbi.ID = nid
for _, cb := range a.checkboxNoteList {
if cb.ID == cbi.NoteID {
for i := range a.noteList {
if a.noteList[i].ID == cbi.NoteID {
a.log.Debug("adding new cb item: ", *cbi)
cb.NoteItems = append(cb.NoteItems, *cbi)
ilst := a.noteList[i].NoteItems.([]CheckboxNoteItem)
a.log.Debug("existing cb item: ", ilst)
ilst = append(ilst, *cbi)
a.noteList[i].NoteItems = ilst
break
}
}
Expand Down
35 changes: 31 additions & 4 deletions checkboxItem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,18 @@ func TestNotesAPI_setSavedCheckboxItem(t *testing.T) {
cb.Type = "checkbox"
api := sapi.GetNew()

api.setSavedCheckboxNote(&cb)
var ntlst []Note
var n1 Note
n1.ID = 5
n1.LastUsed = time.Now()
n1.OwnerEmail = "[email protected]"
n1.NoteItems = cbilst
n1.Title = "cb note 1"
n1.Type = "checkbox"
ntlst = append(ntlst, n1)
sapi.noteList = ntlst

//api.setSavedCheckboxNote(&cb)

var cbi3 CheckboxNoteItem
cbi3.Checked = false
Expand All @@ -263,7 +274,9 @@ func TestNotesAPI_setSavedCheckboxItem(t *testing.T) {

api.setSavedCheckboxItem(&cbi3)

if len(sapi.checkboxNoteList[0].NoteItems) != 3 {
ilst := sapi.noteList[0].NoteItems.([]CheckboxNoteItem)

if len(ilst) != 3 {
t.Fail()
}

Expand Down Expand Up @@ -296,7 +309,19 @@ func TestNotesAPI_setSavedCheckboxItem2(t *testing.T) {
cb.Type = "checkbox"
api := sapi.GetNew()

api.setSavedCheckboxNote(&cb)

var ntlst []Note
var n1 Note
n1.ID = 5
n1.LastUsed = time.Now()
n1.OwnerEmail = "[email protected]"
n1.NoteItems = cbilst
n1.Title = "cb note 1"
n1.Type = "checkbox"
ntlst = append(ntlst, n1)
sapi.noteList = ntlst

//api.setSavedCheckboxNote(&cb)

var cbi3 CheckboxNoteItem
cbi3.ID = 2
Expand All @@ -306,7 +331,9 @@ func TestNotesAPI_setSavedCheckboxItem2(t *testing.T) {

api.setSavedCheckboxItem(&cbi3)

if len(sapi.checkboxNoteList[0].NoteItems) != 2 {
ilst := sapi.noteList[0].NoteItems.([]CheckboxNoteItem)

if len(ilst) != 2 {
t.Fail()
}

Expand Down
141 changes: 70 additions & 71 deletions coverage.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ github.com/Ulbora/cocka2notesApi/checkboxItem.go:65.11,67.4 1 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:68.26,71.4 2 1
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.41 1 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:95.41,97.27 2 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:97.27,99.33 2 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:109.5,109.10 1 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:99.33,101.38 2 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:101.38,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.41 4 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:117.41,118.27 1 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:118.27,121.10 3 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:128.72,130.2 1 1
github.com/Ulbora/cocka2notesApi/checkboxItem.go:133.75,135.2 1 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/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
Expand All @@ -37,38 +37,37 @@ github.com/Ulbora/cocka2notesApi/note.go:63.2,64.13 2 1
github.com/Ulbora/cocka2notesApi/note.go:54.16,59.14 5 1
github.com/Ulbora/cocka2notesApi/note.go:59.14,61.4 1 1
github.com/Ulbora/cocka2notesApi/note.go:68.60,78.24 8 1
github.com/Ulbora/cocka2notesApi/note.go:88.2,91.12 3 1
github.com/Ulbora/cocka2notesApi/note.go:85.2,88.12 3 1
github.com/Ulbora/cocka2notesApi/note.go:78.24,81.3 2 1
github.com/Ulbora/cocka2notesApi/note.go:81.8,83.17 2 1
github.com/Ulbora/cocka2notesApi/note.go:83.17,85.4 1 1
github.com/Ulbora/cocka2notesApi/note.go:95.44,103.24 8 1
github.com/Ulbora/cocka2notesApi/note.go:112.2,115.12 3 1
github.com/Ulbora/cocka2notesApi/note.go:103.24,106.3 2 1
github.com/Ulbora/cocka2notesApi/note.go:106.8,108.17 2 1
github.com/Ulbora/cocka2notesApi/note.go:108.17,110.4 1 1
github.com/Ulbora/cocka2notesApi/note.go:119.56,126.24 6 1
github.com/Ulbora/cocka2notesApi/note.go:132.2,135.13 3 1
github.com/Ulbora/cocka2notesApi/note.go:126.24,128.3 1 1
github.com/Ulbora/cocka2notesApi/note.go:128.8,130.3 1 1
github.com/Ulbora/cocka2notesApi/note.go:139.70,150.2 9 1
github.com/Ulbora/cocka2notesApi/note.go:152.59,154.41 2 1
github.com/Ulbora/cocka2notesApi/note.go:164.2,164.12 1 1
github.com/Ulbora/cocka2notesApi/note.go:154.41,155.22 1 1
github.com/Ulbora/cocka2notesApi/note.go:155.22,161.9 6 1
github.com/Ulbora/cocka2notesApi/note.go:164.12,167.3 2 1
github.com/Ulbora/cocka2notesApi/note.go:170.65,172.40 2 1
github.com/Ulbora/cocka2notesApi/note.go:179.2,179.12 1 1
github.com/Ulbora/cocka2notesApi/note.go:172.40,173.18 1 1
github.com/Ulbora/cocka2notesApi/note.go:173.18,176.9 3 1
github.com/Ulbora/cocka2notesApi/note.go:182.47,184.37 2 1
github.com/Ulbora/cocka2notesApi/note.go:194.2,194.12 1 1
github.com/Ulbora/cocka2notesApi/note.go:184.37,185.22 1 1
github.com/Ulbora/cocka2notesApi/note.go:185.22,191.9 6 1
github.com/Ulbora/cocka2notesApi/note.go:194.12,197.3 2 1
github.com/Ulbora/cocka2notesApi/note.go:200.53,202.36 2 1
github.com/Ulbora/cocka2notesApi/note.go:209.2,209.12 1 1
github.com/Ulbora/cocka2notesApi/note.go:202.36,203.18 1 1
github.com/Ulbora/cocka2notesApi/note.go:203.18,206.9 3 1
github.com/Ulbora/cocka2notesApi/note.go:81.8,83.3 1 1
github.com/Ulbora/cocka2notesApi/note.go:92.48,100.24 8 1
github.com/Ulbora/cocka2notesApi/note.go:106.2,109.12 3 1
github.com/Ulbora/cocka2notesApi/note.go:100.24,103.3 2 1
github.com/Ulbora/cocka2notesApi/note.go:103.8,105.3 1 1
github.com/Ulbora/cocka2notesApi/note.go:113.64,121.24 7 1
github.com/Ulbora/cocka2notesApi/note.go:128.2,131.18 3 1
github.com/Ulbora/cocka2notesApi/note.go:121.24,124.3 2 1
github.com/Ulbora/cocka2notesApi/note.go:124.8,126.3 1 1
github.com/Ulbora/cocka2notesApi/note.go:135.70,146.2 9 1
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:177.2,177.13 1 1
github.com/Ulbora/cocka2notesApi/note.go:161.28,163.29 2 1
github.com/Ulbora/cocka2notesApi/note.go:163.29,171.28 8 1
github.com/Ulbora/cocka2notesApi/note.go:174.4,174.9 1 1
github.com/Ulbora/cocka2notesApi/note.go:171.28,173.5 1 1
github.com/Ulbora/cocka2notesApi/note.go:180.51,181.28 1 1
github.com/Ulbora/cocka2notesApi/note.go:181.28,182.32 1 1
github.com/Ulbora/cocka2notesApi/note.go:182.32,186.9 4 1
github.com/Ulbora/cocka2notesApi/note.go:191.57,193.28 2 1
github.com/Ulbora/cocka2notesApi/note.go:208.2,208.13 1 1
github.com/Ulbora/cocka2notesApi/note.go:193.28,194.29 1 1
github.com/Ulbora/cocka2notesApi/note.go:194.29,202.28 8 1
github.com/Ulbora/cocka2notesApi/note.go:205.4,205.9 1 1
github.com/Ulbora/cocka2notesApi/note.go:202.28,204.5 1 1
github.com/Ulbora/cocka2notesApi/note.go:212.49,214.2 1 1
github.com/Ulbora/cocka2notesApi/noteItem.go:32.58,37.16 5 1
github.com/Ulbora/cocka2notesApi/noteItem.go:50.2,51.13 2 1
github.com/Ulbora/cocka2notesApi/noteItem.go:37.16,42.11 5 1
Expand All @@ -83,34 +82,34 @@ github.com/Ulbora/cocka2notesApi/noteItem.go:65.11,67.4 1 1
github.com/Ulbora/cocka2notesApi/noteItem.go:68.26,71.4 2 1
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.37 1 1
github.com/Ulbora/cocka2notesApi/noteItem.go:94.37,96.27 2 1
github.com/Ulbora/cocka2notesApi/noteItem.go:96.27,98.33 2 1
github.com/Ulbora/cocka2notesApi/noteItem.go:107.5,107.10 1 1
github.com/Ulbora/cocka2notesApi/noteItem.go:98.33,100.38 2 1
github.com/Ulbora/cocka2notesApi/noteItem.go:100.38,104.12 4 1
github.com/Ulbora/cocka2notesApi/noteItem.go:110.8,110.28 1 1
github.com/Ulbora/cocka2notesApi/noteItem.go:110.28,115.37 4 1
github.com/Ulbora/cocka2notesApi/noteItem.go:115.37,116.27 1 1
github.com/Ulbora/cocka2notesApi/noteItem.go:116.27,119.10 3 1
github.com/Ulbora/cocka2notesApi/noteItem.go:126.56,128.2 1 1
github.com/Ulbora/cocka2notesApi/noteItem.go:131.59,133.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:49.33,58.2 6 1
github.com/Ulbora/cocka2notesApi/notesApi.go:61.44,63.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:65.106,66.20 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:69.2,71.37 3 1
github.com/Ulbora/cocka2notesApi/notesApi.go:77.2,78.16 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:84.2,84.12 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:66.20,68.3 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:71.37,74.3 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:74.8,76.3 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:78.16,79.37 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:79.37,82.4 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:88.43,90.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:93.43,95.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:98.42,100.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:103.45,105.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:108.50,110.2 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: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: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
github.com/Ulbora/cocka2notesApi/notesApi.go:59.44,61.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:63.106,64.20 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:67.2,69.37 3 1
github.com/Ulbora/cocka2notesApi/notesApi.go:75.2,76.16 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:82.2,82.12 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:64.20,66.3 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:69.37,72.3 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:72.8,74.3 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:76.16,77.37 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:77.37,80.4 2 1
github.com/Ulbora/cocka2notesApi/notesApi.go:86.43,88.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:91.43,93.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:96.42,98.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:101.45,103.2 1 1
github.com/Ulbora/cocka2notesApi/notesApi.go:106.50,108.2 1 1
github.com/Ulbora/cocka2notesApi/user.go:30.47,35.16 5 1
github.com/Ulbora/cocka2notesApi/user.go:44.2,45.13 2 1
github.com/Ulbora/cocka2notesApi/user.go:35.16,40.15 5 1
Expand Down
Loading

0 comments on commit 60896f9

Please sign in to comment.